Expand description
This is the main data structure of this library. It represents an arbitrary-precision floating-point number. The data structure is generic and accepts the EXPONENT and MANTISSA constants, that represent the encoding number of bits that are dedicated to storing these values.
Implementations§
source§impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
sourcepub fn add_with_rm(a: Self, b: Self, rm: RoundingMode) -> Self
pub fn add_with_rm(a: Self, b: Self, rm: RoundingMode) -> Self
Computes a+b using the rounding mode rm
.
sourcepub fn sub_with_rm(a: Self, b: Self, rm: RoundingMode) -> Self
pub fn sub_with_rm(a: Self, b: Self, rm: RoundingMode) -> Self
Computes a-b using the rounding mode rm
.
source§impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
sourcepub fn mul_with_rm(a: Self, b: Self, rm: RoundingMode) -> Self
pub fn mul_with_rm(a: Self, b: Self, rm: RoundingMode) -> Self
Compute a*b using the rounding mode rm
.
source§impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
sourcepub fn div_with_rm(a: Self, b: Self, rm: RoundingMode) -> Self
pub fn div_with_rm(a: Self, b: Self, rm: RoundingMode) -> Self
Compute a/b, with the rounding mode rm
.
source§impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
sourcepub fn from_u64(val: u64) -> Self
pub fn from_u64(val: u64) -> Self
Load the integer val
into the float. Notice that the number may
overflow, or rounded to the nearest even integer.
sourcepub fn from_i64(val: i64) -> Self
pub fn from_i64(val: i64) -> Self
Load the integer val
into the float. Notice that the number may
overflow, or rounded to the nearest even integer.
sourcepub fn to_i64(&self, rm: RoundingMode) -> i64
pub fn to_i64(&self, rm: RoundingMode) -> i64
Converts and returns the rounded integral part.
sourcepub fn trunc(&self) -> Self
pub fn trunc(&self) -> Self
Returns a value that is rounded to the nearest integer that’s not larger in magnitude than this float.
sourcepub fn cast_with_rm<const E: usize, const M: usize>(
&self,
rm: RoundingMode
) -> Float<E, M>
pub fn cast_with_rm<const E: usize, const M: usize>(
&self,
rm: RoundingMode
) -> Float<E, M>
Cast to another float using the rounding mode rm
.
sourcepub fn cast<const E: usize, const M: usize>(&self) -> Float<E, M>
pub fn cast<const E: usize, const M: usize>(&self) -> Float<E, M>
Convert from one float format to another.
pub fn as_f32(&self) -> f32
pub fn as_f64(&self) -> f64
pub fn from_f32(float: f32) -> Self
pub fn from_f64(float: f64) -> Self
source§impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> Float<EXPONENT, MANTISSA>
sourcepub fn new(sign: bool, exp: i64, mantissa: BigInt<4>) -> Self
pub fn new(sign: bool, exp: i64, mantissa: BigInt<4>) -> Self
Create a new normal floating point number.
sourcepub fn raw(sign: bool, exp: i64, mantissa: BigInt<4>, category: Category) -> Self
pub fn raw(sign: bool, exp: i64, mantissa: BigInt<4>, category: Category) -> Self
Create a new normal floating point number.
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if the Float is negative
sourcepub fn set_sign(&mut self, sign: bool)
pub fn set_sign(&mut self, sign: bool)
Update the sign of the float to sign
. True means negative.
sourcepub fn get_mantissa(&self) -> BigInt<4>
pub fn get_mantissa(&self) -> BigInt<4>
Returns the mantissa of the float.
sourcepub fn get_category(&self) -> Category
pub fn get_category(&self) -> Category
Returns the category of the float.
sourcepub fn get_exp_bounds() -> (i64, i64)
pub fn get_exp_bounds() -> (i64, i64)
Returns the upper and lower bounds of the exponent.
Trait Implementations§
source§impl<const EXPONENT: usize, const MANTISSA: usize> Add<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> Add<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
source§impl<const EXPONENT: usize, const MANTISSA: usize> Div<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> Div<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
source§impl<const EXPONENT: usize, const MANTISSA: usize> Mul<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> Mul<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
source§impl<const EXPONENT: usize, const MANTISSA: usize> PartialEq<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> PartialEq<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
source§impl<const EXPONENT: usize, const MANTISSA: usize> PartialOrd<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
impl<const EXPONENT: usize, const MANTISSA: usize> PartialOrd<Float<EXPONENT, MANTISSA>> for Float<EXPONENT, MANTISSA>
Page 66. Chapter 3. Floating-Point Formats and Environment Table 3.8: Comparison predicates and the four relations. and IEEE 754-2019 section 5.10 - totalOrder.
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more