Struct scientific::Scientific
source · pub struct Scientific { /* private fields */ }
Expand description
Arbitrary precision scientific number
See the module-level documentation for more details.
Implementations§
source§impl Scientific
impl Scientific
sourcepub const ZERO: Scientific = _
pub const ZERO: Scientific = _
A value of zero.
sourcepub const ONE: Scientific = _
pub const ONE: Scientific = _
A value of one.
sourcepub fn from_string(source: String) -> Result<Scientific, ConversionError>
pub fn from_string(source: String) -> Result<Scientific, ConversionError>
Convert an String
into a value.
This does consume the String and does not require allocation.
§Errors
Will return ConversionError::ParseError
if the string is invalid.
sourcepub fn from_bytes(bytes: &[u8]) -> Result<Scientific, ConversionError>
pub fn from_bytes(bytes: &[u8]) -> Result<Scientific, ConversionError>
Convert a compressed binary format into a value.
sourcepub fn as_raw_mantissa(&self) -> &[u8] ⓘ
pub fn as_raw_mantissa(&self) -> &[u8] ⓘ
Return a reference to the mantissa.
sourcepub fn from_raw_parts(
negative: bool,
mantissa: Vec<u8>,
exponent: isize,
) -> Result<Scientific, ConversionError>
pub fn from_raw_parts( negative: bool, mantissa: Vec<u8>, exponent: isize, ) -> Result<Scientific, ConversionError>
Convert raw parts into an value.
§Errors
Will return ConversionError::ParseError
if the mantissa contains values other than 0..=9.
sourcepub fn sqrt_truncate(&self, precision: Precision) -> Result<Scientific, Error>
pub fn sqrt_truncate(&self, precision: Precision) -> Result<Scientific, Error>
Returns the square root of an number, truncating.
The square root will be calculated up to a given precision.
sourcepub fn sqrt_rpsp(&self, precision: Precision) -> Result<Scientific, Error>
pub fn sqrt_rpsp(&self, precision: Precision) -> Result<Scientific, Error>
Returns the square root of an number, rounding.
The square root will be calculated up to a given precision, but correctly rounded.
As all RPSP functions it calculates one more digit than requested for simpler usage of the final rounding.
sourcepub fn abs(&self) -> Scientific
pub fn abs(&self) -> Scientific
Computes the absolute value.
sourcepub fn abs_assign(&mut self)
pub fn abs_assign(&mut self)
Computes the absolute value, storing it in self.
sourcepub fn neg_assign(&mut self)
pub fn neg_assign(&mut self)
Negating the value, storing it in self.
sourcepub fn div_truncate(
&self,
rhs: &Scientific,
precision: Precision,
) -> Result<Scientific, Error>
pub fn div_truncate( &self, rhs: &Scientific, precision: Precision, ) -> Result<Scientific, Error>
Calculate division, truncating.
Please be aware that div_truncate
is only calculating digits up to the specified precision.
For example 509/100 with a precision of 2 digits or 1 decimals will calculate 5.0 and not 5.1 as it’s may be expected with rounding in mind.
sourcepub fn div_rem(
&self,
rhs: &Scientific,
) -> Result<(Scientific, Scientific), Error>
pub fn div_rem( &self, rhs: &Scientific, ) -> Result<(Scientific, Scientific), Error>
Calculate division and remainder at the same time.
This will be faster than calculating them separately.
sourcepub fn div_rpsp(
&self,
rhs: &Scientific,
precision: Precision,
) -> Result<Scientific, Error>
pub fn div_rpsp( &self, rhs: &Scientific, precision: Precision, ) -> Result<Scientific, Error>
Calculate division with included rpsp (Rounding to Prepare for Shorter Precision)
Use rpsp (Rounding to Prepare for Shorter Precision) only during internal calculations and do one “proper” round at the end of all calculations.
sourcepub fn truncate_assign(&mut self, precision: Precision)
pub fn truncate_assign(&mut self, precision: Precision)
Truncate the value and store it in self.
sourcepub fn truncate(&self, precision: Precision) -> Scientific
pub fn truncate(&self, precision: Precision) -> Scientific
Truncate the value.
sourcepub fn round_assign(&mut self, precision: Precision, rounding: Rounding)
pub fn round_assign(&mut self, precision: Precision, rounding: Rounding)
Round the value and store it in self.
sourcepub fn round(&self, precision: Precision, rounding: Rounding) -> Scientific
pub fn round(&self, precision: Precision, rounding: Rounding) -> Scientific
Round the value.
sourcepub fn round_rpsp_assign(&mut self, precision: Precision)
pub fn round_rpsp_assign(&mut self, precision: Precision)
Round the value with RPSP and store it in self.
sourcepub fn round_rpsp(&self, precision: Precision) -> Scientific
pub fn round_rpsp(&self, precision: Precision) -> Scientific
Round the value with RPSP.
sourcepub fn len(&self) -> isize
pub fn len(&self) -> isize
Returns the length of the mantissa.
Will return length zero for the value zero.
sourcepub fn decimals(&self) -> isize
pub fn decimals(&self) -> isize
Returns the number of decimals.
0.001
/1e-3
will return 3, 1000
/1e3
will return -3.
sourcepub fn exponent0(&self) -> isize
pub fn exponent0(&self) -> isize
Returns the exponent if the mantissa is written directly behind the decimal dot.
123
will return 3
(because it was interpreted as 0.123e3
).
sourcepub fn exponent1(&self) -> isize
pub fn exponent1(&self) -> isize
Returns the exponent if the mantissa is written with one digit in front ot the decimal dot.
123
will return 2
(because it was interpreted as 1.23e3
).
sourcepub fn exponent(&self) -> isize
pub fn exponent(&self) -> isize
Returns the exponent if the mantissa is written directly in front ot the decimal dot.
1.23
will return -2
(because it was interpreted as 123e-2
).
sourcepub fn powi(&self, exponent: usize) -> Scientific
pub fn powi(&self, exponent: usize) -> Scientific
Raise a number to an integer power.
sourcepub fn is_sign_positive(&self) -> bool
pub fn is_sign_positive(&self) -> bool
Returns true
if the number is positive and not zero.
sourcepub fn is_sign_negative(&self) -> bool
pub fn is_sign_negative(&self) -> bool
Returns true
if the number is negative and not zero.
Trait Implementations§
source§impl Add for &Scientific
impl Add for &Scientific
source§impl AddAssign<&Scientific> for Scientific
impl AddAssign<&Scientific> for Scientific
source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+=
operation. Read moresource§impl Clone for Scientific
impl Clone for Scientific
source§fn clone(&self) -> Scientific
fn clone(&self) -> Scientific
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Scientific
impl Debug for Scientific
source§impl<'de> Deserialize<'de> for Scientific
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Scientific
serde
only.source§fn deserialize<D>(
deserializer: D,
) -> Result<Self, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Self, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl Display for Scientific
impl Display for Scientific
source§impl From<&Scientific> for f32
impl From<&Scientific> for f32
source§fn from(value: &Scientific) -> Self
fn from(value: &Scientific) -> Self
source§impl From<&Scientific> for f64
impl From<&Scientific> for f64
source§fn from(value: &Scientific) -> Self
fn from(value: &Scientific) -> Self
source§impl From<i128> for Scientific
impl From<i128> for Scientific
source§impl From<i16> for Scientific
impl From<i16> for Scientific
source§impl From<i32> for Scientific
impl From<i32> for Scientific
source§impl From<i64> for Scientific
impl From<i64> for Scientific
source§impl From<i8> for Scientific
impl From<i8> for Scientific
source§impl From<isize> for Scientific
impl From<isize> for Scientific
source§impl From<u128> for Scientific
impl From<u128> for Scientific
source§impl From<u16> for Scientific
impl From<u16> for Scientific
source§impl From<u32> for Scientific
impl From<u32> for Scientific
source§impl From<u64> for Scientific
impl From<u64> for Scientific
source§impl From<u8> for Scientific
impl From<u8> for Scientific
source§impl From<usize> for Scientific
impl From<usize> for Scientific
source§impl FromStr for Scientific
impl FromStr for Scientific
source§impl Hash for &Scientific
impl Hash for &Scientific
source§impl Mul for &Scientific
impl Mul for &Scientific
source§impl MulAssign<&Scientific> for Scientific
impl MulAssign<&Scientific> for Scientific
source§fn mul_assign(&mut self, rhs: &Self)
fn mul_assign(&mut self, rhs: &Self)
*=
operation. Read moresource§impl Neg for &Scientific
impl Neg for &Scientific
source§impl Ord for Scientific
impl Ord for Scientific
source§impl PartialEq for Scientific
impl PartialEq for Scientific
source§impl PartialOrd for Scientific
impl PartialOrd for Scientific
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 Scientific
Available on crate feature serde
only.
impl Serialize for Scientific
serde
only.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 Shl<isize> for &Scientific
impl Shl<isize> for &Scientific
source§impl ShlAssign<isize> for Scientific
impl ShlAssign<isize> for Scientific
source§fn shl_assign(&mut self, rhs: isize)
fn shl_assign(&mut self, rhs: isize)
<<=
operation. Read moresource§impl Shr<isize> for &Scientific
impl Shr<isize> for &Scientific
source§impl ShrAssign<isize> for Scientific
impl ShrAssign<isize> for Scientific
source§fn shr_assign(&mut self, rhs: isize)
fn shr_assign(&mut self, rhs: isize)
>>=
operation. Read moresource§impl Sub for &Scientific
impl Sub for &Scientific
source§impl SubAssign<&Scientific> for Scientific
impl SubAssign<&Scientific> for Scientific
source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-=
operation. Read moresource§impl TryFrom<&Scientific> for i128
impl TryFrom<&Scientific> for i128
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for i16
impl TryFrom<&Scientific> for i16
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for i32
impl TryFrom<&Scientific> for i32
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for i64
impl TryFrom<&Scientific> for i64
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for i8
impl TryFrom<&Scientific> for i8
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for isize
impl TryFrom<&Scientific> for isize
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for u128
impl TryFrom<&Scientific> for u128
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for u16
impl TryFrom<&Scientific> for u16
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for u32
impl TryFrom<&Scientific> for u32
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for u64
impl TryFrom<&Scientific> for u64
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for u8
impl TryFrom<&Scientific> for u8
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<&Scientific> for usize
impl TryFrom<&Scientific> for usize
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<f32> for Scientific
impl TryFrom<f32> for Scientific
source§impl TryFrom<f64> for Scientific
impl TryFrom<f64> for Scientific
impl Eq for Scientific
impl Send for Scientific
arc
only.impl Sync for Scientific
arc
only.