Logical functions

The TrueType instruction set includes a set of logical functions that can be used to test the value of a stack element or to compare the values of two stack elements. The logical functions compare 32 bit values (ULONG) and return a Boolean value to the top of the stack.

To easily remember the order in which stack values are handled during logical operations, imagine writing the stack values from left to right, starting with the bottom value. Then insert the operator between the two furthest right elements. For example:

GT a,b would be interpreted as (b>a):

c b > a

Less Than

LT[ ]

Code Range

0x50

Pops

e2: stack element (ULONG)

e1: stack element (ULONG)

Pushes

Boolean value (ULONG in the range [0,1])


Pops e2 and e1 off the stack and compares them: if e1 is less than e2, 1, signifying TRUE, is pushed onto the stack. If e1 is not less than e2, 0, signifying FALSE, is placed onto the stack.

Example:

LT[ ]

Less Than or Equal

LTEQ[ ]

Code Range

0x51

Pops

e2: stack element (ULONG)

e1: stack element (ULONG)

Pushes

Boolean value (ULONG in the range [0,1])


Pops e2 and e1 off the stack and compares them. If e1 is less than or equal to e2, 1, signifying TRUE, is pushed onto the stack. If e1 is not less than or equal to e2, 0, signifying FALSE, is placed onto the stack.

Example:

LTEQ[ ]

Greater Than

GT[ ]

Code Range

0x52

Pops

e2: stack element (ULONG)

e1: stack element (ULONG)

Pushes

Boolean value (ULONG in the range [0,1])


Pops e1 and e2 off the stack and compares them. If e1 is greater than e2, 1, signifying TRUE, is pushed onto the stack. If e1 is not greater than e2, 0, signifying FALSE, is placed onto the stack.

Example:

GT[ ]

Greater Than or Equal

GTEQ[ ]

Code Range

0x53

Pops

e2: stack element (ULONG)

e1: stack element (ULONG)

Pushes

Boolean value (ULONG in the range [0,1])


Pops e1 and e2 off the stack and compares them. If e1 is greater than or equal to e2, 1, signifying TRUE, is pushed onto the stack. If e1 is not greater than or equal to e2, 0, signifying FALSE, is placed onto the stack.

Example:

GTEQ[ ]

EQual

EQ[ ]

Code Range

0x54

Pops

e1: stack element (ULONG)

e2: stack element (ULONG)

Pushes

Boolean value (ULONG in the range [0,1])


Pops e1 and e2 off the stack and compares them. If they are equal, 1, signifying TRUE is pushed onto the stack. If they are not equal, 0, signifying FALSE is placed onto the stack.

Example:

EQ[ ]

Not EQual

NEQ[ ]

Code Range

0x55

Pops

e1:stack element (ULONG)

e2: stack element (ULONG)

Pushes

Boolean value (ULONG in the range [0,1])


Pops e1 and e2 from the stack and compares them. If they are not equal, 1, signifying TRUE, is pushed onto the stack. If they are equal, 0, signifying FALSE, is placed on the stack.

Example:

ODD

ODD[ ]

Code Range

0x56

Pops

e1: stack element (F26Dot6)

Pushes

Boolean value

Uses

round_state


Tests whether the number at the top of the stack is odd. Pops e1 from the stack and rounds it as specified by the round_state before testing it. After the value is rounded, it is shifted from a fixed point value to an integer value (any fractional values are ignored). If the integer value is odd, one, signifying TRUE, is pushed onto the stack. If it is even, zero, signifying FALSE is placed onto the stack.

Example:

ODD[ ]

This example assumes that round_state is RTG.

EVEN

EVEN[ ]

Code Range

0x57

Pops

e1: stack element (F26Dot6)

Pushes

Boolean value (ULONG in the range [0,1])

Uses

round_state


Tests whether the number at the top of the stack is even. Pops e1 off the stack and rounds it as specified by the round_state before testing it. If the rounded number is even, one, signifying TRUE, is pushed onto the stack if it is odd, zero, signifying FALSE, is placed onto the stack.

Example:

EVEN[ ]

This example assumes that round_state is RTG.

logical AND

AND[ ]

Code Range

0x5A

Pops

e1: stack element (ULONG)

e2: stack element (ULONG)

Pushes

( e1 and e2 ): logical and of e1 and e2 (ULONG)


Pops e1 and e2 off the stack and pushes onto the stack the result of a logical and of the two elements. Zero is returned if either or both of the elements are FALSE (have the value zero). One is returned if both elements are TRUE (have a non zero value).

case 1:

AND[ ]

case 2:

AND[ ]

logical OR

OR[ ]

Code Range

0x5B

Pops

e1: stack element (ULONG)

e2: stack element (ULONG)

Pushes

(e1 or e2): logical or of e1 and e2 (ULONG)


Pops e1 and e2 off the stack and pushes onto the stack the result of a logical or operation between the two elements. Zero is returned if both of the elements are FALSE. One is returned if either both of the elements are TRUE.

Example:

case 1:

OR[ ]

case 2:

OR[ ]

logical NOT

NOT[ ]

Code Range

0x5C

Pops

e: stack element (ULONG)

Pushes

(not e): logical negation of e (ULONG)


Pops e off the stack and returns the result of a logical NOT operation performed on e. If originally zero, one is pushed onto the stack if originally nonzero, zero is pushed onto the stack.

Example:

case 1:

case 2: