# Calculator

Calculator mk Tue, 03/30/2010 - 16:46### 8.53 Basic arithmetic

This module is an extended version of the V4 arithmetic module. It implements the arithmetic operations on the built-in types, *chr*, *bte*, *sht*, *int*, *flt*, *dbl* and *lng*. All combinations are implemented. Limited combinations are implemented for *bit*, *oid* and *str*.

`[binary operators]`

- The implemented operators are first of all all comparison that return a TRUE/FALSE value (
*bit*values), i.e.*<=*,*<*,*==*,*!=*,*>=*, and*>=*.The module also implements the operators

*+*,*-*,***and*/*. The rules for the return types operators is as follows. If one of the input types is a floating point the result will be a floating point. The largest type of the input types is taken.The

*max*and*min*functions return the maximum and minimum of the two input parameters. `[unary operators]`

- This module also implements the unary
*abs*() function, which calculates the absolute value of the given input parameter, as well as the*-*unary operator.The

*inv*unary operation calculates the inverse of the input value. An error message is given when the input value is zero. `[bitwise operators]`

- For integers there are some additional operations. The
*%*operator implements the congruent modulo operation. The*<<*and*>>*are the left and right bit shift. The*or*,*and*,*xor*and*not*for integers are implemented as bitwise boolean operations. `[boolean operators]`

- The
*or*,*and*,*xor*and*not*for the bit atomic type in MIL (this corresponds to what is normally called boolean) are implemented as the logic operations. `[random numbers]`

- This module also contains the rand and srand functions. The
*srand*() function initializes the random number generator using a seed value. The subsequent calls to*rand*() are pseudo random numbers (with the same seed the sequence can be repeated).

The general interpretation for the NIL value is "unknown". This semantics mean that any operation that receives at least one NIL value, will produce a NIL value in the output for sure.

The only exception to this rule are the "==" and "!=" equality test routines (it would otherwise become rather difficult to test whether a value is nil).