Returns the common logarithm (base 10) of a number.

1. Description

The log operator pops a positive number from the operand stack and pushes its common logarithm (logarithm base 10). 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 log 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) - Base-10 logarithm of num

3. Parameters

num

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

4. Return Values

real

log₁₀(num) - the common logarithm (always real)

5. Examples

5.1. Basic Usage

% Powers of 10
10 log         % → 1.0 (log₁₀(10) = 1)
100 log        % → 2.0 (log₁₀(100) = 2)
1000 log       % → 3.0 (log₁₀(1000) = 3)

% Other values
1 log          % → 0.0 (log₁₀(1) = 0)
2 log          % → 0.30103

5.2. Domain Restriction

% WRONG: Non-positive arguments
0 log          % ERROR: rangecheck
-5 log         % ERROR: rangecheck

% CORRECT: Validate input
/safeLog {  % num default -> result
    exch dup 0 gt {
        log exch pop
    } {
        pop
    } ifelse
} def

-5 0 safeLog   % → 0 (returns default)
10 0 safeLog   % → 1.0
  • ln - Natural logarithm (base e)

  • exp - Exponentiation

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 log          % ERROR: rangecheck
-10 log        % ERROR: rangecheck

9. See Also


Back to top

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