Built-In Math and Trigonometric Functions

The assembler supports many built-in mathematical functions. The built-in functions always return a value and they can be used in conditional assembly or any place where a constant can be used.

In Table 4-7 x, y and z are type float, n is an int. The functions $cvi, $int and $sgn return an integer and all other functions return a float. Angles for trigonometric functions are expressed in radians.

Table 4-7 Built-In Mathematical Functions

Function Description
$acos(x) Returns cos-1(x) in range [0, π], -1<=x<=1
$asin(x) Returns sin-1(x) in range [-π/2, π/2], -1<=x<=1
$atanx) Returns tan-1(x) in range [-π/2, π/2]
$atan2(x, y) Returns tan-1(y/x) in range [-π, π]
$ceil(x) Returns the smallest integer not less than x, as a float
$cos(x) Returns the cosine of x
$cosh(x) Returns the hyperbolic cosine of x
$cvf(n) Converts an integer to a float
$cvi(x) Converts a float to an integer. Returns an integer.
$exp(x) Returns the exponential function ex
$fabs(x) Returns the absolute value |x|
$floor(x) Returns the largest integer not greater than x, as a float
$fmod(x, y) Returns the floating-point remainder of x/y, with the same sign as x
$int(x) Returns 1 if x has an integer value; else returns 0. Returns an integer.
$ldexp(x, n) Multiplies x by an integer power of 2. That is, x × 2n
$log(x) Returns the natural logarithm ln(x), where x>0
$log10(x) Returns the base-10 logarithm log10(x), where x>0
$max(x, y, ...z) Returns the greatest value from the argument list
$min(x, y, ...z) Returns the smallest value from the argument list
$pow(x, y) Returns xy
$round(x) Returns x rounded to the nearest integer
$sgn(x) Returns the sign of x. Returns 1 if x is positive, 0 if x is zero, and -1 if x is negative. Returns an integer.
$sin(x) Returns the sine of x
$sinh(x) Returns the hyperbolic sine of x
$sqrt(x) Returns the square root of x, x≥0
$strtod(str) Converts a character string to a double precision floating-point value. The string contains a properly-formatted C99-style floating-point literal.
$tan(x) Returns the tangent of x
$tanh(x) Returns the hyperbolic tangent of x
$trunc(x) Returns x truncated toward 0