Forum Discussion
iRule Math - Square Root?
Michael,
Thanks for the reply. Its very disappointing that they don't support basic math functions - what could be the motivation for that? Anyway, i was able to implement my own (hacky!) square root calculator based on the Nth Root Algorithm (http://en.wikipedia.org/wiki/N-th_root_algorithm). Code snippet below for anyone who might be interested:
Calcuate the square root. Based on the http://en.wikipedia.org/wiki/N-th_root_algorithm
set guess [expr {$targetValue/2}]
for {set i 0} {$i < 32} {incr i} {
set guess [expr {$guess + $targetValue/$guess}]
set guess [expr {$guess/2}]
}
set answer $guess
Obviously this doesn't have any special-case handling (1, negative values, etc) and isn't very performant but it works well enough for my use case.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com