Forum Discussion

Nathan_Pearce_4's avatar
Nathan_Pearce_4
Historic F5 Account
May 21, 2010

Math problem (possible human error)

when RULE_INIT { log local0. "Maths Test: 57 + 22: [expr {57 +22}]. 57 + 022: [expr {57 + 022}]" } Returns: : Maths Test: 57 + 22: 79. 57 + 022: 75 Can anyone explain why this might be? Tested on LTM VE but looking for verification on other platforms.
  • Actually, that's not an error. When you are attempting to add "022", the TCL interpreter is treating that number as octal. octal 022 is 18 and 57 + 18 equals 75. The manual page for expr explains the rules on interpretation of numbers and their formats

     

     

    http://tmml.sourceforge.net/doc/tcl/expr.html

     

     

    -Joe

     

  • BTW, if you do want to ensure that a number is treated as an integer, you can use the scan command

    [expr 57 + [scan 022 %d]]

    That should produce the expected value of 59 since "scan 022 %d" will return 22.

    -Joe

  • Nathan_Pearce_4's avatar
    Nathan_Pearce_4
    Historic F5 Account
    Fantastic. Thanks Joe. The 022 I amusing is not a number I have control over (three digit value extracted from payload) so I was thinking about performing a trimleft on any zero's but your solution is much more elegant.
  • Nathan_Pearce_4's avatar
    Nathan_Pearce_4
    Historic F5 Account
    That was the last piece of the puzzle for a credit card/payments system transaction switch. You can find it in the Finance Group:

     

    http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/71/aft/1172446/afv/topic/aff/2297/showtab/groupforums/Default.aspx