Skip to main content

FloatValue

Enum FloatValue 

Source
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.

Fields

§value: f64
§precision: u32
§

Decimal

Python passed a Decimal. precision is abs(exponent).

Fields

§precision: u32

Implementations§

Source§

impl FloatValue

Source

pub fn precision(&self) -> u32

Source

pub fn is_negative(&self) -> bool

Source

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.

Source

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).

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FloatValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.