# FLOAT

A double precision (64-bit) IEEE 754 floating point. The rounding mode is round to nearest.

Literals in base 10 may begin with an optional negative sign `-`, followed by whole part, optionally followed by fractional part, optionally followed by exponent where:

• Decimal digit: Characters `0` through `9`.
• Whole part: A nonempty sequence of decimal digits.
• Fractional part: A decimal point `.` followed by nonempty sequence of decimal digits.
• Exponent: An `e` marker followed by optional `-` / `+` sign followed by nonempty sequence of decimal digits.

Literals in base 16 may begin with an optional negative sign `-`, followed by hexadecimal base indicator `0x`, followed by whole part, optionally followed by fractional part, optionally followed by exponent where:

• Hexadecimal digit: Decimal digit or letters `a` through `f` or letters `A` through `F`.
• Whole part: A nonempty sequence of hexadecimal digits.
• Fractional part: A decimal point `.` followed by nonempty sequence of hexadecimal digits.
• Exponent: A `p` marker followed by optional `-` / `+` sign followed by nonempty sequence of decimal digits. Note that the exponent is always given in base 10, even when the whole and fractional parts are in hexadecimal.

Hexadecimal floating point values are case insensitive.

Negative values are also permitted. The `-` forms part of literal syntax.

Literals missing both the fractional part and the exponent will be interpreted as INTEGER literals, and implicit conversion to a FLOAT constant will be performed at compile time provided that the integer in question can be accurately represented as a FLOAT quantity. A compilation error is given if this conversion cannot be performed.

For example:

``declare local var.f FLOAT;set var.f = 1.2;set var.f = 1.2e3;set var.f = -1.2e-3;set var.f = 1e3;set var.f = 0xA.B;set var.f = 0xA.Bp3;set var.f = -0xA.Bp-3;set var.f = 0xAp3;``

Floating point values are grouped into one of several classifications:

• Finite`math.is_finite` A value that is neither NaN nor an infinity.

• Subnormal`math.is_subnormal` The FLOAT type supports subnormals (also known as denormals).

• NaN`math.is_nan` The FLOAT type may express NaN (Not a Number). In general, arithmetic operations involving a NaN will produce NaN. NaN values are signaled through the `"fastly.error"` variable.

There is no literal syntax for assigning NaN, but a `math.NAN` constant is provided.

• Normal`math.is_normal` A value that is neither NaN, subnormal, an infinity nor a zero.

Note that "normal" is not the exact opposite of "subnormal" because of the other possible non-subnormal values.

• Infinite`math.is_infinite` The FLOAT type may express IEEE 754 infinities. These are signed values. Infinities behave with special semantics for some operators.

There is no literal syntax for assigning infinities, but `math.POS_INFINITY` and `math.NEG_INFINITY` constants are provided.

• Zero There are two kinds of zero: positive and negative. Both compare equal.

No VCL function is provided to determine whether a floating point value is a zero. Because both positive and negative zero compare equal, a comparison may be made simply by `var.x == 0`.

Conversions to STRING values are always rendered to 3dp (3 decimal places) precision:

``declare local var.f FLOAT;set var.f = -3.5;log var.f; /* "-3.500" */``