Raises a base to a power (exponentiation).

1. Description

The exp operator pops two numbers from the operand stack (base and exponent) and pushes base raised to the exponent power. If the exponent has a fractional part, the result is meaningful only if the base is non-negative. The result is always a real number.

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

2. Syntax

base exponent exp real

2.1. Stack Effect

Table 1. Before Execution
Position Content

Top

exponent (integer or real) - The power

Top-1

base (integer or real) - The base

Table 2. After Execution
Position Content

Top

real (real) - base^exponent (always real)

3. Parameters

base

The base number (integer or real)

exponent

The power to raise to (integer or real)

4. Return Values

real

The result of base^exponent (always a real number)

5. Examples

5.1. Basic Exponentiation

% Integer powers
2 3 exp        % → 8.0 (2³)
10 2 exp       % → 100.0 (10²)
5 0 exp        % → 1.0 (5⁰ = 1)

% Fractional powers (roots)
9 0.5 exp      % → 3.0 (√9)
8 0.333 exp    % → 2.0 (approximately ∛8)

% Negative exponents (reciprocals)
2 -1 exp       % → 0.5 (2⁻¹ = 1/2)
10 -2 exp      % → 0.01 (10⁻²)

5.2. Domain Restrictions

% Negative base with integer exponent
-2 3 exp       % → -8.0 (valid)
-2 2 exp       % → 4.0 (valid)

% WRONG: Negative base with fractional exponent
-9 0.5 exp     % ERROR: undefinedresult
  • sqrt - Square root

  • ln - Natural logarithm

  • log - Base-10 logarithm

  • mul - Multiplication

7. PostScript Level

Available in: PostScript Level 1 and higher

8. Error Conditions

stackunderflow

The operand stack contains fewer than two elements.

typecheck

One or both operands are not numbers.

undefinedresult

Negative base with fractional exponent, or result out of range.

-4 0.5 exp     % ERROR: undefinedresult

9. See Also


Back to top

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