## Chapter 4.6: Mathematics

[TOP] [UP] [PREV] [NEXT]

Note on real numbers:In version 4.23, many math functions were upgraded to handle both integers and real numbers. Where it makes sense, if integers are operated on, the result is an integer. If reals, or a mixture of reals and integers are operated on, the result is a real. In the latter case, unless additional precision results from the operation (such as in division), the precision of the result is the same as the most precise argument.

For example: $plus (2 5) is 7 $plus (2.1 5.23) is 7.34 $plus (2 3.14159) is 5.14159

- $plus(a b [c...])
- Evaluates to the sum of all of its arguments. Handles integers and reals.
- $plusmod(a b x)
- Evaluates to sum of
aandb, modulox.A,b, andxare truncated to integers first.- $minus(a b)
- Evaluates to the difference,
a-b. Handles integers and reals.- $mult(a b [c...])
- Evaluates to the product of all of its arguments. Handles integers and reals.
- $divide(a b)
- Truncates
aandbto integers, and evaluates to the integer quotient ofa/b.- $quotient(a b [r])
- Evaluates to the real quotient of
a/b. Ifris supplied, rounded to that many digits to the right of the decimal point.- $round(a r)
- If
ais an integer, evaluates toa. Otherwise, it roundsatordigits to the right of the decimal point.- $greater(a b)
- Evaluates to "1" if
ais greater thanb. Otherwise "0". Handles integers and reals.- $gt_equal(a b)
- Evaluates to "1" if
ais greater than or equal tob. Otherwise "0". Handles integers and reals.- $less(a b)
- Evaluates to "1" if
ais less thanb. Otherwise "0". Handles integers and reals.- $between(a x b)
- Evaluates to "1" if
xis betweenaandb(a<=x<=b). Otherwise "0". Very useful for processing the result of server-side image maps. Handles integers and reals.- $max(a b [c...])
- Evalutes to the larger of its arguments. Handles integers and reals.
- $min(a b [c...])
- Evaluates to the smaller of its arguments. Handles integers and reals.
- $bit_and(a b ...)
- Evaluates to bitwise logical AND of
a,b, etc.- $bit_or(a b ...)
- Evaluates to bitwise logical OR of
a,b, etc.- $bit_not(a)
- Evaluates to the first 16 bits of the bitwise logical negation of
a.- $hex2dec(a)
- Evaluates to the (decimal) number with hexadecimal value
a. E.g., $hex2dec(f) is 15.- $dec2hex(a)
- Evaluates to the (hexadecimal) number with decimal value
a. E.g., $dec2hex(15) is "f".- $random(max)
- Evaluates to a random number from 0 to
max-1, inclusive.