Struct browser_window::javascript::BigFloat
source · pub struct BigFloat { /* private fields */ }Expand description
Number representation.
Implementations§
source§impl BigFloat
impl BigFloat
sourcepub fn from_bytes(bytes: &[u8], sign: i8, exponent: i8) -> BigFloat
pub fn from_bytes(bytes: &[u8], sign: i8, exponent: i8) -> BigFloat
Creates a BigFloat value from a sequence of bytes. Each byte must represent a decimal digit.
First byte is the most significant. bytes can be of any length.
If bytes is longer than required, then the remaining bytes are ignored.
If the “sign” is negative, then the resulting BigFloat will be negative.
§Examples
let n1 = BigFloat::from_bytes(&[1,2,3,4,2,0,0,0], 1, -3);
let n2 = BigFloat::from_u32(12342);
assert!(n1.cmp(&n2) == Some(0));sourcepub fn from_f64(f: f64) -> BigFloat
pub fn from_f64(f: f64) -> BigFloat
Creates a BigFloat from f64. The conversion is not guaranteed to be lossless since BigFloat and f64 have different bases.
sourcepub fn from_f32(f: f32) -> BigFloat
pub fn from_f32(f: f32) -> BigFloat
Creates a BigFloat from f32. The conversion is not guaranteed to be lossless since BigFloat and f64 have different bases.
sourcepub fn to_i64(&self) -> Option<i64>
pub fn to_i64(&self) -> Option<i64>
Converts BigFloat to i64.
The function retursn None if self is Inf, NaN, or out of range of i64.
sourcepub fn to_i128(&self) -> Option<i128>
pub fn to_i128(&self) -> Option<i128>
Converts BigFloat to i128.
The function retursn None if self is Inf, NaN, or out of range of i128.
sourcepub fn to_u64(&self) -> Option<u64>
pub fn to_u64(&self) -> Option<u64>
Converts absolute value of self to u64.
The function retursn None if self is Inf, NaN, or out of range of u64.
sourcepub fn to_u128(&self) -> Option<u128>
pub fn to_u128(&self) -> Option<u128>
Converts absolute value of self to u128.
The function retursn None if self is Inf, NaN, or out of range of u128.
sourcepub fn get_mantissa_bytes(&self, bytes: &mut [u8])
pub fn get_mantissa_bytes(&self, bytes: &mut [u8])
Returns the mantissa of the BigFloat in bytes. Each byte represents a decimal digit.
The first byte is the most significant. bytes can be of any length.
If the length of bytes is less than the number of decimal positions filled in the mantissa,
then the rest of the mantissa will be omitted.
The length of the mantissa can be determined using get_mantissa_len.
If self is Inf or NaN, nothing is returned.
§Examples
let n = BigFloat::from_f64(123.42);
let mut m = [0; 40];
n.get_mantissa_bytes(&mut m);
// compare m[0..10] to [1,2,3,4,2,0,0,0,0,0]
assert!(m[0..10].iter().zip([1,2,3,4,2,0,0,0,0,0].iter()).filter(|x| { x.0 != x.1 }).count() == 0);sourcepub fn get_mantissa_len(&self) -> usize
pub fn get_mantissa_len(&self) -> usize
Returns the number of decimal places filled in the mantissa.
If self is Inf or NaN, 0 is returned.
sourcepub fn get_sign(&self) -> i8
pub fn get_sign(&self) -> i8
Returns 1 if BigFloat is positive, -1 otherwise.
If self is NaN, 0 is returned.
sourcepub fn get_exponent(&self) -> i8
pub fn get_exponent(&self) -> i8
Returns the exponent part of the number.
If self is Inf or NaN, 0 is returned.
sourcepub fn set_exponent(&mut self, e: i8)
pub fn set_exponent(&mut self, e: i8)
Sets the exponent part of the number. The function has no effect on Inf and NaN values.
sourcepub fn to_raw_parts(&self) -> Option<([i16; 10], i16, i8, i8)>
pub fn to_raw_parts(&self) -> Option<([i16; 10], i16, i8, i8)>
Returns the raw parts of the number: the mantissa, the number of decimal places in the mantissa,
the sign, and the exponent.
If self is Inf or NaN, None is returned.
sourcepub fn from_raw_parts(
mantissa: [i16; 10],
mantissa_len: i16,
sign: i8,
exponent: i8
) -> BigFloat
pub fn from_raw_parts( mantissa: [i16; 10], mantissa_len: i16, sign: i8, exponent: i8 ) -> BigFloat
Creates a BigFloat from the raw parts. to_raw_parts can be used to get the raw parts of a number.
sourcepub fn is_inf_pos(&self) -> bool
pub fn is_inf_pos(&self) -> bool
Returns true if self is positive infinity.
sourcepub fn is_inf_neg(&self) -> bool
pub fn is_inf_neg(&self) -> bool
Returns true if self is negative infinity.
sourcepub fn add(&self, d2: &BigFloat) -> BigFloat
pub fn add(&self, d2: &BigFloat) -> BigFloat
Adds d2 to self and returns the result of the addition.
sourcepub fn sub(&self, d2: &BigFloat) -> BigFloat
pub fn sub(&self, d2: &BigFloat) -> BigFloat
Subtracts d2 from self and return the result of the subtraction.
sourcepub fn mul(&self, d2: &BigFloat) -> BigFloat
pub fn mul(&self, d2: &BigFloat) -> BigFloat
Multiplies self by d2 and returns the result of the multiplication.
sourcepub fn div(&self, d2: &BigFloat) -> BigFloat
pub fn div(&self, d2: &BigFloat) -> BigFloat
Divides self by d2 and returns the result of the division.
sourcepub fn cmp(&self, d2: &BigFloat) -> Option<i16>
pub fn cmp(&self, d2: &BigFloat) -> Option<i16>
Compares self to d2.
Returns positive if self > d2, negative if self < d2, zero if self == d2, None if self or d2 is NaN.
sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if self is positive.
The function returns false if self is NaN.
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if self is negative.
The function returns false if self is NaN.
sourcepub fn is_subnormal(&self) -> bool
pub fn is_subnormal(&self) -> bool
Returns true if self is subnormal.
A number is considered subnormal if not all digits of the mantissa are used, and the exponent has the minimum possible value.
sourcepub fn clamp(&self, min: &BigFloat, max: &BigFloat) -> BigFloat
pub fn clamp(&self, min: &BigFloat, max: &BigFloat) -> BigFloat
Restricts the value of self to an interval determined by the values of min and max.
The function returns max if self is greater than max, min if self is less than min, and self otherwise.
If either argument is NaN or min is greater than max, the function returns NaN.
sourcepub fn max(&self, d1: &BigFloat) -> BigFloat
pub fn max(&self, d1: &BigFloat) -> BigFloat
Returns the value of d1 if d1 is greater than self, or the value of self otherwise.
If either argument is NaN, the function returns NaN.
sourcepub fn min(&self, d1: &BigFloat) -> BigFloat
pub fn min(&self, d1: &BigFloat) -> BigFloat
Returns value of d1 if d1 is less than self, or the value of self otherwise.
If either argument is NaN, the function returns NaN.
sourcepub fn signum(&self) -> BigFloat
pub fn signum(&self) -> BigFloat
Returns a BigFloat with the value -1 if self is negative, 1 if self is positive, zero otherwise.
The function returns NaN If self is NaN.
sourcepub fn parse(s: &str) -> Option<BigFloat>
pub fn parse(s: &str) -> Option<BigFloat>
Parses a number from the string s.
The function expects s to be a number in scientific format in base 10, or +-Inf, or NaN.
§Examples
use num_bigfloat::BigFloat;
let n = BigFloat::parse("0.0").unwrap();
assert!(n.to_f64() == 0.0);
let n = BigFloat::parse("1.123e-123").unwrap();
assert!((n.to_f64() - 1.123e-123).abs() < f64::EPSILON);
let n = BigFloat::parse("-Inf").unwrap();
assert!(n.to_f64() == f64::NEG_INFINITY);
let n = BigFloat::parse("NaN").unwrap();
assert!(n.to_f64().is_nan());sourcepub fn random_normal(exp_from: i8, exp_to: i8) -> Result<BigFloat, Error>
pub fn random_normal(exp_from: i8, exp_to: i8) -> Result<BigFloat, Error>
Returns a random normalized (not subnormal) BigFloat number with exponent in the range
from exp_from to exp_to inclusive. The sign can be positive and negative. Zero is excluded.
Function does not follow any specific distribution law.
The intended use of this function is for testing.
§Errors
InvalidArgument - when exp_from is greater than exp_to.
sourcepub fn classify(&self) -> FpCategory
pub fn classify(&self) -> FpCategory
Returns category of self as defined by core::num::FpCategory.
source§impl BigFloat
impl BigFloat
sourcepub fn round(&self, n: usize, rm: RoundingMode) -> BigFloat
pub fn round(&self, n: usize, rm: RoundingMode) -> BigFloat
Returns a rounded number with n decimal positions in the fractional part of the number using the rounding mode rm.
sourcepub fn sin(&self) -> BigFloat
pub fn sin(&self) -> BigFloat
Returns the sine of self. The function takes an angle in radians as an argument.
sourcepub fn cos(&self) -> BigFloat
pub fn cos(&self) -> BigFloat
Returns the cosine of self. The function takes an angle in radians as an argument.
sourcepub fn tan(&self) -> BigFloat
pub fn tan(&self) -> BigFloat
Returns the tangent of self. The function takes an angle in radians as an argument.
sourcepub fn asin(&self) -> BigFloat
pub fn asin(&self) -> BigFloat
Returns the arcsine of self. The result is an angle in radians ranging from -pi/2 to pi/2.
sourcepub fn acos(&self) -> BigFloat
pub fn acos(&self) -> BigFloat
Returns the arccosine of self. The result is an angle in radians ranging from 0 to pi.
Trait Implementations§
source§impl AddAssign<&BigFloat> for BigFloat
impl AddAssign<&BigFloat> for BigFloat
source§fn add_assign(&mut self, rhs: &BigFloat)
fn add_assign(&mut self, rhs: &BigFloat)
+= operation. Read moresource§impl AddAssign for BigFloat
impl AddAssign for BigFloat
source§fn add_assign(&mut self, rhs: BigFloat)
fn add_assign(&mut self, rhs: BigFloat)
+= operation. Read moresource§impl<'de> Deserialize<'de> for BigFloat
impl<'de> Deserialize<'de> for BigFloat
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<BigFloat, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<BigFloat, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl DivAssign<&BigFloat> for BigFloat
impl DivAssign<&BigFloat> for BigFloat
source§fn div_assign(&mut self, rhs: &BigFloat)
fn div_assign(&mut self, rhs: &BigFloat)
/= operation. Read moresource§impl DivAssign for BigFloat
impl DivAssign for BigFloat
source§fn div_assign(&mut self, rhs: BigFloat)
fn div_assign(&mut self, rhs: BigFloat)
/= operation. Read moresource§impl Euclid for BigFloat
impl Euclid for BigFloat
source§fn div_euclid(&self, v: &BigFloat) -> BigFloat
fn div_euclid(&self, v: &BigFloat) -> BigFloat
rem_euclid. Read moresource§fn rem_euclid(&self, v: &BigFloat) -> BigFloat
fn rem_euclid(&self, v: &BigFloat) -> BigFloat
self (mod v). Read moresource§fn div_rem_euclid(&self, v: &Self) -> (Self, Self)
fn div_rem_euclid(&self, v: &Self) -> (Self, Self)
source§impl Float for BigFloat
impl Float for BigFloat
source§fn neg_zero() -> BigFloat
fn neg_zero() -> BigFloat
This function is provided only for compatibility since -0.0 is not implemented.
source§fn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
Note: BigFloat NaN has no sign.
source§fn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
Note: BigFloat NaN has no sign.
source§fn mul_add(self, a: BigFloat, b: BigFloat) -> BigFloat
fn mul_add(self, a: BigFloat, b: BigFloat) -> BigFloat
This function is provided only for compatibility. It is not faster than separate multiplication and addition.
source§fn powi(self, n: i32) -> BigFloat
fn powi(self, n: i32) -> BigFloat
This function is provided only for compatibility. It is not faster than powf.
source§fn integer_decode(self) -> (u64, i16, i8)
fn integer_decode(self) -> (u64, i16, i8)
This function converts BigFloat to f64 and decomposes it.
source§fn neg_infinity() -> BigFloat
fn neg_infinity() -> BigFloat
source§fn min_value() -> BigFloat
fn min_value() -> BigFloat
source§fn min_positive_value() -> BigFloat
fn min_positive_value() -> BigFloat
source§fn max_value() -> BigFloat
fn max_value() -> BigFloat
source§fn is_infinite(self) -> bool
fn is_infinite(self) -> bool
true if this value is positive infinity or negative infinity and
false otherwise. Read moresource§fn classify(self) -> FpCategory
fn classify(self) -> FpCategory
source§fn floor(self) -> BigFloat
fn floor(self) -> BigFloat
source§fn ceil(self) -> BigFloat
fn ceil(self) -> BigFloat
source§fn round(self) -> BigFloat
fn round(self) -> BigFloat
0.0. Read moresource§fn log(self, base: BigFloat) -> BigFloat
fn log(self, base: BigFloat) -> BigFloat
source§fn abs_sub(self, other: BigFloat) -> BigFloat
fn abs_sub(self, other: BigFloat) -> BigFloat
source§fn hypot(self, other: BigFloat) -> BigFloat
fn hypot(self, other: BigFloat) -> BigFloat
x and y. Read moresource§fn asin(self) -> BigFloat
fn asin(self) -> BigFloat
source§fn acos(self) -> BigFloat
fn acos(self) -> BigFloat
source§fn atan(self) -> BigFloat
fn atan(self) -> BigFloat
source§fn to_degrees(self) -> Self
fn to_degrees(self) -> Self
source§fn to_radians(self) -> Self
fn to_radians(self) -> Self
source§impl FloatConst for BigFloat
impl FloatConst for BigFloat
source§fn FRAC_1_SQRT_2() -> BigFloat
fn FRAC_1_SQRT_2() -> BigFloat
1.0 / sqrt(2.0).source§fn FRAC_2_SQRT_PI() -> BigFloat
fn FRAC_2_SQRT_PI() -> BigFloat
2.0 / sqrt(π).source§impl FromPrimitive for BigFloat
impl FromPrimitive for BigFloat
source§fn from_i64(n: i64) -> Option<BigFloat>
fn from_i64(n: i64) -> Option<BigFloat>
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(n: u64) -> Option<BigFloat>
fn from_u64(n: u64) -> Option<BigFloat>
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(n: i128) -> Option<BigFloat>
fn from_i128(n: i128) -> Option<BigFloat>
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(n: u128) -> Option<BigFloat>
fn from_u128(n: u128) -> Option<BigFloat>
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_f32(n: f32) -> Option<BigFloat>
fn from_f32(n: f32) -> Option<BigFloat>
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_f64(n: f64) -> Option<BigFloat>
fn from_f64(n: f64) -> Option<BigFloat>
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_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_i8(n: i8) -> Option<Self>
fn from_i8(n: 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_i16(n: i16) -> Option<Self>
fn from_i16(n: 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_i32(n: i32) -> Option<Self>
fn from_i32(n: 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_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§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: 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§impl MulAdd for BigFloat
impl MulAdd for BigFloat
This trait is provided only for compatibility. It does not provide performance benefits.
source§impl MulAddAssign for BigFloat
impl MulAddAssign for BigFloat
This trait is provided only for compatibility. It does not provide performance benefits.
source§fn mul_add_assign(&mut self, a: BigFloat, b: BigFloat)
fn mul_add_assign(&mut self, a: BigFloat, b: BigFloat)
*self = (*self * a) + bsource§impl MulAssign<&BigFloat> for BigFloat
impl MulAssign<&BigFloat> for BigFloat
source§fn mul_assign(&mut self, rhs: &BigFloat)
fn mul_assign(&mut self, rhs: &BigFloat)
*= operation. Read moresource§impl MulAssign for BigFloat
impl MulAssign for BigFloat
source§fn mul_assign(&mut self, rhs: BigFloat)
fn mul_assign(&mut self, rhs: BigFloat)
*= operation. Read moresource§impl PartialEq for BigFloat
impl PartialEq for BigFloat
source§impl PartialOrd for BigFloat
impl PartialOrd for BigFloat
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 Serialize for BigFloat
impl Serialize for BigFloat
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl Signed for BigFloat
impl Signed for BigFloat
source§fn abs_sub(&self, other: &BigFloat) -> BigFloat
fn abs_sub(&self, other: &BigFloat) -> BigFloat
source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
source§impl SubAssign<&BigFloat> for BigFloat
impl SubAssign<&BigFloat> for BigFloat
source§fn sub_assign(&mut self, rhs: &BigFloat)
fn sub_assign(&mut self, rhs: &BigFloat)
-= operation. Read moresource§impl SubAssign for BigFloat
impl SubAssign for BigFloat
source§fn sub_assign(&mut self, rhs: BigFloat)
fn sub_assign(&mut self, rhs: BigFloat)
-= operation. Read moresource§impl ToPrimitive for BigFloat
impl ToPrimitive for BigFloat
source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self to an i64. If the value cannot be
represented by an i64, then None is returned.source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self to a u64. If the value cannot be
represented by a u64, then None is returned.source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self to an i128. If the value cannot be
represented by an i128 (i64 under the default implementation), then
None is returned. Read moresource§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self to a u128. If the value cannot be
represented by a u128 (u64 under the default implementation), then
None is returned. Read moresource§fn to_f64(&self) -> Option<f64>
fn to_f64(&self) -> Option<f64>
self to an f64. Overflows may map to positive
or negative inifinity, otherwise None is returned if the value cannot
be represented by an f64. Read moresource§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self to an isize. If the value cannot be
represented by an isize, then None is returned.source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self to an i8. If the value cannot be
represented by an i8, then None is returned.source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self to an i16. If the value cannot be
represented by an i16, then None is returned.source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self to an i32. If the value cannot be
represented by an i32, then None is returned.source§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self to a usize. If the value cannot be
represented by a usize, then None is returned.source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self to a u8. If the value cannot be
represented by a u8, then None is returned.source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self to a u16. If the value cannot be
represented by a u16, then None is returned.impl Copy for BigFloat
impl Eq for BigFloat
Auto Trait Implementations§
impl RefUnwindSafe for BigFloat
impl Send for BigFloat
impl Sync for BigFloat
impl Unpin for BigFloat
impl UnwindSafe for BigFloat
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> LowerBounded for Twhere
T: Bounded,
impl<T> LowerBounded for Twhere
T: Bounded,
source§impl<T> Real for Twhere
T: Float,
impl<T> Real for Twhere
T: Float,
source§fn min_positive_value() -> T
fn min_positive_value() -> T
source§fn round(self) -> T
fn round(self) -> T
0.0. Read moresource§fn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
true if self is positive, including +0.0,
Float::infinity(), and with newer versions of Rust f64::NAN. Read moresource§fn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
true if self is negative, including -0.0,
Float::neg_infinity(), and with newer versions of Rust -f64::NAN. Read moresource§fn mul_add(self, a: T, b: T) -> T
fn mul_add(self, a: T, b: T) -> T
(self * a) + b with only one rounding
error, yielding a more accurate result than an unfused multiply-add. Read moresource§fn log(self, base: T) -> T
fn log(self, base: T) -> T
source§fn to_degrees(self) -> T
fn to_degrees(self) -> T
source§fn to_radians(self) -> T
fn to_radians(self) -> T
source§fn hypot(self, other: T) -> T
fn hypot(self, other: T) -> T
x and y. Read moresource§fn asin(self) -> T
fn asin(self) -> T
source§fn acos(self) -> T
fn acos(self) -> T
source§fn atan(self) -> T
fn atan(self) -> T
source§fn exp_m1(self) -> T
fn exp_m1(self) -> T
e^(self) - 1 in a way that is accurate even if the
number is close to zero. Read more