Home / Docs / Specification / 29. Numerics
29.2 Literals
Release v0.4.0
ebnf
float_literal = digits "." digits [ "e" [ "-" ] exponent ] ;
digits = digit { [ "_" ] digit } ;
exponent = "0" | nonzero_digit { digit } ;- Form. A float literal has digits on both sides of the point:
0.5,1.0,6.674_30e-11,1.0e21. The integer part has no leading zero except0itself, and_stands only between digits. The exponent is written with a lowercasee, an optional-, and no+. - No ambiguity with methods and ranges. A point that a digit does not follow does not start a fraction, so
5.to_f64()is a method call on the integer5,1..5is a range, and1.0.sqrt()is a method call on1.0. Each of1.,.5,1e5,1.e5,1.0E5,1.0e+5,01.5and1.5e05is a malformed literal, U0007, with an edit to the accepted form. - No hex floats. A program that needs an exact bit pattern writes
f64_from_bits(bits:)(§3 rule 9). - Value. A literal denotes the binary64 value nearest to its exact decimal value, ties to even.
0.1is0x3FB999999999999A. - Range. A literal that rounds to an infinity, as
1.0e309, or that is not zero and rounds to zero, as1.0e-400, is U2031. A literal that rounds to a subnormal value is accepted. - Typing. A float literal is always
F64. An integer literal never takes the typeF64: whereF64is expected,1is U2001, with an edit to1.0. - Negative numbers use unary
-, which on0.0gives-0.0. There are no literals for NaN and the infinities: the prelude givesnan()andinfinity(), and-infinity()is the negative one. - The canonical form (spec/15) keeps a float literal as written.