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

source

pub const ZERO: Scientific = _

A value of zero.

source

pub const ONE: Scientific = _

A value of one.

source

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.

source

pub fn to_bytes(&self) -> Vec<u8>

Convert a value into a compressed binary format.

source

pub fn from_bytes(bytes: &[u8]) -> Result<Scientific, ConversionError>

Convert a compressed binary format into a value.

source

pub fn as_raw_mantissa(&self) -> &[u8]

Return a reference to the mantissa.

source

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.

source

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.

source

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.

source

pub fn abs(&self) -> Scientific

Computes the absolute value.

source

pub fn abs_assign(&mut self)

Computes the absolute value, storing it in self.

source

pub fn neg_assign(&mut self)

Negating the value, storing it in self.

source

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.

source

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.

source

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.

source

pub fn truncate_assign(&mut self, precision: Precision)

Truncate the value and store it in self.

source

pub fn truncate(&self, precision: Precision) -> Scientific

Truncate the value.

source

pub fn round_assign(&mut self, precision: Precision, rounding: Rounding)

Round the value and store it in self.

source

pub fn round(&self, precision: Precision, rounding: Rounding) -> Scientific

Round the value.

source

pub fn round_rpsp_assign(&mut self, precision: Precision)

Round the value with RPSP and store it in self.

source

pub fn round_rpsp(&self, precision: Precision) -> Scientific

Round the value with RPSP.

source

pub fn len(&self) -> isize

Returns the length of the mantissa.

Will return length zero for the value zero.

source

pub fn decimals(&self) -> isize

Returns the number of decimals.

0.001/1e-3 will return 3, 1000/1e3 will return -3.

source

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).

source

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).

source

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).

source

pub fn powi(&self, exponent: usize) -> Scientific

Raise a number to an integer power.

source

pub fn is_zero(&self) -> bool

Returns true if the number is zero.

source

pub fn is_sign_positive(&self) -> bool

Returns true if the number is positive and not zero.

source

pub fn is_sign_negative(&self) -> bool

Returns true if the number is negative and not zero.

Trait Implementations§

source§

impl Add for &Scientific

§

type Output = Scientific

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl Clone for Scientific

source§

fn clone(&self) -> Scientific

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 Debug for Scientific

source§

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

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

impl<'de> Deserialize<'de> for Scientific

Available on crate feature serde only.
source§

fn deserialize<D>( deserializer: D ) -> Result<Self, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Scientific

source§

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

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

impl From<&Scientific> for f32

source§

fn from(value: &Scientific) -> Self

Converts to this type from the input type.
source§

impl From<&Scientific> for f64

source§

fn from(value: &Scientific) -> Self

Converts to this type from the input type.
source§

impl From<i128> for Scientific

source§

fn from(value: i128) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Scientific

source§

fn from(value: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Scientific

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Scientific

source§

fn from(value: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Scientific

source§

fn from(value: i8) -> Self

Converts to this type from the input type.
source§

impl From<isize> for Scientific

source§

fn from(val: isize) -> Self

Converts to this type from the input type.
source§

impl From<u128> for Scientific

source§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Scientific

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Scientific

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Scientific

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Scientific

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for Scientific

source§

fn from(val: usize) -> Self

Converts to this type from the input type.
source§

impl FromStr for Scientific

§

type Err = ConversionError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for &Scientific

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Mul for &Scientific

§

type Output = Scientific

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl Neg for &Scientific

§

type Output = Scientific

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Ord for Scientific

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Scientific

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Scientific

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Scientific

Available on crate feature serde only.
source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Shl<isize> for &Scientific

§

type Output = Scientific

The resulting type after applying the << operator.
source§

fn shl(self, rhs: isize) -> Self::Output

Performs the << operation. Read more
source§

impl ShlAssign<isize> for Scientific

source§

fn shl_assign(&mut self, rhs: isize)

Performs the <<= operation. Read more
source§

impl Shr<isize> for &Scientific

§

type Output = Scientific

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: isize) -> Self::Output

Performs the >> operation. Read more
source§

impl ShrAssign<isize> for Scientific

source§

fn shr_assign(&mut self, rhs: isize)

Performs the >>= operation. Read more
source§

impl Sub for &Scientific

§

type Output = Scientific

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl TryFrom<&Scientific> for i128

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for i16

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for i32

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for i64

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for i8

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for isize

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for u128

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for u16

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for u32

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for u64

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for u8

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Scientific> for usize

§

type Error = ConversionError

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

fn try_from(value: &Scientific) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<f32> for Scientific

§

type Error = ConversionError

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

fn try_from(value: f32) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<f64> for Scientific

§

type Error = ConversionError

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

fn try_from(value: f64) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for Scientific

source§

impl Send for Scientific

Available on crate feature arc only.
source§

impl Sync for Scientific

Available on crate feature arc only.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,