pub enum FloatValue {
Float {
value: f64,
precision: u32,
},
Decimal {
value: BigDecimal,
precision: u32,
},
}Expand description
The value handed to the float path, mirroring what Python’s dispatcher saw.
base.float2tuple branches on isinstance(value, Decimal): the Decimal
arm is exact arbitrary precision, the float arm is lossy f64. They are not
interchangeable — issue #603 exists precisely because a float() cast
silently rounded 98_746_251_323_029.99 at trillion scale.
Variants§
Float
Python passed a float. precision is derived from repr on the
Python side.
Decimal
Python passed a Decimal. precision is abs(exponent).
Implementations§
Source§impl FloatValue
impl FloatValue
pub fn precision(&self) -> u32
pub fn is_negative(&self) -> bool
Sourcepub fn has_visible_point(&self) -> bool
pub fn has_visible_point(&self) -> bool
Whether Python’s string form of the value shows a decimal point —
the "." in str(value) test many self-contained converters route on.
repr(float) has a point unless repr picked exponent form (1e+16);
str(Decimal) has one exactly when the scale is positive.
Sourcepub fn as_whole_int(&self) -> Option<BigInt>
pub fn as_whole_int(&self) -> Option<BigInt>
Python’s int(value) == value routing test: Some(int) when the
value is whole, None when fractional. NaN/±inf return None — the
dispatcher keeps those on the Python side (base’s assert raises
OverflowError/ValueError there, outside the whole-value route).
Sourcepub fn whole_float_int(&self) -> Option<BigInt>
pub fn whole_float_int(&self) -> Option<BigInt>
PR savoirfairelinux/num2words#666: the dispatcher’s
isinstance(number, float) and number == int(number) test — Some(int)
only for a genuine float (not Decimal) whose value is integral.
Routes a whole float through the integer to_ordinal_num so the result
formats without the decimal point (“1st”, not “1.0st”). Decimals keep
their scale (“5.00th”), matching isinstance(number, float) == False.
Trait Implementations§
Source§impl Clone for FloatValue
impl Clone for FloatValue
Source§fn clone(&self) -> FloatValue
fn clone(&self) -> FloatValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more