Previous:Comments Main Index Next:Float Literals

### Float Expressions

Many parts of the POV-Ray language require you to specify one or more floating point numbers. A floating point number is a number with a decimal point. Floats may be specified using literals, identifiers or functions which return float values. You may also create very complex float expressions from combinations of any of these using various familiar operators.

Where POV-Ray needs an integer value it allows you to specify a float value and it truncates it to an integer. When POV-Ray needs a logical or boolean value it interprets any non-zero float as true and zero as false. Because float comparisons are subject to rounding errors POV-Ray accepts values extremely close to zero as being false when doing boolean functions. Typically values whose absolute values are less than a preset value epsilon are considered false for logical expressions. The value of epsilon is system dependent but is generally about 1.0e-10. Two floats a and b are considered to be equal if abs(a-b) < epsilon.

The full syntax for float expressions is given below. Detailed explanations are given in the following sub-sections.

FLOAT:
  NUMERIC_TERM [SIGN NUMERIC_TERM]
SIGN:

`
  +
` | `-`
NUMERIC_TERM:
  NUMERIC_FACTOR [MULT NUMERIC_FACTOR]
MULT:
`
  *
` | `/`
NUMERIC_FACTOR:
  FLOAT_LITERAL
|
  FLOAT_IDENTIFIER
|
  SIGN NUMERIC_FACTOR
|
  FLOAT_FUNCTION
|
  FLOAT_BUILT-IN_IDENT
| `
  (
` FULL_EXPRESSION `)` | `
  !
` NUMERIC_FACTOR |
  VECTOR DECIMAL_POINT DOT_ITEM
FLOAT_LITERAL:
  [DIGIT...] [DECIMAL_POINT] DIGIT... [EXP [SIGN] DIGIT...]
DIGIT:
`
  0
` | `1` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9`
DECIMAL_POINT:
`
  .
`
EXP:
`
  e
` | `E`
DOT_ITEM:
`
  x
` | `y` | `z` | `t` | `u` | `v` | `red` | `blue` | `green` | `filter` | `transmit`
FLOAT_FUNCTION:
`
  abs(
` FLOAT `)` | `acos(` FLOAT `)` | `val(` STRING `)` | `asc(` STRING `)` | `
  asin(
` FLOAT `)` | `atan2(` FLOAT `,` FLOAT `)` | `ceil(` FLOAT `)` | `cos(` FLOAT `)` | `
  defined(
`IDENTIFIER `)` | `degrees(` FLOAT `)` | `div(` FLOAT `,` FLOAT `)` | `exp(` FLOAT `)` | `
  file_exists(
` STRING `)` | `floor(` FLOAT `)` | `int(` FLOAT `)` | `log(` FLOAT `)` | `
  max(
` FLOAT `,` FLOAT `)` | `min(` FLOAT `,` FLOAT `)` | `mod(` FLOAT `,` FLOAT `)` | `
  pow(
` FLOAT `,` FLOAT `)` | `radians(` FLOAT `)` | `sin(` FLOAT `)` | `sqrt(` FLOAT `)` | `
  strcmp(
` STRING `,` STRING `)` | `strlen(` STRING `)` | `tan(` FLOAT `)` | `
  vdot(
` VECTOR `,` VECTOR `)` | `vlength(` VECTOR `)` | `seed(` FLOAT `)` | `rand(` FLOAT `)` | `
  dimensions(
` ARRAY_IDENTIFIER `)` | `dimension_size(` ARRAY_IDENTIFIER `,` FLOAT `)`
FLOAT_BUILT-IN_IDENT:
`
  clock
` | `pi` | `version` | `true` | `yes` | `on` | `false` | `no` | `
  off
` | `clock_delta`
FULL_EXPRESSION:
  LOGICAL_EXPRESSION [
`?` FULL_EXPRESSION `:` FULL_EXPRESSION]
LOGICAL_EXPRESSION:
  REL_TERM [LOGICAL_OPERATOR REL_TERM]
LOGICAL_OPERATOR:
`
  &
` | `|` (note this means an ampersand or a vertical bar is a logical operator)
REL_TERM:
  FLOAT [REL_OPERATOR FLOAT]
REL_OPERATOR:
`
  <
` | `<=` | `=` | `>=` | `>` | `!=`
INT:
  FLOAT
(note any syntax which requires a integer INT will accept a FLOAT and it will be truncated
  to an integer internally by POV-Ray).

Note: FLOAT_IDENTIFIERS are identifiers previously declared to have float values. The DOT_ITEM syntax is actually a vector or color operator but it returns a float value. See "Vector Operators" or "Color Operators" for details. An ARRAY_IDENTIFIER is just the identifier name of a previously declared array, it does not include the `[]` braces nor the index. The syntax for STRING is in the section "Strings".

Previous:Comments Main Index Next:Float Literals