calc

*ARES System Manual: calc Application*

`calc ``<`*calculation*>

: Performs arithmetic.
`calc -x ``<`*calculation*>

: Return result in hexadecimal.
`calc -d ``<`*value*>

: Decode ARES signal.
`calc -e ``<`*value*>

: Encode ARES signal.
`calc -r [``[``<`*min*>] `<`*max*>]

: Generate random number.
The

`calc`

program performs decimal arithmetic with integers and floating-point numbers. It is low-precision, and limited to LSL native data types.
Unlike

`lslisp`and the

`expressions`used by

`input`,

`calc`

implements a parser that correctly respects operator precedence (order-of-operations).
It may seem excessive to implement a command-line calculator program for ARES, but the ability to do math in

`.as`

scripts without depending on `input`

's limited memory is expected to be valuable in the future.
Supported symbols

ARES calc recognizes the following non-numeric keywords: << >> + - ** * / % ^ ~ && || & | ( )

Numbers will be interpreted as integers unless they contain a decimal point. If either argument to a binary operator is a float, the result will be a float.

To input a hexadecimal value, prefix it with

`0x`

, as in LSL and C.
Operator precedence classes

Parentheses: ( )

Unary numeric operators: - ~ (unary negation, bitwise complement)

Exponentiation: << >> ** (left shift, right shift, exponentiation)

Production: * / % (multiplication, division, modulo)

Summation: + - (addition, subtraction)

Bitwise operators: ^ & | (bitwise XOR, bitwise AND, bitwise OR)

Unary boolean operator: ! (NOT)

Binary boolean operators: && || (boolean AND, boolean OR)

All operators in

`calc`

are left-associative. This may occasionally result in some surprising results, e.g. 2**3**4 is (2**3)**4 (equal to 2048) rather than 2**(3**4) (equal to 2417851639229258349412352, which is much too big for LSL).
Random number generation

The

`-r`

flag causes `calc`

to generate a random number.
When no additional arguments are specified, the result is a floating point value between 0.0 and 1.0.

When one argument (

`<`*max*>

) is specified, the result is an integer value between 0 and `<`*max*>

- 1.
When two arguments (

`<`*min*>

and `<`*max*>

) are specified, the result is an integer value between `<`*min*>

and `<`*max*>

- 1.