Struct Float

Source
pub struct Float<FT: FloatTraits> { /* private fields */ }
Expand description

the floating-point type with the specified FloatTraits

Implementations§

Source§

impl<Bits: FloatBitsType, FT: FloatTraits<Bits = Bits>> Float<FT>

Source

pub fn from_bits_and_traits(bits: Bits, traits: FT) -> Self

construct Float from bits

Source

pub fn from_bits(bits: Bits) -> Self
where FT: Default,

construct Float from bits

Source

pub fn bits(&self) -> &Bits

get the underlying bits

Source

pub fn set_bits(&mut self, bits: Bits)

set the underlying bits

Source

pub fn traits(&self) -> &FT

get the FloatTraits

Source

pub fn into_bits_and_traits(self) -> (Bits, FT)

get the bits and FloatTraits

Source

pub fn into_bits(self) -> Bits

get the underlying bits

Source

pub fn into_traits(self) -> FT

get the FloatTraits

Source

pub fn properties(&self) -> FloatProperties

get the FloatProperties

Source

pub fn sign(&self) -> Sign

get the sign

Source

pub fn set_sign(&mut self, sign: Sign)

set the sign

Source

pub fn toggle_sign(&mut self)

toggle the sign

Source

pub fn exponent_field(&self) -> Bits

get the exponent field

the mathematical exponent and the exponent field’s values for normal floating-point numbers are related by the following equation: mathematical_exponent + exponent_bias == exponent_field

Source

pub fn set_exponent_field(&mut self, exponent: Bits)

set the exponent field

the mathematical exponent and the exponent field’s values for normal floating-point numbers are related by the following equation: mathematical_exponent + exponent_bias == exponent_field

Source

pub fn mantissa_field(&self) -> Bits

get the mantissa field

Source

pub fn set_mantissa_field(&mut self, mantissa: Bits)

set the mantissa field

Source

pub fn mantissa_field_msb(&self) -> bool

get the mantissa field’s MSB

Source

pub fn set_mantissa_field_msb(&mut self, mantissa_msb: bool)

set the mantissa field’s MSB

Source

pub fn class(&self) -> FloatClass

calculate the FloatClass

Source

pub fn is_negative_infinity(&self) -> bool

return true if self.class() is NegativeInfinity

Source

pub fn is_negative_normal(&self) -> bool

return true if self.class() is NegativeNormal

Source

pub fn is_negative_subnormal(&self) -> bool

return true if self.class() is NegativeSubnormal

Source

pub fn is_negative_zero(&self) -> bool

return true if self.class() is NegativeZero

Source

pub fn is_positive_infinity(&self) -> bool

return true if self.class() is PositiveInfinity

Source

pub fn is_positive_normal(&self) -> bool

return true if self.class() is PositiveNormal

Source

pub fn is_positive_subnormal(&self) -> bool

return true if self.class() is PositiveSubnormal

Source

pub fn is_positive_zero(&self) -> bool

return true if self.class() is PositiveZero

Source

pub fn is_quiet_nan(&self) -> bool

return true if self.class() is QuietNaN

Source

pub fn is_signaling_nan(&self) -> bool

return true if self.class() is SignalingNaN

Source

pub fn is_infinity(&self) -> bool

return true if self is infinity

Source

pub fn is_normal(&self) -> bool

return true if self.class() is NegativeNormal or PositiveNormal

Source

pub fn is_subnormal(&self) -> bool

return true if self is subnormal

Source

pub fn is_zero(&self) -> bool

return true if self is zero

Source

pub fn is_nan(&self) -> bool

return true if self is NaN

Source

pub fn is_finite(&self) -> bool

return true if self is finite (not NaN or infinity)

Source

pub fn is_subnormal_or_zero(&self) -> bool

return true if self is subnormal or zero

Source

pub fn to_ratio(&self) -> Option<Ratio<BigInt>>

get the mathematical value of self as a Ratio<BigInt>. if self is NaN or infinite, returns None.

Source

pub fn to_real_algebraic_number(&self) -> Option<RealAlgebraicNumber>

get the mathematical value of self as a RealAlgebraicNumber. if self is NaN or infinite, returns None.

Source

pub fn positive_zero_with_traits(traits: FT) -> Self

get the positive zero value

Source

pub fn positive_zero() -> Self
where FT: Default,

get the positive zero value

Source

pub fn negative_zero_with_traits(traits: FT) -> Self

get the negative zero value

Source

pub fn negative_zero() -> Self
where FT: Default,

get the negative zero value

Source

pub fn signed_zero_with_traits(sign: Sign, traits: FT) -> Self

get the zero with sign sign

Source

pub fn signed_zero(sign: Sign) -> Self
where FT: Default,

get the zero with sign sign

Source

pub fn positive_infinity_with_traits(traits: FT) -> Self

get the positive infinity value

Source

pub fn positive_infinity() -> Self
where FT: Default,

get the positive infinity value

Source

pub fn negative_infinity_with_traits(traits: FT) -> Self

get the negative infinity value

Source

pub fn negative_infinity() -> Self
where FT: Default,

get the negative infinity value

Source

pub fn signed_infinity_with_traits(sign: Sign, traits: FT) -> Self

get the infinity with sign sign

Source

pub fn signed_infinity(sign: Sign) -> Self
where FT: Default,

get the infinity with sign sign

Source

pub fn quiet_nan_with_traits(traits: FT) -> Self

get the canonical quiet NaN, which is also just the canonical NaN

Source

pub fn quiet_nan() -> Self
where FT: Default,

get the canonical quiet NaN, which is also just the canonical NaN

Source

pub fn signaling_nan_with_traits(traits: FT) -> Self

get the canonical signaling NaN

Source

pub fn signaling_nan() -> Self
where FT: Default,

get the canonical signaling NaN

Source

pub fn into_quiet_nan(self) -> Self

convert self into a quiet NaN

Source

pub fn to_quiet_nan(&self) -> Self

convert self into a quiet NaN

Source

pub fn signed_max_normal_with_traits(sign: Sign, traits: FT) -> Self

get the largest finite value with sign sign

Source

pub fn signed_max_normal(sign: Sign) -> Self
where FT: Default,

get the largest finite value with sign sign

Source

pub fn signed_min_subnormal_with_traits(sign: Sign, traits: FT) -> Self

get the subnormal value closest to zero with sign sign

Source

pub fn signed_min_subnormal(sign: Sign) -> Self
where FT: Default,

get the subnormal value closest to zero with sign sign

Source

pub fn from_real_algebraic_number_with_traits( value: &RealAlgebraicNumber, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

round from a RealAlgebraicNumber into a floating-point value.

Source

pub fn from_real_algebraic_number( value: &RealAlgebraicNumber, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

round from a RealAlgebraicNumber into a floating-point value.

Source

pub fn add( &self, rhs: &Self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

add floating-point numbers

Source

pub fn sub( &self, rhs: &Self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

subtract floating-point numbers

Source

pub fn mul( &self, rhs: &Self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

multiply floating-point numbers

Source

pub fn div( &self, rhs: &Self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

divide floating-point numbers

Source

pub fn ieee754_remainder( &self, rhs: &Self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

compute the IEEE 754 remainder of two floating-point numbers

Source

pub fn fused_mul_add( &self, factor: &Self, term: &Self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

calculate the result of (self * factor) + term rounding only once, returning the result

Source

pub fn round_to_integer( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<BigInt>

round self to an integer, returning the result as an integer or None

Source

pub fn round_to_integral( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

round self to an integer, returning the result as a Float

Source

pub fn normalize(&mut self)

normalize self. This is a no-op for all floating-point formats where has_implicit_leading_bit is true (which includes all standard floating-point formats).

Source

pub fn next_up_or_down( &self, up_or_down: UpOrDown, fp_state: Option<&mut FPState>, ) -> Self

compute the result of next_up or next_down

Source

pub fn next_up(&self, fp_state: Option<&mut FPState>) -> Self

compute the least floating-point number that compares greater than self

Source

pub fn next_down(&self, fp_state: Option<&mut FPState>) -> Self

compute the greatest floating-point number that compares less than self

Source

pub fn log_b(&self, fp_state: Option<&mut FPState>) -> Option<BigInt>

get the floor of the log base 2 of the absolute value of self

Source

pub fn scale_b( &self, scale: BigInt, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

get self * 2^scale

Source

pub fn sqrt( &self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

get the square-root of self

Source

pub fn convert_from_float_with_traits<SrcFT: FloatTraits>( src: &Float<SrcFT>, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert src to the floating-point format specified by traits.

Source

pub fn convert_from_float<SrcFT: FloatTraits>( src: &Float<SrcFT>, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert src to the floating-point format specified by FT::default() where Self is Float<FT>.

Source

pub fn convert_to_float_with_traits<DestFT: FloatTraits>( &self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: DestFT, ) -> Float<DestFT>

convert self to the floating-point format specified by traits.

Source

pub fn convert_to_float<DestFT: FloatTraits + Default>( &self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Float<DestFT>

convert self to the floating-point format specified by DestFT::default().

Source

pub fn neg_assign(&mut self)

negate and assign the result back to self. identical to self.toggle_sign()

Source

pub fn neg(&self) -> Self

compute the negation of self

Source

pub fn abs_assign(&mut self)

compute the absolute-value and assign the result back to self. identical to self.set_sign(Sign::Positive)

Source

pub fn abs(&self) -> Self

compute the absolute-value

Source

pub fn copy_sign_assign<FT2: FloatTraits>(&mut self, sign_src: &Float<FT2>)

set self’s sign to the sign of sign_src

Source

pub fn copy_sign<FT2: FloatTraits>(&self, sign_src: &Float<FT2>) -> Self

construct a Float from self but with the sign of sign_src

Source

pub fn compare( &self, rhs: &Self, quiet: bool, fp_state: Option<&mut FPState>, ) -> Option<Ordering>

compare two Float values

Source

pub fn compare_quiet( &self, rhs: &Self, fp_state: Option<&mut FPState>, ) -> Option<Ordering>

compare two Float values

Source

pub fn compare_signaling( &self, rhs: &Self, fp_state: Option<&mut FPState>, ) -> Option<Ordering>

compare two Float values

Source

pub fn from_bigint_with_traits( value: BigInt, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_bigint( value: BigInt, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_biguint_with_traits( value: BigUint, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_biguint( value: BigUint, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_u8_with_traits( value: u8, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_u8( value: u8, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_u16_with_traits( value: u16, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_u16( value: u16, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_u32_with_traits( value: u32, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_u32( value: u32, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_u64_with_traits( value: u64, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_u64( value: u64, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_u128_with_traits( value: u128, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_u128( value: u128, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_usize_with_traits( value: usize, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_usize( value: usize, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_i8_with_traits( value: i8, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_i8( value: i8, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_i16_with_traits( value: i16, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_i16( value: i16, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_i32_with_traits( value: i32, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_i32( value: i32, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_i64_with_traits( value: i64, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_i64( value: i64, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_i128_with_traits( value: i128, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_i128( value: i128, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn from_isize_with_traits( value: isize, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, traits: FT, ) -> Self

convert from integer to floating-point

Source

pub fn from_isize( value: isize, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self
where FT: Default,

convert from integer to floating-point

Source

pub fn to_bigint( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<BigInt>

convert from floating-point to integer

Source

pub fn to_biguint( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<BigUint>

convert from floating-point to integer

Source

pub fn to_u8( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<u8>

convert from floating-point to integer

Source

pub fn to_u16( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<u16>

convert from floating-point to integer

Source

pub fn to_u32( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<u32>

convert from floating-point to integer

Source

pub fn to_u64( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<u64>

convert from floating-point to integer

Source

pub fn to_u128( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<u128>

convert from floating-point to integer

Source

pub fn to_usize( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<usize>

convert from floating-point to integer

Source

pub fn to_i8( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<i8>

convert from floating-point to integer

Source

pub fn to_i16( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<i16>

convert from floating-point to integer

Source

pub fn to_i32( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<i32>

convert from floating-point to integer

Source

pub fn to_i64( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<i64>

convert from floating-point to integer

Source

pub fn to_i128( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<i128>

convert from floating-point to integer

Source

pub fn to_isize( &self, exact: bool, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Option<isize>

convert from floating-point to integer

Source

pub fn rsqrt( &self, rounding_mode: Option<RoundingMode>, fp_state: Option<&mut FPState>, ) -> Self

reciprocal square root – computes 1 / sqrt(self)

Trait Implementations§

Source§

impl<FT: Clone + FloatTraits> Clone for Float<FT>
where FT::Bits: Clone,

Source§

fn clone(&self) -> Float<FT>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Bits: FloatBitsType, FT: FloatTraits<Bits = Bits>> Debug for Float<FT>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<FT: FloatTraits + Default> Default for Float<FT>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<DynamicFloat> for Float<FloatProperties>

Source§

fn from(value: DynamicFloat) -> Self

Converts to this type from the input type.
Source§

impl From<Float<FloatProperties>> for DynamicFloat

Source§

fn from(value: Float<FloatProperties>) -> Self

Converts to this type from the input type.
Source§

impl<FT: Copy + FloatTraits> Copy for Float<FT>
where FT::Bits: Copy,

Auto Trait Implementations§

§

impl<FT> Freeze for Float<FT>
where FT: Freeze, <FT as FloatTraits>::Bits: Freeze,

§

impl<FT> RefUnwindSafe for Float<FT>

§

impl<FT> Send for Float<FT>
where FT: Send, <FT as FloatTraits>::Bits: Send,

§

impl<FT> Sync for Float<FT>
where FT: Sync, <FT as FloatTraits>::Bits: Sync,

§

impl<FT> Unpin for Float<FT>
where FT: Unpin, <FT as FloatTraits>::Bits: Unpin,

§

impl<FT> UnwindSafe for Float<FT>
where FT: UnwindSafe, <FT as FloatTraits>::Bits: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.