$calcint » History » Version 3
Per Amundsen, 05/31/2019 04:59 AM
1 | 1 | Per Amundsen | _Added in 3.3_ |
---|---|---|---|
2 | |||
3 | *$calcint(operations)* |
||
4 | |||
5 | Returns the result of the specified operations. You can perform multiple operations. |
||
6 | |||
7 | 3 | Per Amundsen | Can calculate extremely high numbers, but can only be used on whole numbers, not decimal/float/fractions. Does not have the limitation in [[$calc]]() where any term or output value 2^96 or higher is zero. |
8 | 1 | Per Amundsen | |
9 | 2 | Paul Janson | Any term containing non-zero fraction replaced by zero. Output has any fraction removed. |
10 | |||
11 | 1 | Per Amundsen | [[Arithmetic Operators]]. |
12 | |||
13 | Operations can be grouped with parentheses. |
||
14 | |||
15 | 3 | Per Amundsen | Same operators as [[$calc]]() uses except: |
16 | 2 | Paul Janson | |
17 | // floor divide operator behaves like / operator, being an 'int divide' that's identical for positive results but not for negatives. |
||
18 | |||
19 | |||
20 | 1 | Per Amundsen | *Parameters* |
21 | |||
22 | operations - The calculations to perform. |
||
23 | |||
24 | *Example* |
||
25 | |||
26 | <pre> |
||
27 | 2 | Paul Janson | accurate result for extremely large integers |
28 | //echo -ag $calcint( ((2 ^ 256) - 1) * ((2 ^ 256) +1) ) |
||
29 | |||
30 | fraction removed from output. not affected by fraction being zero |
||
31 | //echo -ag $calcint(48.0 / 10.0) is same as $int($calc(48 / 10)) |
||
32 | |||
33 | term with fraction treated as if zero |
||
34 | //echo -ag $calcint(5 + 2.5) is same as 5 + 0 |
||
35 | |||
36 | not affected by value 2^96 or greater |
||
37 | //var %ag 79228162514264337593543950335 | echo -a $calcint(1+%a) vs $calc(1+%a) is 79228162514264337593543950336 vs 0 |
||
38 | |||
39 | fractional terms created by parenthesis can affect output |
||
40 | //echo -ag $calcint(2 * (48 / 10)) vs $calcint(2 * 48 / 10) is 8 vs 9 |
||
41 | |||
42 | If you need floordivide for negative numbers, you must calculate it using / (divide) and % (modulo). Note that $calc() is accurate for a smaller range: |
||
43 | //var -s %numerator -10 , %denominator 3 , %intdivide $calcint(%numerator / %denominator) , %mod $calcint(%numerator % %denominator) , %floordiv %intdivide | if (%intdivide < 0) var -s %floordiv $calcint(%floordiv - $iif(%mod,1,0)) | echo -a %floordiv vs $calc(%numerator // %denominator) |
||
44 | 1 | Per Amundsen | </pre> |