Previous:Float Identifiers   Main Index   Next:Built-in Float Identifiers



Float Operators

Arithmetic expressions: Basic math expressions can be created from float literals, identifiers or functions using the following operators in this order of precedence...

( )

expressions in parentheses first

+A -A !A

unary minus, unary plus and logical "not"

A*B A/B

multiplication and division

A+B A-B

addition and subtraction

Relational, logical and conditional expressions may also be created. However there is a restriction that these types of expressions must be enclosed in parentheses first. This restriction, which is not imposed by most computer languages, is necessary because POV-Ray allows mixing of float and vector expressions. Without the parentheses there is an ambiguity problem. Parentheses are not required for the unary logical not operator "!" as shown above. The operators and their precedence are shown here.

Relational expressions: The operands are arithmetic expressions and the result is always boolean with 1 for true and 0 for false. All relational operators have the same precedence.

(A < B)

A is less than B

(A <= B)

A is less than or equal to B

(A = B)

A is equal to B (actually abs(A-B)<EPSILON)

(A != B)

A is not equal to B (actually abs(A-B)>=EPSILON)

(A >= B)

A is greater than or equal to B

(A > B)

A is greater than B

Logical expressions: The operands are converted to boolean values of 0 for false and 1 for true. The result is always boolean. All logical operators have the same precedence. Note that these are not bit-wise operations, they are logical.

(A & B)

true only if both A and B are true, false otherwise

(A | B)

true if either A or B or both are true

Conditional expressions: The operand C is boolean while operands A and B are any expressions. The result is of the same type as A and B.

(C ? A : B)

if C then A else B

Assuming the various identifiers have been declared, the following are examples of valid expressions...

1+2+3    2*5     1/3     Row*3    Col*5

(Offset-5)/2      This/That+Other*Thing

((This<That) & (Other>=Thing)?Foo:Bar)

Expressions are evaluated left to right with innermost parentheses evaluated first, then unary +, - or !, then multiply or divide, then add or subtract, then relational, then logical, then conditional.



Previous:Float Identifiers   Main Index   Next:Built-in Float Identifiers