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

num1 truncate num2

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)

5. Examples

5.1. Basic Truncation

% Positive numbers truncate down
3.2 truncate   % → 3.0
3.9 truncate   % → 3.0

% Negative numbers truncate up (toward zero)
-4.8 truncate  % → -4.0 (toward zero)
-4.1 truncate  % → -4.0

% Integers unchanged
99 truncate    % → 99

5.2. Extracting Integer Part

% Get integer and fractional parts
/getParts {  % num -> intPart fracPart
    dup truncate     % num intPart
    2 copy sub       % num intPart fracPart
    3 1 roll pop     % intPart fracPart
} def

3.7 getParts   % → 3.0 0.7
-5.3 getParts  % → -5.0 -0.3

7. PostScript Level

Available in: PostScript Level 1 and higher

8. Error Conditions

stackunderflow

The operand stack is empty.

typecheck

The operand is not a number.

9. See Also


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.