Home / Docs / Specification / 29. Numerics
29.4 Conversions
Release v0.4.0
- From integers.
n.to_f64()with no argument, onIntor a fixed-width integer, is IEEEconvertFromInt: the nearest binary64 value, ties to even, decided on every bit of the integer. It is exact for every integer of magnitude at most 2^53. AnIntof magnitude 2^1024 − 2^970 or more gives an infinity of its sign. It never fails, and it resolves ahead of a function of the same name. - To integers.
x.to_int_exact()givesOption[Int]:Some(n)whenxis finite and integral, withnits exact value (-0.0givesSome(0)), andNonefor NaN, an infinity and a value with a fraction. The rounding is the program's to write:x.floor().to_int_exact(). A fixed-width integer is reached throughInt, by the conversions of spec/18 §4. - No other conversion.
x.to_int()andx.to_i64()and the other integer conversions on anF64are U2001, with a repair toto_int_exact().