pub struct Number<'a> { /* private fields */ }Expand description
Implementations§
Source§impl<'a> Number<'a>
impl<'a> Number<'a>
Sourcepub fn text(&self) -> &'a str
pub fn text(&self) -> &'a str
The number exactly as written: 12.50 stays 12.50, and a 30-digit integer keeps every digit.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Whether it is written with digits only, with no point and no exponent: 7 is, 7.0 and
7e0 are not.
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
The number as an i64, exactly, when it is a whole number that fits, however it is written:
7, 7.0, 700e-2 and 1e3 all are, and -0 is 0. 1.5 and 9223372036854775808
are None. No float is used on the way: a fraction is never cut, nor a digit rounded.
Sourcepub fn as_f64(&self) -> f64
pub fn as_f64(&self) -> f64
The nearest f64, correctly rounded, exactly as Rust’s own parser gives it: 1e400 is
infinite, and -0 is negative zero.
Most numbers take one multiplication or division, with no second pass. Digits that fit 2^53
and a power of ten up to 10^22 are both exact in a double, so one rounding gives the nearest
(Clinger’s fast path). A larger power still qualifies when part of it moves into the digits
and they still fit, as 123e30 is 123000000 × 10^22. The rest go through str::parse.