Project

General

Profile

$calcint » History » Revision 3

Revision 2 (Paul Janson, 12/25/2018 02:38 AM) → Revision 3/4 (Per Amundsen, 05/31/2019 04:59 AM)

_Added in 3.3_ 

 *$calcint(operations)* 

 Returns the result of the specified operations. You can perform multiple operations. 

 Can calculate extremely high numbers, but can only be used on whole numbers, not decimal/float/fractions. Does not have the limitation in [[$calc]]() $calc() where any term or output value 2^96 or higher is zero. 

 Any term containing non-zero fraction replaced by zero. Output has any fraction removed. 

 [[Arithmetic Operators]]. 

 Operations can be grouped with parentheses. 

 Same operators as [[$calc]]() $calc() uses except: 

 // floor divide operator behaves like / operator, being an 'int divide' that's identical for positive results but not for negatives. 


 *Parameters* 

 operations - The calculations to perform. 

 *Example* 

 <pre> 
 accurate result for extremely large integers 
 //echo -ag $calcint( ((2 ^ 256) - 1) * ((2 ^ 256) +1) ) 

 fraction removed from output. not affected by fraction being zero 
 //echo -ag $calcint(48.0 / 10.0) is same as $int($calc(48 / 10)) 

 term with fraction treated as if zero 
 //echo -ag $calcint(5 + 2.5) is same as 5 + 0 

 not affected by value 2^96 or greater 
 //var %ag 79228162514264337593543950335 | echo -a $calcint(1+%a) vs $calc(1+%a) is 79228162514264337593543950336 vs 0 

 fractional terms created by parenthesis can affect output 
 //echo -ag $calcint(2 * (48 / 10)) vs $calcint(2 * 48 / 10) is 8 vs 9 

 If you need floordivide for negative numbers, you must calculate it using / (divide) and % (modulo). Note that $calc() is accurate for a smaller range: 
 //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) 
 </pre>