Struct astro_nalgebra::BigFloat
source · pub struct BigFloat<CTX: BigFloatCtx> { /* private fields */ }
Expand description
Arbitrary precision float type that is a wrapper around [astro_float::BigFloat
]. Has trait
implementations to be used with nalgebra and num_traits.
BigFloat has a type parameter (CTX) that can be either ConstCtx
if the precision and
rounding mode is known at compile-time. Or one can be created with
make_dyn_ctx
if the precision or rounding mode are not known at
compile time.
One limitation with this library is that only BigFloats with the same CTX parameter are allowed to interop. This means that the precision of a computation system cannot be changed without explicitly casting all variables.
NOTE: It is recommended to make a type alias such as the one below.
Example
use astro_nalgebra::{BigFloat, ConstCtx};
type BF128 = BigFloat<ConstCtx<128>>;
let ten: BF128 = "10".parse().unwrap();
let seven: BF128 = "7".parse().unwrap();
println!("{}", ten / seven);
Implementations§
source§impl<CTX: BigFloatCtx> BigFloat<CTX>
impl<CTX: BigFloatCtx> BigFloat<CTX>
sourcepub fn as_f64(&self) -> f64
pub fn as_f64(&self) -> f64
Returns the closest f64
to this BigFloat.
If self is NaN
, returns f64::NAN
If self is Inf
, returns f64::INFINITY
or f64::NEG_INFINITY
Otherwise, returns the closest f64
value to this BigFloat.
NOTE: If the value is above f64::MAX
, this function will overflow into f64::INFINITY
.
NOTE: This is function is defined within this package because astro_float
‘s
implementation is private, so it is not an officially supported function.’
sourcepub fn as_int(&self) -> Option<(Sign, u128)>
pub fn as_int(&self) -> Option<(Sign, u128)>
Returns sign and integer as u128. If the absolute value is greater than u128::MAX, returns None.
NOTE: it is much more idiomatic to use the BigFloat::try_into
method.
NOTE: This will truncate anything below 1 without giving a warning or error
You can check if a number is an integer by ensuring that it is equivalent to its truncated
form by using this snippet: float.clone().trunc() - float
Example
use astro_nalgebra::{BigFloat,ConstCtx,Sign};
let int: BigFloat<ConstCtx<128>> = "1234512345".parse().unwrap();
if let Some((sign, integer)) = int.as_int() {
assert_eq!(integer,1234512345u128);
assert_eq!(sign, Sign::Pos);
}
else {
// Value greater than u128::MAX
}
Trait Implementations§
source§impl<CTX: BigFloatCtx> AbsDiffEq for BigFloat<CTX>
impl<CTX: BigFloatCtx> AbsDiffEq for BigFloat<CTX>
source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
.source§impl<CTX: BigFloatCtx> Add for BigFloat<CTX>
impl<CTX: BigFloatCtx> Add for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> AddAssign for BigFloat<CTX>
impl<CTX: BigFloatCtx> AddAssign for BigFloat<CTX>
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§impl<CTX: BigFloatCtx> Clone for BigFloat<CTX>
impl<CTX: BigFloatCtx> Clone for BigFloat<CTX>
source§impl<CTX: BigFloatCtx + 'static> ComplexField for BigFloat<CTX>
impl<CTX: BigFloatCtx + 'static> ComplexField for BigFloat<CTX>
type RealField = BigFloat<CTX>
fn is_finite(&self) -> bool
fn mul_add(self, a: Self, b: Self) -> Self
source§fn hypot(self, other: Self) -> Self::RealField
fn hypot(self, other: Self) -> Self::RealField
fn recip(self) -> Self
source§fn from_real(re: Self::RealField) -> Self
fn from_real(re: Self::RealField) -> Self
source§fn modulus_squared(self) -> Self::RealField
fn modulus_squared(self) -> Self::RealField
source§fn norm1(self) -> Self
fn norm1(self) -> Self
fn conjugate(self) -> Self
fn ln(self) -> Self
fn log2(self) -> Self
fn log10(self) -> Self
fn log(self, base: Self::RealField) -> Self
fn ln_1p(self) -> Self
fn exp(self) -> Self
fn exp2(self) -> Self
fn exp_m1(self) -> Self
fn powi(self, n: i32) -> Self
fn powf(self, n: Self::RealField) -> Self
fn sqrt(self) -> Self
fn cbrt(self) -> Self
fn try_sqrt(self) -> Option<Self>
fn powc(self, n: Self) -> Self
fn round(self) -> Self
fn floor(self) -> Self
fn ceil(self) -> Self
source§fn abs(self) -> Self
fn abs(self) -> Self
self / self.signum()
. Read morefn fract(self) -> Self
fn trunc(self) -> Self
fn sin(self) -> Self
fn cos(self) -> Self
fn tan(self) -> Self
fn asin(self) -> Self
fn acos(self) -> Self
fn atan(self) -> Self
fn sinh(self) -> Self
fn cosh(self) -> Self
fn tanh(self) -> Self
fn asinh(self) -> Self
fn acosh(self) -> Self
fn atanh(self) -> Self
fn sin_cos(self) -> (Self, Self)
source§fn to_polar(self) -> (Self::RealField, Self::RealField)
fn to_polar(self) -> (Self::RealField, Self::RealField)
source§fn to_exp(self) -> (Self::RealField, Self)
fn to_exp(self) -> (Self::RealField, Self)
fn sinh_cosh(self) -> (Self, Self)
fn sinhc(self) -> Self
fn coshc(self) -> Self
source§impl<'de, CTX: BigFloatCtx> Deserialize<'de> for BigFloat<CTX>
impl<'de, CTX: BigFloatCtx> Deserialize<'de> for BigFloat<CTX>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<CTX: BigFloatCtx> Div for BigFloat<CTX>
impl<CTX: BigFloatCtx> Div for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> DivAssign for BigFloat<CTX>
impl<CTX: BigFloatCtx> DivAssign for BigFloat<CTX>
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresource§impl<CTX: BigFloatCtx> From<BigFloat> for BigFloat<CTX>
impl<CTX: BigFloatCtx> From<BigFloat> for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> FromPrimitive for BigFloat<CTX>
impl<CTX: BigFloatCtx> FromPrimitive for BigFloat<CTX>
source§fn from_f64(prim: f64) -> Option<Self>
fn from_f64(prim: f64) -> Option<Self>
f64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_f32(prim: f32) -> Option<Self>
fn from_f32(prim: f32) -> Option<Self>
f32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u8(prim: u8) -> Option<Self>
fn from_u8(prim: u8) -> Option<Self>
u8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i8(prim: i8) -> Option<Self>
fn from_i8(prim: i8) -> Option<Self>
i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u16(prim: u16) -> Option<Self>
fn from_u16(prim: u16) -> Option<Self>
u16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i16(prim: i16) -> Option<Self>
fn from_i16(prim: i16) -> Option<Self>
i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u32(prim: u32) -> Option<Self>
fn from_u32(prim: u32) -> Option<Self>
u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i32(prim: i32) -> Option<Self>
fn from_i32(prim: i32) -> Option<Self>
i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i64(prim: i64) -> Option<Self>
fn from_i64(prim: i64) -> Option<Self>
i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_u64(prim: u64) -> Option<Self>
fn from_u64(prim: u64) -> Option<Self>
u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_i128(prim: i128) -> Option<Self>
fn from_i128(prim: i128) -> Option<Self>
i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_u128(prim: u128) -> Option<Self>
fn from_u128(prim: u128) -> Option<Self>
u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.source§impl<CTX: BigFloatCtx> FromStr for BigFloat<CTX>
impl<CTX: BigFloatCtx> FromStr for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> Mul for BigFloat<CTX>
impl<CTX: BigFloatCtx> Mul for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> MulAssign for BigFloat<CTX>
impl<CTX: BigFloatCtx> MulAssign for BigFloat<CTX>
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresource§impl<CTX: BigFloatCtx> Neg for BigFloat<CTX>
impl<CTX: BigFloatCtx> Neg for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> Num for BigFloat<CTX>
impl<CTX: BigFloatCtx> Num for BigFloat<CTX>
type FromStrRadixErr = ParseBigFloatError
source§fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36
). Read moresource§impl<CTX: BigFloatCtx> One for BigFloat<CTX>
impl<CTX: BigFloatCtx> One for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> PartialEq for BigFloat<CTX>
impl<CTX: BigFloatCtx> PartialEq for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> PartialOrd for BigFloat<CTX>
impl<CTX: BigFloatCtx> PartialOrd for BigFloat<CTX>
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 moresource§impl<CTX: BigFloatCtx + 'static> RealField for BigFloat<CTX>
impl<CTX: BigFloatCtx + 'static> RealField for BigFloat<CTX>
source§fn is_sign_positive(&self) -> bool
fn is_sign_positive(&self) -> bool
source§fn is_sign_negative(&self) -> bool
fn is_sign_negative(&self) -> bool
fn max(self, other: Self) -> Self
fn min(self, other: Self) -> Self
fn clamp(self, min: Self, max: Self) -> Self
fn frac_pi_2() -> Self
fn frac_pi_3() -> Self
fn frac_pi_4() -> Self
fn frac_pi_6() -> Self
fn frac_pi_8() -> Self
fn two_pi() -> Self
fn pi() -> Self
fn e() -> Self
fn ln_2() -> Self
fn ln_10() -> Self
fn log2_e() -> Self
fn log10_e() -> Self
source§fn min_value() -> Option<Self>
fn min_value() -> Option<Self>
source§fn max_value() -> Option<Self>
fn max_value() -> Option<Self>
fn frac_1_pi() -> Self
fn frac_2_pi() -> Self
fn frac_2_sqrt_pi() -> Self
fn atan2(self, other: Self) -> Self
source§impl<CTX: BigFloatCtx + 'static> RelativeEq for BigFloat<CTX>
impl<CTX: BigFloatCtx + 'static> RelativeEq for BigFloat<CTX>
source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
_max_relative: Self::Epsilon
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, _max_relative: Self::Epsilon ) -> bool
source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool
RelativeEq::relative_eq
.source§impl<CTX: BigFloatCtx> Rem for BigFloat<CTX>
impl<CTX: BigFloatCtx> Rem for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> RemAssign for BigFloat<CTX>
impl<CTX: BigFloatCtx> RemAssign for BigFloat<CTX>
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%=
operation. Read moresource§impl<CTX: BigFloatCtx> Serialize for BigFloat<CTX>
impl<CTX: BigFloatCtx> Serialize for BigFloat<CTX>
source§impl<CTX: BigFloatCtx + 'static> Signed for BigFloat<CTX>
impl<CTX: BigFloatCtx + 'static> Signed for BigFloat<CTX>
source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
source§impl<CTX: BigFloatCtx> Sub for BigFloat<CTX>
impl<CTX: BigFloatCtx> Sub for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> SubAssign for BigFloat<CTX>
impl<CTX: BigFloatCtx> SubAssign for BigFloat<CTX>
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moresource§impl<CTX: BigFloatCtx> UlpsEq for BigFloat<CTX>
impl<CTX: BigFloatCtx> UlpsEq for BigFloat<CTX>
source§impl<CTX: BigFloatCtx> Zero for BigFloat<CTX>
impl<CTX: BigFloatCtx> Zero for BigFloat<CTX>
impl<CTX: Eq + BigFloatCtx> Eq for BigFloat<CTX>
impl<CTX: BigFloatCtx> Field for BigFloat<CTX>
impl<CTX: BigFloatCtx> StructuralEq for BigFloat<CTX>
Auto Trait Implementations§
impl<CTX> RefUnwindSafe for BigFloat<CTX>
impl<CTX> Send for BigFloat<CTX>
impl<CTX> Sync for BigFloat<CTX>
impl<CTX> Unpin for BigFloat<CTX>
impl<CTX> UnwindSafe for BigFloat<CTX>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> SimdComplexField for Twhere
T: ComplexField,
impl<T> SimdComplexField for Twhere
T: ComplexField,
§type SimdRealField = <T as ComplexField>::RealField
type SimdRealField = <T as ComplexField>::RealField
source§fn from_simd_real(re: <T as SimdComplexField>::SimdRealField) -> T
fn from_simd_real(re: <T as SimdComplexField>::SimdRealField) -> T
source§fn simd_real(self) -> <T as SimdComplexField>::SimdRealField
fn simd_real(self) -> <T as SimdComplexField>::SimdRealField
source§fn simd_imaginary(self) -> <T as SimdComplexField>::SimdRealField
fn simd_imaginary(self) -> <T as SimdComplexField>::SimdRealField
source§fn simd_modulus(self) -> <T as SimdComplexField>::SimdRealField
fn simd_modulus(self) -> <T as SimdComplexField>::SimdRealField
source§fn simd_modulus_squared(self) -> <T as SimdComplexField>::SimdRealField
fn simd_modulus_squared(self) -> <T as SimdComplexField>::SimdRealField
source§fn simd_argument(self) -> <T as SimdComplexField>::SimdRealField
fn simd_argument(self) -> <T as SimdComplexField>::SimdRealField
source§fn simd_norm1(self) -> <T as SimdComplexField>::SimdRealField
fn simd_norm1(self) -> <T as SimdComplexField>::SimdRealField
source§fn simd_scale(self, factor: <T as SimdComplexField>::SimdRealField) -> T
fn simd_scale(self, factor: <T as SimdComplexField>::SimdRealField) -> T
factor
.source§fn simd_unscale(self, factor: <T as SimdComplexField>::SimdRealField) -> T
fn simd_unscale(self, factor: <T as SimdComplexField>::SimdRealField) -> T
factor
.source§fn simd_to_polar(
self
) -> (<T as SimdComplexField>::SimdRealField, <T as SimdComplexField>::SimdRealField)
fn simd_to_polar( self ) -> (<T as SimdComplexField>::SimdRealField, <T as SimdComplexField>::SimdRealField)
source§fn simd_to_exp(self) -> (<T as SimdComplexField>::SimdRealField, T)
fn simd_to_exp(self) -> (<T as SimdComplexField>::SimdRealField, T)
source§fn simd_signum(self) -> T
fn simd_signum(self) -> T
self / self.modulus()
fn simd_floor(self) -> T
fn simd_ceil(self) -> T
fn simd_round(self) -> T
fn simd_trunc(self) -> T
fn simd_fract(self) -> T
fn simd_mul_add(self, a: T, b: T) -> T
source§fn simd_abs(self) -> <T as SimdComplexField>::SimdRealField
fn simd_abs(self) -> <T as SimdComplexField>::SimdRealField
self / self.signum()
. Read moresource§fn simd_hypot(self, other: T) -> <T as SimdComplexField>::SimdRealField
fn simd_hypot(self, other: T) -> <T as SimdComplexField>::SimdRealField
fn simd_recip(self) -> T
fn simd_conjugate(self) -> T
fn simd_sin(self) -> T
fn simd_cos(self) -> T
fn simd_sin_cos(self) -> (T, T)
fn simd_sinh_cosh(self) -> (T, T)
fn simd_tan(self) -> T
fn simd_asin(self) -> T
fn simd_acos(self) -> T
fn simd_atan(self) -> T
fn simd_sinh(self) -> T
fn simd_cosh(self) -> T
fn simd_tanh(self) -> T
fn simd_asinh(self) -> T
fn simd_acosh(self) -> T
fn simd_atanh(self) -> T
fn simd_sinhc(self) -> T
fn simd_coshc(self) -> T
fn simd_log(self, base: <T as SimdComplexField>::SimdRealField) -> T
fn simd_log2(self) -> T
fn simd_log10(self) -> T
fn simd_ln(self) -> T
fn simd_ln_1p(self) -> T
fn simd_sqrt(self) -> T
fn simd_exp(self) -> T
fn simd_exp2(self) -> T
fn simd_exp_m1(self) -> T
fn simd_powi(self, n: i32) -> T
fn simd_powf(self, n: <T as SimdComplexField>::SimdRealField) -> T
fn simd_powc(self, n: T) -> T
fn simd_cbrt(self) -> T
source§fn simd_horizontal_sum(self) -> <T as SimdValue>::Element
fn simd_horizontal_sum(self) -> <T as SimdValue>::Element
self
.source§fn simd_horizontal_product(self) -> <T as SimdValue>::Element
fn simd_horizontal_product(self) -> <T as SimdValue>::Element
self
.source§impl<T> SimdPartialOrd for T
impl<T> SimdPartialOrd for T
source§fn simd_ge(self, other: T) -> <T as SimdValue>::SimdBool
fn simd_ge(self, other: T) -> <T as SimdValue>::SimdBool
>=
comparison.source§fn simd_le(self, other: T) -> <T as SimdValue>::SimdBool
fn simd_le(self, other: T) -> <T as SimdValue>::SimdBool
<=
comparison.source§fn simd_clamp(self, min: T, max: T) -> T
fn simd_clamp(self, min: T, max: T) -> T
self
between the corresponding lane of min
and max
.source§fn simd_horizontal_min(self) -> <T as SimdValue>::Element
fn simd_horizontal_min(self) -> <T as SimdValue>::Element
self
.source§fn simd_horizontal_max(self) -> <T as SimdValue>::Element
fn simd_horizontal_max(self) -> <T as SimdValue>::Element
self
.source§impl<T> SimdRealField for Twhere
T: RealField,
impl<T> SimdRealField for Twhere
T: RealField,
fn simd_atan2(self, other: T) -> T
fn simd_default_epsilon() -> T
source§fn simd_copysign(self, sign: T) -> T
fn simd_copysign(self, sign: T) -> T
fn simd_pi() -> T
fn simd_two_pi() -> T
fn simd_frac_pi_2() -> T
fn simd_frac_pi_3() -> T
fn simd_frac_pi_4() -> T
fn simd_frac_pi_6() -> T
fn simd_frac_pi_8() -> T
fn simd_frac_1_pi() -> T
fn simd_frac_2_pi() -> T
fn simd_frac_2_sqrt_pi() -> T
fn simd_e() -> T
fn simd_log2_e() -> T
fn simd_log10_e() -> T
fn simd_ln_2() -> T
fn simd_ln_10() -> T
source§impl<T> SimdSigned for T
impl<T> SimdSigned for T
source§fn simd_abs_sub(&self, other: &T) -> T
fn simd_abs_sub(&self, other: &T) -> T
self
. Read moresource§fn simd_signum(&self) -> T
fn simd_signum(&self) -> T
Self
.source§fn is_simd_positive(&self) -> <T as SimdValue>::SimdBool
fn is_simd_positive(&self) -> <T as SimdValue>::SimdBool
source§fn is_simd_negative(&self) -> <T as SimdValue>::SimdBool
fn is_simd_negative(&self) -> <T as SimdValue>::SimdBool
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.