Added in 1.8.10
Returns the result of the specified operations. You can perform multiple operations.
Operations can be grouped with parentheses.
|operations||The calculations to perform.|
Note: $calc uses the left-to-right
PE(MD)(AS) order of operations, but also includes Floor Divide and Modulo. When parenthesis are not used, operators are evaluated in left-to-right order within each of these levels 1-4. All level N operations are performed left-to-right before any level N+1 operations are performed.
() 1. Parenthesis ^ 2. Exponent (dont' use 96 or greater) // 3. Floor division, X // Y same as $floor($calc(X / Y)) % 3. Modulus X % Y is remainder when dividing X / Y * 3. Multiplication / 3. Division + 4. Addition - 4. Subtraction
(AdiIRC only) = $calc is accurate to any integer value up within the range [1-2^96,-1+2^96], but returns result of 0 exponent is 96 or greater. If result of multiply or add is >= 2^96, that intermediate operation has the result of zero. Accuracy of the fraction to the right of the decimal is limited by the size of the number to the left.
If needing integer math for values 2^96 and above, see $calcint.
; Returns 6. //echo -ag $calc((4 + 4) - 2)
Accuracy above 2^53: //echo -a $calc(2^53 + 1) currectly returns an ODD number and so does $calc(2^95+1) ; next is 0 because, even though the result is in the valid range, the 2^96 operation has undefined result //echo -a $calc(2^96-1) ; result is 7 because the multiply is earlier priority than the addition //echo -a $calc( 4 + 1 * 3) ; result is 15 because the parenthesis altered the order of operations //echo -a $calc( (4 + 1) * 3) ; While AdiIRC offers many fraction digits, it's up to you to decide how many of the least you wish to keep. //echo -a $calc( (3/7) *70 ) result = 30.000000000000000000000000002 alias calc6 return $round($calc($parms),6) You can use [[$round]] to ensure the result is rounded to 6 decimal places or to the level you prefer. //var -p %a (3/7) *70 | echo -a $round($calc( %a ),6)