trunc/2—truncate a real number to an integer (symmetric around 0)

The trunc/2 primitive truncates a real number to an integer (symmetric around  0).

$INTVAL=trunc($NUMBER)

trunc/2 arguments

Argument

Mode

Type

Description

$NUMBER

Input

INTEGER|REAL

Specifies the numeric (integer or real) value that is to be converted to an integer

$INTVAL

Output

INTEGER

The conversion result, returned as an integer

Use trunc/2 to convert the numeric value specified by the $NUMBER argument to an integer value returned in the $INTVAL argument. For positive numbers, the conversion truncates the number to the largest integer value that is smaller than or equal to it. A negative number is truncated to the smallest integer value that is greater than or equal to it. This function is symmetric around 0.

The following statement holds true for the truncation process:

"X ≥ 0: X-1 < trunc(X) £ 	 X 
"X £  0: X £ 					 trunc(X) < X+1

trunc/2 example

$DEV = trunc( ( $AVERAGE_DURATION - real($E.duration) ) ^ 2 );
Was this page helpful? Yes No Submitting... Thank you

Comments