Float syntax

Factor handbook » The language » Syntax » Literals » Number syntax

Factor handbook » The language » Syntax » Literals » Number syntax

Prev: | Ratio syntax |

Next: | Complex number syntax |

Floating point literals are specified when a literal number contains a decimal point or exponent. Exponents are marked by an e or E:

Literal numbers without a decimal point or an exponent always parse as integers:

Literal floating point approximations of ratios can also be input by placing a decimal point in the denominator:

The special float values have their own syntax:

A Not-a-number literal with an arbitrary payload can also be input:

To see the 64 bit value of 0/0. on your platform, execute the following code :

Hexadecimal, octal and binary float literals are also supported. These consist of a hexadecimal, octal or binary literal with a decimal point and a mandatory base-two exponent expressed as a decimal number after p or P:

The normalized hex form ±0x1.MMMMMMMMMMMMMp±EEEE allows any floating-point number to be specified precisely. The values of MMMMMMMMMMMMM and EEEE map directly to the mantissa and exponent fields of the binary IEEE 754 representation.

More information on floats can be found in Floats.

10.5
-3.1456
7e13
1.0e-5
1.0E+5

Literal numbers without a decimal point or an exponent always parse as integers:

1 float? .

f

f

1. float? .

t

t

1e0 float? .

t

t

Literal floating point approximations of ratios can also be input by placing a decimal point in the denominator:

1/2. .

0.5

0.5

1/3. .

0.3333333333333333

0.3333333333333333

1/0.5 .

2.0

2.0

1/2.5 .

0.4

0.4

1+1/2. .

1.5

1.5

1+1/2.5 .

1.4

1.4

The special float values have their own syntax:

Positive infinity | 1/0. |

Negative infinity | -1/0. |

Not-a-number (positive) | 0/0. |

Not-a-number (negative) | -0/0. |

A Not-a-number literal with an arbitrary payload can also be input:

NAN:

To see the 64 bit value of 0/0. on your platform, execute the following code :

USING: io math math.parser ;
"NAN: " write 0/0. double>bits >hex print

Hexadecimal, octal and binary float literals are also supported. These consist of a hexadecimal, octal or binary literal with a decimal point and a mandatory base-two exponent expressed as a decimal number after p or P:

8.0 0x1.0p3 = .

t

t

-1024.0 -0x1.0P10 = .

t

t

10.125 0x1.44p3 = .

t

t

10.125 0b1.010001p3 = .

t

t

10.125 0o1.21p3 = .

t

t

The normalized hex form ±0x1.MMMMMMMMMMMMMp±EEEE allows any floating-point number to be specified precisely. The values of MMMMMMMMMMMMM and EEEE map directly to the mantissa and exponent fields of the binary IEEE 754 representation.

More information on floats can be found in Floats.

This documentation was generated offline from a
`load-all`

image. If you want, you can also
browse the documentation from within the UI developer tools. See
the Factor website
for more information.

Factor 0.99 x86.64 (2173, heads/master-f3ee5c5979, Sep 18 2022 13:17:51)