Truncates a number toward zero by removing its fractional part.
1. Description
The truncate operator pops a number from the operand stack and pushes the integer part of that number, discarding the fractional part. Truncation is always toward zero (for positive numbers, rounds down; for negative numbers, rounds up). The type of the result is the same as the type of the operand.
This is a Level 1 operator, available in all PostScript implementations.
2. Syntax
num1truncatenum2
2.1. Stack Effect
Table 1. Before Execution
Position
Content
Top
num1 (integer or real) - Number to truncate
Table 2. After Execution
Position
Content
Top
num2 (integer or real) - Integer part of num1 (same type)
3. Parameters
num1
Any number (integer or real)
4. Return Values
num2
The integer part of num1 with fractional part removed (type matches num1)
% Get integer and fractional parts/getParts{% num -> intPart fracPartduptruncate% num intPart2copysub% num intPart fracPart31rollpop% intPart fracPart}def3.7getParts% → 3.0 0.7-5.3getParts% → -5.0 -0.3