Arithmetic operators perform mathematical calculations on numbers from the operand stack. They consume their operands and push the result back onto the stack.
PostScript supports both integer and real (floating-point) arithmetic, with automatic type promotion when mixing types.
num1 num2 div (1) (2) (3)-
Dividend
-
Divisor
-
Operator that divides
Where,
num1-
Number to divide
num2-
Divisor (must not be zero)
Stack effect: num1 num2 — quotient
int1 int2 idiv (1) (2) (3)-
Dividend (integer)
-
Divisor (integer)
-
Operator for integer division
Where,
int1, int2-
Integer operands
Stack effect: int1 int2 — quotient
The atan operator returns the arctangent of num1/num2 in degrees, with
proper handling of the quadrant.
num1 num2 atan (1) (2) (3)-
Numerator (Y value)
-
Denominator (X value)
-
Operator for arctangent
Where,
num1, num2-
Numbers (num2 cannot be zero unless num1 is also zero)
Stack effect: num1 num2 — angle
% Distance between (x1,y1) and (x2,y2)
/x1 10 def /y1 20 def
/x2 40 def /y2 60 def
x2 x1 sub dup mul % (x2-x1)²
y2 y1 sub dup mul % (y2-y1)²
add sqrt % √((x2-x1)² + (y2-y1)²)
% Result: 50.0Pythagorean theorem for distance.