Project

General

Profile

$calcint » History » Version 4

Per Amundsen, 02/16/2023 09:15 PM

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 4 Per Amundsen
table(ktable).
23
|*Parameter*|*Description*|
24
| operations | The calculations to perform. |
25 1 Per Amundsen
26
*Example*
27
28
<pre>
29 2 Paul Janson
accurate result for extremely large integers
30
//echo -ag $calcint( ((2 ^ 256) - 1) * ((2 ^ 256) +1) )
31
32
fraction removed from output. not affected by fraction being zero
33
//echo -ag $calcint(48.0 / 10.0) is same as $int($calc(48 / 10))
34
35
term with fraction treated as if zero
36
//echo -ag $calcint(5 + 2.5) is same as 5 + 0
37
38
not affected by value 2^96 or greater
39
//var %ag 79228162514264337593543950335 | echo -a $calcint(1+%a) vs $calc(1+%a) is 79228162514264337593543950336 vs 0
40
41
fractional terms created by parenthesis can affect output
42
//echo -ag $calcint(2 * (48 / 10)) vs $calcint(2 * 48 / 10) is 8 vs 9
43
44
If you need floordivide for negative numbers, you must calculate it using / (divide) and % (modulo). Note that $calc() is accurate for a smaller range:
45
//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)
46 1 Per Amundsen
</pre>