CML Reference Guide

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 a and b, modulo xA, b, and x are 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 a and b to integers, and evaluates to the integer quotient of a / b.

$quotient(a b [r])
Evaluates to the real quotient of a / b.  If r is supplied, rounded to that many digits to the right of the decimal point.

$round(a r)
If a is an integer, evaluates to a.  Otherwise, it rounds a to r digits to the right of the decimal point.

$greater(a b)
Evaluates to "1" if a is greater than b.  Otherwise "0".  Handles integers and reals.

$gt_equal(a b)
Evaluates to "1" if a is greater than or equal to b.  Otherwise "0".  Handles integers and reals.

$less(a b)
Evaluates to "1" if a is less than b.  Otherwise "0".  Handles integers and reals.

$between(a x b)
Evaluates to "1" if x is between a and b (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.