Forum Discussion
Kevin_Raison_74
Nimbostratus
Dec 08, 2005Exponentiation, involution
Can someone tell me how to accomplish pow(x,y) in F5's TCL implementation?
Thanks.
Kevin Raison
Dec 09, 2005
Not sure why the "**" operator doesn't work but it seems it doesn't and I've tested it in several stand-along tcl interpreters as well.
There is a builtin "pow" command that you could use but it looks like we've disabled the math commands within iRules for performance reasons.
Don't dispair though. Where there's a will, there's a way.
Here's a rough implementation of the logic behind pow that you can include in your iRule.
set y 2000
set e 9
set t 2
if { $t == 0 } {
if { $e > 0 } {
set m 0
} elseif { $e < 0 } {
log local0. "undefined exponentiation!"
} elseif { $e == 0 } {
set m 1
}
} elseif { $t == 1 } {
set m 1
} elseif { $e == 0 } {
set m 1
} elseif { ($t < -1) && ($e < 0) } {
set m 0
} elseif { $t == -1 } {
if { [expr ($e & 1)] == 0 } {
set m 1
} else {
set m -1
}
} else {
for {set i 1; set m $t} {$i<$e} {incr i} { set m [expr $m*$t]; }
}
set x [ expr { int($y * $m) } ]
puts $m
puts $x
*disclaimer: this code is pseudo tested. Please test before using it.
There may be some more optimal way to approach this but this should work for you.
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
