Returns the natural logarithm (base e) of a number.

1. Description

The ln operator pops a positive number from the operand stack and pushes its natural logarithm (logarithm base e, where e ≈ 2.71828). The operand must be positive; zero or negative values cause a rangecheck error. The result is always a real number.

This is a Level 1 operator, available in all PostScript implementations.

2. Syntax

num ln real

2.1. Stack Effect

Table 1. Before Execution
Position Content

Top

num (integer or real) - Positive number

Table 2. After Execution
Position Content

Top

real (real) - Natural logarithm of num

3. Parameters

num

A positive number (integer or real, must be > 0)

4. Return Values

real

ln(num) - the natural logarithm (always real)

5. Examples

5.1. Basic Usage

% Common values
10 ln          % → 2.30259 (ln(10))
100 ln         % → 4.60517 (ln(100))
2.71828 ln     % → 1.0 (ln(e) ≈ 1)
1 ln           % → 0.0 (ln(1) = 0)

% WRONG: Non-positive arguments
0 ln           % ERROR: rangecheck
-5 ln          % ERROR: rangecheck
  • log - Base-10 logarithm

  • exp - Exponentiation (inverse operation)

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.

rangecheck

The operand is zero or negative.

0 ln           % ERROR: rangecheck
-5 ln          % ERROR: rangecheck

9. See Also


Back to top

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