Arithmetic and Logic Operators

This next three clauses specify operators which are not directly involved in manipulating or imaging page elements and related objects. This includes:

The specification of these operators and their semantics includes the specification of conditions which may cause content exceptions to be raised as a result of interpretation of the operators. Content exceptions and exception handling are defined in . In addition to these operator-specific exceptions, there are generic exceptions which may be raised during the interpretation of almost any operator. These generic exceptions and their semantics are described in . It is important to emphasize that SPDL specifies only the effect to be achieved, and not the mechanism which must be used to produce that result. While the definitions of this clause may, as an explanatory convenience, call for specific Operand Stack manipulations and object manipulations in a specific order, it is likely that the actual implementations will achieve the desired effect of a given operator in a different manner.

The arithmetic operators described below perform their operations in accordance with the rules for binary floating point arithmetic set forth in IEEE 754 using the default values where options, such as traps, are specified in IEEE 754.

In the specifications in this clause, an operator which has two or more operands of type Number shall accept both Integer and Real values within the range of the operator. If one or more operands are Integers and some operand is a Real then the Integer operands will be converted to Real to perform the operation.

AbsoluteValue

The AbsoluteValue operator takes a single operand,

  • <x: Number>
  • and returns a single result
  • <y: Number>
  • where y shall be the absolute value of x. If the operand x is of type Integer, the result y shall be of type Integer; otherwise y shall be of type Real.

    Add

    The Add operator takes two operands,

  • <y: Number>
  • <x: Number>
  • and returns a single result
  • <z: Number>
  • where z = x + y. If both operands are of type Integer, the result z shall be of type Integer if z is representable as a value of type Integer; otherwise z shall be of type Real.

    ArcTangent

    The ArcTangent operator takes two operands,

  • <x: Number>
  • <y: Number>
  • and returns a single result
  • <a: Real>
  • where a shall be the angle between 0 and 360 in degrees whose tangent is y / x. The sign of the operands determine the quadrant in which the result will lie as shown in . xyResult PositivePositivePositive X, Positive Y quadrant PositiveNegativePositive X, Negative Y quadrant NegativePositiveNegative X, Positive Y quadrant NegativeNegativeNegative X, Negative Y quadrant PositiveZero0.0 NegativeZero180.0 ZeroPositive90.0 ZeroNegative270.0 ZeroZeroRaiseError shall be invoked with UndefinedResult as its operand.

    And

    The And operator takes two operands,

  • <y: Boolean or Integer>
  • <x: Boolean or Integer>
  • and returns a single result
  • <z: Boolean or Integer>
  • Both operands must be of the same type. If both operands are of type Boolean, z shall be also of type Boolean, and the value of z shall be the Boolean intersection of the values of x and y. If both operands are of type Integer, z shall be also of type Integer, and the value of z shall be the bitwise and of the binary representations of x and y in two's complement representation.

    Ceiling

    The Ceiling operator takes a single operand,

  • <x: Number>
  • and returns a single result
  • <y: Number>
  • where y shall be the least integer value greater than or equal to x. If the operand is of type Integer, y shall be of type Integer. If the operand is of type Real, y shall be of type Real.

    Cosine

    The Cosine operator takes one operand,

  • <a: Number>
  • and returns a single result
  • <c: Real>
  • where a is an angle expressed in degrees, and c shall be the cosine of that angle.

    Divide

    The Divide operator takes two operands,

  • <y: Number>
  • <x: Number> and returns a single result
  • <z: Real>
  • where z shall be the result of dividing x by y. If y is zero, RaiseError shall be invoked with UndefinedResult as its operand.

    Equal

    The Equal operator takes two operands,

  • <y: Any>
  • <x: Any>
  • and returns a single result
  • <z: Boolean>
  • where z shall be true if x and y are both of the same type and their values are equal; and z shall be false otherwise — exceptions to this general rule are listed below.

    If x and y are both of type Number, they may be compared even if one operand is of type Integer and the other is of type Real. In this case, the operand of type Integer shall be converted to type Real and the two operands shall be compared as values of type Real.

    If x and y are both object references, then x and y are considered to be equal if they both reference the same object.

    Values of type Identifier and OctetStringReference may be compared; in this case the OctetString that corresponds to the value of type Identifier and the referenced OctetString are compared as simple sequences of octets.

    The attributes (18.4) associated with the values are not considered in determining the equality of values.

    Exponentiate

    The Exponentiate operator takes two operands,

  • <y: Number>
  • <x: Number>
  • and returns a single result
  • <z: Real>
  • where the value of z shall be x raised to the y power. If x is negative and y has a fractional component, RaiseError shall be invoked with UndefinedResult as its operand.

    False

    The False operator takes no operands and returns a single result

  • <false: Boolean>
  • which shall be a Boolean value which shall be false.

    Floor

    The Floor operator takes a single operand,

  • <x: Number>
  • and returns a single result
  • <y: Number>
  • where y shall be the greatest integer value less than or equal to x. If the operand is of type Integer, y shall be of type Integer. If the operand is of type Real, y shall be of type Real.

    GreaterOrEqual

    The GreaterOrEqual operator takes two operands,

  • <y: Number>
  • <x: Number>
  • and returns a single result
  • <z: Boolean>
  • where z shall be the result of {x y LessThan Not}.

    GreaterThan

    The GreaterThan operator takes two operands,

  • <y: Number>
  • <x: Number>
  • and returns a single result
  • <z: Boolean>
  • where z shall be true if x > y, and z shall be false otherwise.

    IntegerDivide

    The IntegerDivide operator takes two operands,

  • <y: Integer>
  • <x: Integer>
  • and returns a single result
  • <z: Integer>
  • where z shall be the result of {x y Divide Truncate}. If y is zero, RaiseError shall be invoked with UndefinedResult as its operand.

    LessOrEqual

    The LessOrEqual operator takes two operands,

  • <y: Number>
  • <x: Number>
  • and returns a single result
  • <z: Boolean>
  • where z shall be the result of {x y GreaterThan Not Not}.

    LessThan

    The LessThan operator takes two operands,

  • <y: Number>
  • <x: Number>
  • and returns a single result
  • <z: Boolean>
  • where z shall be true if x < y, and z shall be false otherwise.

    Logarithm

    The Logarithm operator takes one operand,

  • <n: Number>
  • and returns a single result
  • <log: Real>
  • where log shall be the common logarithm (base 10) of n.

    LogicalShift

    The LogicalShift operator takes two operands,

  • <s: Integer>
  • <m: Integer>
  • and returns a single result
  • <n: Integer>
  • where m is the value whose binary representation is to be logically shifted, s specifies the number of bits to shift and the direction of the shift, and n shall be the resultant shifted value. If s is positive, a left-shift of s bits shall be performed on m; if s is negative a right-shift shall be performed on m. Bits shifted in shall have a zero value.

    Multiply

    The Multiply operator takes two operands,

  • <y: Number>
  • <x: Number>
  • and returns a single result
  • <z: Number>
  • where z is the result of multiplying x by y. If both operands are of type Integer, the result z shall be of type Integer if z is representable as a value of type Integer and a value of type Real, otherwise; otherwise z shall be of type Real.

    NaturalLogarithm

    The NaturalLogarithm operator takes one operand,

  • <n: Number>
  • and returns a single result
  • <ln: Real>
  • where ln shall be the natural logarithm (the logarithm base e) of n.

    Negate

    The Negate operator takes a single operand,

  • <x: Number>
  • and returns a single result
  • <y: Number>
  • where y = -x. If the operand x is of type Integer, the result y shall be of type Integer; otherwise y shall be of type Real.

    Not

    The Not operator takes a single operand,

  • <x: Boolean or Integer>
  • and returns a single result
  • <z: Boolean or Integer>
  • If the operand is of type Boolean, z shall also be of type Boolean; the value of z shall be true if the value of x is false, and z shall be false otherwise. If the operand is of type Integer, z shall also be of type Integer, and the value of z shall be the one's complement of the binary representation of x.

    NotEqual

    The NotEqual operator takes two operands,

  • <y: Any>
  • <x: Any>
  • and returns a single result
  • <z: Boolean>
  • where z is the result of {x y Equal Not}.

    Null

    The Null operator takes no operands and returns a single result

  • <null: Null>
  • which shall be the value of type Null.

    Or

    The Or operator takes two operands,

  • <y: Boolean or Integer>
  • <x: Boolean or Integer>
  • and returns a single result
  • <z: Boolean or Integer>
  • Both operands must be of the same type. If both operands are of type Boolean, z shall also be of type Boolean, and the value of z shall be the Boolean union of the values of x and y. If both operands are of type Integer, z shall also be of type Integer, and the value of z shall be the bitwise 'inclusive or' of the binary representations of x and y.

    Rand

    The Rand operator takes no operands and returns a single result

  • <rand: Real>
  • where the returned value shall be a pseudo random number between 0 and 1 inclusive.

    RandSetState

    The RandSetState operator takes a single operand

  • <seed: Integer>
  • and returns no results. The effect shall be to initialize the state of the random number generator. A given seed will always result in the same set of numbers returned from the Rand operator in the same order on a given implementation. A given seed may not produce the same set of numbers across implementations. The seed shall be automatically set to a random value at the beginning of each high-level structure (DOCUMENT, PAGESET, PAGE, or PICTURE).

    Remainder

    The Remainder operator takes two operands,

  • <y: Integer>
  • <x: Integer>
  • and returns a single result
  • <z: Integer>
  • where z shall be the remainder that results from the integer division of x by y. The sign of z shall be the same as the sign of x. If y is zero, RaiseError shall be invoked with UndefinedResult as its operand.
  • {x y Remainder}
  • shall be equivalent to
  • {x y x y IntegerDivide Multiply Subtract}
  • Round

    The Round operator takes a single operand,

  • <x: Number>
  • and returns a single result
  • <y: Integer>
  • where y shall be the integer value nearest to x. If x is equally close to two integer values then y shall be the larger of the two.

    Sine

    The Sine operator takes one operand,

  • <a: Number>
  • and returns a single result
  • <s: Real>
  • where a is an angle expressed in degrees, and s shall be the sine of that angle.

    SquareRoot

    The SquareRoot operator takes one operand,

  • <x: Number>
  • and returns a single result
  • <y: Real>
  • where x shall be non-negative, and the result y shall be the non-negative square root of x.

    Subtract

    The Subtract operator takes two operands,

  • <y: Number>
  • <x: Number>
  • and returns a single result
  • <z: Number>
  • where z = x - y. If both operands are of type Integer, the result z shall be of type Integer if z is representable as a value of type Integer; otherwise z shall be of type Real.

    True

    The True operator takes no operands and returns a single result

  • <true: Boolean>
  • which shall be a Boolean value which shall be true.

    Truncate

    The Truncate operator takes a single operand,

  • <x: Number>
  • and returns a single result
  • <y: Number>
  • If x is greater than or equal to zero, then y shall be the greatest integer value less than or equal to x. If x is less than zero, then y shall be the least integer value greater than or equal to x. If the operand is of type Integer, y shall be of type Integer. If the operand is of type Real, y shall be of type Real.

    Xor

    The Xor operator takes two operands,

  • <y: Boolean or Integer>
  • <x: Boolean or Integer>
  • and returns a single result
  • <z: Boolean or Integer>
  • Both operands must be of the same type. If both operands are of type Boolean, z shall also be of type Boolean; the value of z shall be true if the values of x and y are different, and z shall be false otherwise. If both operands are of type Integer, z shall also be of type Integer, and the value of z shall be the bitwise 'exclusive or' of the binary representations of x and y.