Struct rust_decimal::Decimal

source ·
#[repr(C)]
pub struct Decimal { /* private fields */ }
Expand description

Decimal represents a 128 bit representation of a fixed-precision decimal number. The finite set of values of type Decimal are of the form m / 10e, where m is an integer such that -296 < m < 296, and e is an integer between 0 and 28 inclusive.

Implementations§

The smallest value that can be represented by this decimal type.

Examples

Basic usage:

assert_eq!(Decimal::MIN, dec!(-79_228_162_514_264_337_593_543_950_335));

The largest value that can be represented by this decimal type.

Examples

Basic usage:

assert_eq!(Decimal::MAX, dec!(79_228_162_514_264_337_593_543_950_335));

A constant representing 0.

Examples

Basic usage:

assert_eq!(Decimal::ZERO, dec!(0));

A constant representing 1.

Examples

Basic usage:

assert_eq!(Decimal::ONE, dec!(1));

A constant representing -1.

Examples

Basic usage:

assert_eq!(Decimal::NEGATIVE_ONE, dec!(-1));

A constant representing 2.

Examples

Basic usage:

assert_eq!(Decimal::TWO, dec!(2));

A constant representing 10.

Examples

Basic usage:

assert_eq!(Decimal::TEN, dec!(10));

A constant representing 100.

Examples

Basic usage:

assert_eq!(Decimal::ONE_HUNDRED, dec!(100));

A constant representing 1000.

Examples

Basic usage:

assert_eq!(Decimal::ONE_THOUSAND, dec!(1000));

A constant representing π as 3.1415926535897932384626433833

Examples

Basic usage:

assert_eq!(Decimal::PI, dec!(3.1415926535897932384626433833));

A constant representing π/2 as 1.5707963267948966192313216916

Examples

Basic usage:

assert_eq!(Decimal::HALF_PI, dec!(1.5707963267948966192313216916));

A constant representing π/4 as 0.7853981633974483096156608458

Examples

Basic usage:

assert_eq!(Decimal::QUARTER_PI, dec!(0.7853981633974483096156608458));

A constant representing 2π as 6.2831853071795864769252867666

Examples

Basic usage:

assert_eq!(Decimal::TWO_PI, dec!(6.2831853071795864769252867666));

A constant representing Euler’s number (e) as 2.7182818284590452353602874714

Examples

Basic usage:

assert_eq!(Decimal::E, dec!(2.7182818284590452353602874714));

A constant representing the inverse of Euler’s number (1/e) as 0.3678794411714423215955237702

Examples

Basic usage:

assert_eq!(Decimal::E_INVERSE, dec!(0.3678794411714423215955237702));

Returns a Decimal with a 64 bit m representation and corresponding e scale.

Arguments
  • num - An i64 that represents the m portion of the decimal number
  • scale - A u32 representing the e portion of the decimal number.
Panics

This function panics if scale is > 28.

Example
let pi = Decimal::new(3141, 3);
assert_eq!(pi.to_string(), "3.141");

Checked version of Decimal::new. Will return Err instead of panicking at run-time.

Example
let max = Decimal::try_new(i64::MAX, u32::MAX);
assert!(max.is_err());

Creates a Decimal using a 128 bit signed m representation and corresponding e scale.

Arguments
  • num - An i128 that represents the m portion of the decimal number
  • scale - A u32 representing the e portion of the decimal number.
Panics

This function panics if scale is > 28 or if num exceeds the maximum supported 96 bits.

Example
let pi = Decimal::from_i128_with_scale(3141i128, 3);
assert_eq!(pi.to_string(), "3.141");

Checked version of Decimal::from_i128_with_scale. Will return Err instead of panicking at run-time.

Example
let max = Decimal::try_from_i128_with_scale(i128::MAX, u32::MAX);
assert!(max.is_err());

Returns a Decimal using the instances constituent parts.

Arguments
  • lo - The low 32 bits of a 96-bit integer.
  • mid - The middle 32 bits of a 96-bit integer.
  • hi - The high 32 bits of a 96-bit integer.
  • negative - true to indicate a negative number.
  • scale - A power of 10 ranging from 0 to 28.
Caution: Undefined behavior

While a scale greater than 28 can be passed in, it will be automatically capped by this function at the maximum precision. The library opts towards this functionality as opposed to a panic to ensure that the function can be treated as constant. This may lead to undefined behavior in downstream applications and should be treated with caution.

Example
let pi = Decimal::from_parts(1102470952, 185874565, 1703060790, false, 28);
assert_eq!(pi.to_string(), "3.1415926535897932384626433832");

Returns a Result which if successful contains the Decimal constitution of the scientific notation provided by value.

Arguments
  • value - The scientific notation of the Decimal.
Example
let value = Decimal::from_scientific("9.7e-7")?;
assert_eq!(value.to_string(), "0.00000097");

Converts a string slice in a given base to a decimal.

The string is expected to be an optional + sign followed by digits. Digits are a subset of these characters, depending on radix, and will return an error if outside the expected range:

  • 0-9
  • a-z
  • A-Z
Examples

Basic usage:

assert_eq!(Decimal::from_str_radix("A", 16)?.to_string(), "10");

Parses a string slice into a decimal. If the value underflows and cannot be represented with the given scale then this will return an error.

Examples

Basic usage:

assert_eq!(Decimal::from_str_exact("0.001")?.to_string(), "0.001");
assert_eq!(Decimal::from_str_exact("0.00000_00000_00000_00000_00000_001")?.to_string(), "0.0000000000000000000000000001");
assert_eq!(Decimal::from_str_exact("0.00000_00000_00000_00000_00000_0001"), Err(Error::Underflow));

Returns the scale of the decimal number, otherwise known as e.

Example
let num = Decimal::new(1234, 3);
assert_eq!(num.scale(), 3u32);

Returns the mantissa of the decimal number.

Example
use rust_decimal_macros::dec;

let num = dec!(-1.2345678);
assert_eq!(num.mantissa(), -12345678i128);
assert_eq!(num.scale(), 7);

Returns true if this Decimal number is equivalent to zero.

Example
let num = Decimal::ZERO;
assert!(num.is_zero());
👎Deprecated since 1.4.0: please use set_sign_positive instead

An optimized method for changing the sign of a decimal number.

Arguments
  • positive: true if the resulting decimal should be positive.
Example
let mut one = Decimal::ONE;
one.set_sign(false);
assert_eq!(one.to_string(), "-1");

An optimized method for changing the sign of a decimal number.

Arguments
  • positive: true if the resulting decimal should be positive.
Example
let mut one = Decimal::ONE;
one.set_sign_positive(false);
assert_eq!(one.to_string(), "-1");

An optimized method for changing the sign of a decimal number.

Arguments
  • negative: true if the resulting decimal should be negative.
Example
let mut one = Decimal::ONE;
one.set_sign_negative(true);
assert_eq!(one.to_string(), "-1");

An optimized method for changing the scale of a decimal number.

Arguments
  • scale: the new scale of the number
Example
let mut one = Decimal::ONE;
one.set_scale(5)?;
assert_eq!(one.to_string(), "0.00001");

Modifies the Decimal towards the desired scale, attempting to do so without changing the underlying number itself.

Setting the scale to something less then the current Decimals scale will cause the newly created Decimal to perform rounding using the MidpointAwayFromZero strategy.

Scales greater than the maximum precision that can be represented by Decimal will be automatically rounded to either Decimal::MAX_PRECISION or the maximum precision that can be represented with the given mantissa.

Arguments
  • scale: The desired scale to use for the new Decimal number.
Example
use rust_decimal_macros::dec;

// Rescaling to a higher scale preserves the value
let mut number = dec!(1.123);
assert_eq!(number.scale(), 3);
number.rescale(6);
assert_eq!(number.to_string(), "1.123000");
assert_eq!(number.scale(), 6);

// Rescaling to a lower scale forces the number to be rounded
let mut number = dec!(1.45);
assert_eq!(number.scale(), 2);
number.rescale(1);
assert_eq!(number.to_string(), "1.5");
assert_eq!(number.scale(), 1);

// This function never fails. Consequently, if a scale is provided that is unable to be
// represented using the given mantissa, then the maximum possible scale is used.
let mut number = dec!(11.76470588235294);
assert_eq!(number.scale(), 14);
number.rescale(28);
// A scale of 28 cannot be represented given this mantissa, however it was able to represent
// a number with a scale of 27
assert_eq!(number.to_string(), "11.764705882352940000000000000");
assert_eq!(number.scale(), 27);

Returns a serialized version of the decimal number. The resulting byte array will have the following representation:

  • Bytes 1-4: flags
  • Bytes 5-8: lo portion of m
  • Bytes 9-12: mid portion of m
  • Bytes 13-16: high portion of m

Deserializes the given bytes into a decimal number. The deserialized byte representation must be 16 bytes and adhere to the following convention:

  • Bytes 1-4: flags
  • Bytes 5-8: lo portion of m
  • Bytes 9-12: mid portion of m
  • Bytes 13-16: high portion of m
👎Deprecated since 0.6.3: please use is_sign_negative instead

Returns true if the decimal is negative.

👎Deprecated since 0.6.3: please use is_sign_positive instead

Returns true if the decimal is positive.

Returns true if the sign bit of the decimal is negative.

Example
assert_eq!(true, Decimal::new(-1, 0).is_sign_negative());
assert_eq!(false, Decimal::new(1, 0).is_sign_negative());

Returns true if the sign bit of the decimal is positive.

Example
assert_eq!(false, Decimal::new(-1, 0).is_sign_positive());
assert_eq!(true, Decimal::new(1, 0).is_sign_positive());
👎Deprecated since 1.12.0: Use the associated constant Decimal::MIN

Returns the minimum possible number that Decimal can represent.

👎Deprecated since 1.12.0: Use the associated constant Decimal::MAX

Returns the maximum possible number that Decimal can represent.

Returns a new Decimal integral with no fractional portion. This is a true truncation whereby no rounding is performed.

Example
let pi = Decimal::new(3141, 3);
let trunc = Decimal::new(3, 0);
// note that it returns a decimal
assert_eq!(pi.trunc(), trunc);

Returns a new Decimal representing the fractional portion of the number.

Example
let pi = Decimal::new(3141, 3);
let fract = Decimal::new(141, 3);
// note that it returns a decimal
assert_eq!(pi.fract(), fract);

Computes the absolute value of self.

Example
let num = Decimal::new(-3141, 3);
assert_eq!(num.abs().to_string(), "3.141");

Returns the largest integer less than or equal to a number.

Example
let num = Decimal::new(3641, 3);
assert_eq!(num.floor().to_string(), "3");

Returns the smallest integer greater than or equal to a number.

Example
let num = Decimal::new(3141, 3);
assert_eq!(num.ceil().to_string(), "4");
let num = Decimal::new(3, 0);
assert_eq!(num.ceil().to_string(), "3");

Returns the maximum of the two numbers.

let x = Decimal::new(1, 0);
let y = Decimal::new(2, 0);
assert_eq!(y, x.max(y));

Returns the minimum of the two numbers.

let x = Decimal::new(1, 0);
let y = Decimal::new(2, 0);
assert_eq!(x, x.min(y));

Strips any trailing zero’s from a Decimal and converts -0 to 0.

Example
let number = Decimal::from_str("3.100")?;
assert_eq!(number.normalize().to_string(), "3.1");

An in place version of normalize. Strips any trailing zero’s from a Decimal and converts -0 to 0.

Example
let mut number = Decimal::from_str("3.100")?;
assert_eq!(number.to_string(), "3.100");
number.normalize_assign();
assert_eq!(number.to_string(), "3.1");

Returns a new Decimal number with no fractional portion (i.e. an integer). Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

Example
// Demonstrating bankers rounding...
let number_down = Decimal::new(65, 1);
let number_up   = Decimal::new(75, 1);
assert_eq!(number_down.round().to_string(), "6");
assert_eq!(number_up.round().to_string(), "8");

Returns a new Decimal number with the specified number of decimal points for fractional portion. Rounding is performed using the provided RoundingStrategy

Arguments
  • dp: the number of decimal points to round to.
  • strategy: the RoundingStrategy to use.
Example
let tax = dec!(3.4395);
assert_eq!(tax.round_dp_with_strategy(2, RoundingStrategy::MidpointAwayFromZero).to_string(), "3.44");

Returns a new Decimal number with the specified number of decimal points for fractional portion. Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

Arguments
  • dp: the number of decimal points to round to.
Example
let pi = dec!(3.1415926535897932384626433832);
assert_eq!(pi.round_dp(2).to_string(), "3.14");

Returns Some(Decimal) number rounded to the specified number of significant digits. If the resulting number is unable to be represented by the Decimal number then None will be returned. When the number of significant figures of the Decimal being rounded is greater than the requested number of significant digits then rounding will be performed using MidpointNearestEven strategy.

Arguments
  • digits: the number of significant digits to round to.
Remarks

A significant figure is determined using the following rules:

  1. Non-zero digits are always significant.
  2. Zeros between non-zero digits are always significant.
  3. Leading zeros are never significant.
  4. Trailing zeros are only significant if the number contains a decimal point.
Example
use rust_decimal_macros::dec;

let value = dec!(305.459);
assert_eq!(value.round_sf(0), Some(dec!(0)));
assert_eq!(value.round_sf(1), Some(dec!(300)));
assert_eq!(value.round_sf(2), Some(dec!(310)));
assert_eq!(value.round_sf(3), Some(dec!(305)));
assert_eq!(value.round_sf(4), Some(dec!(305.5)));
assert_eq!(value.round_sf(5), Some(dec!(305.46)));
assert_eq!(value.round_sf(6), Some(dec!(305.459)));
assert_eq!(value.round_sf(7), Some(dec!(305.4590)));
assert_eq!(Decimal::MAX.round_sf(1), None);

let value = dec!(0.012301);
assert_eq!(value.round_sf(3), Some(dec!(0.0123)));

Returns Some(Decimal) number rounded to the specified number of significant digits. If the resulting number is unable to be represented by the Decimal number then None will be returned. When the number of significant figures of the Decimal being rounded is greater than the requested number of significant digits then rounding will be performed using the provided RoundingStrategy.

Arguments
  • digits: the number of significant digits to round to.
  • strategy: if required, the rounding strategy to use.
Remarks

A significant figure is determined using the following rules:

  1. Non-zero digits are always significant.
  2. Zeros between non-zero digits are always significant.
  3. Leading zeros are never significant.
  4. Trailing zeros are only significant if the number contains a decimal point.
Example
use rust_decimal_macros::dec;

let value = dec!(305.459);
assert_eq!(value.round_sf_with_strategy(0, RoundingStrategy::ToZero), Some(dec!(0)));
assert_eq!(value.round_sf_with_strategy(1, RoundingStrategy::ToZero), Some(dec!(300)));
assert_eq!(value.round_sf_with_strategy(2, RoundingStrategy::ToZero), Some(dec!(300)));
assert_eq!(value.round_sf_with_strategy(3, RoundingStrategy::ToZero), Some(dec!(305)));
assert_eq!(value.round_sf_with_strategy(4, RoundingStrategy::ToZero), Some(dec!(305.4)));
assert_eq!(value.round_sf_with_strategy(5, RoundingStrategy::ToZero), Some(dec!(305.45)));
assert_eq!(value.round_sf_with_strategy(6, RoundingStrategy::ToZero), Some(dec!(305.459)));
assert_eq!(value.round_sf_with_strategy(7, RoundingStrategy::ToZero), Some(dec!(305.4590)));
assert_eq!(Decimal::MAX.round_sf_with_strategy(1, RoundingStrategy::ToZero), Some(dec!(70000000000000000000000000000)));

let value = dec!(0.012301);
assert_eq!(value.round_sf_with_strategy(3, RoundingStrategy::AwayFromZero), Some(dec!(0.0124)));

Convert Decimal to an internal representation of the underlying struct. This is useful for debugging the internal state of the object.

Important Disclaimer

This is primarily intended for library maintainers. The internal representation of a Decimal is considered “unstable” for public use.

Example
use rust_decimal_macros::dec;

let pi = dec!(3.1415926535897932384626433832);
assert_eq!(format!("{:?}", pi), "3.1415926535897932384626433832");
assert_eq!(format!("{:?}", pi.unpack()), "UnpackedDecimal { \
    negative: false, scale: 28, hi: 1703060790, mid: 185874565, lo: 1102470952 \
}");

Parses a 32-bit float into a Decimal number whilst retaining any non-guaranteed precision.

Typically when a float is parsed in Rust Decimal, any excess bits (after ~7.22 decimal points for f32 as per IEEE-754) are removed due to any digits following this are considered an approximation at best. This function bypasses this additional step and retains these excess bits.

Example
// Usually floats are parsed leveraging float guarantees. i.e. 0.1_f32 => 0.1
assert_eq!("0.1", Decimal::from_f32(0.1_f32).unwrap().to_string());

// Sometimes, we may want to represent the approximation exactly.
assert_eq!("0.100000001490116119384765625", Decimal::from_f32_retain(0.1_f32).unwrap().to_string());

Parses a 64-bit float into a Decimal number whilst retaining any non-guaranteed precision.

Typically when a float is parsed in Rust Decimal, any excess bits (after ~15.95 decimal points for f64 as per IEEE-754) are removed due to any digits following this are considered an approximation at best. This function bypasses this additional step and retains these excess bits.

Example
// Usually floats are parsed leveraging float guarantees. i.e. 0.1_f64 => 0.1
assert_eq!("0.1", Decimal::from_f64(0.1_f64).unwrap().to_string());

// Sometimes, we may want to represent the approximation exactly.
assert_eq!("0.1000000000000000055511151231", Decimal::from_f64_retain(0.1_f64).unwrap().to_string());

Checked addition. Computes self + other, returning None if overflow occurred.

Saturating addition. Computes self + other, saturating at the relevant upper or lower boundary.

Checked multiplication. Computes self * other, returning None if overflow occurred.

Saturating multiplication. Computes self * other, saturating at the relevant upper or lower boundary.

Checked subtraction. Computes self - other, returning None if overflow occurred.

Saturating subtraction. Computes self - other, saturating at the relevant upper or lower boundary.

Checked division. Computes self / other, returning None if overflow occurred.

Checked remainder. Computes self % other, returning None if overflow occurred.

Trait Implementations§

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Generate an arbitrary value of Self from the given unstructured data. Read more
Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
The archived representation of this type. Read more
The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Creates the archived version of this value at the given position and writes it to the given output. Read more
The expression being returned
Perform the conversion
The expression being returned
Perform the conversion
The expression being returned
Perform the conversion
The expression being returned
Perform the conversion
Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Deserialize this instance from a slice of bytes.
Get the name of the type without brackets.
Recursively, using DFS, add type definitions required for this type. For primitive types this is an empty map. Type definition explains how to serialize/deserialize a type.
Helper method to add a single type definition to the map.
Serialize this instance into a vector of bytes.
Adds two numbers, checking for overflow. If overflow happens, None is returned.
Divides two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned.
Multiplies two numbers, checking for underflow or overflow. If underflow or overflow happens, None is returned.
Finds the remainder of dividing two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned. Read more
Subtracts two numbers, checking for underflow. If underflow happens, None is returned.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Returns the default value for a Decimal (equivalent to Decimal::ZERO). Read more

Deserialize this value from the given Serde deserializer. Read more
Deserializes using the given deserializer
Formats the value using the given formatter. Read more
Generate a random value of T, using rng as the source of randomness.
Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Converts to this type from the input type.
Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.

Conversion to Decimal.

Converts to this type from the input type.
Returns a default value, if any exists, to be used during lenient parsing when the form field is missing. Read more
Parse a value of T from a form value field. Read more
Parse a value of T from a form data field. Read more
Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an i128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an u64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an u128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts a f64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more
Determines if a value of this type can be created from the specified Postgres Type.
Creates a new value of this type from a NULL SQL value. Read more
A convenience function that delegates to from_sql and from_sql_null depending on the value of raw.
See the trait documentation.
A specialized variant of from_sql for handling null values. Read more
See the trait documentation.
A specialized variant of from_sql for handling null values. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The result after applying the operator.
Returns the multiplicative inverse of self. Read more
Formats the value using the given formatter.
The estimated exponential function, ex. Stops calculating when it is within tolerance of roughly 0.0000002.
The estimated exponential function, ex. Stops calculating when it is within tolerance of roughly 0.0000002. Returns None on overflow.
The estimated exponential function, ex using the tolerance provided as a hint as to when to stop calculating. A larger tolerance will cause the number to stop calculating sooner at the potential cost of a slightly less accurate result.
The estimated exponential function, ex using the tolerance provided as a hint as to when to stop calculating. A larger tolerance will cause the number to stop calculating sooner at the potential cost of a slightly less accurate result. Returns None on overflow.
Raise self to the given integer exponent: xy
Raise self to the given integer exponent xy returning None on overflow.
Raise self to the given unsigned integer exponent: xy
Raise self to the given unsigned integer exponent xy returning None on overflow.
Raise self to the given floating point exponent: xy
Raise self to the given floating point exponent xy returning None on overflow.
Raise self to the given Decimal exponent: xy. If exp is not whole then the approximation ey*ln(x) is used.
Raise self to the given Decimal exponent xy returning None on overflow. If exp is not whole then the approximation ey*ln(x) is used.
The square root of a Decimal. Uses a standard Babylonian method.
Calculates the natural logarithm for a Decimal calculated using Taylor’s series.
Calculates the checked natural logarithm for a Decimal calculated using Taylor’s series. Returns None for negative numbers or zero.
Calculates the base 10 logarithm of a specified Decimal number.
Calculates the checked base 10 logarithm of a specified Decimal number. Returns None for negative numbers or zero.
Abramowitz Approximation of Error Function from wikipedia
The Cumulative distribution function for a Normal distribution
The Probability density function for a Normal distribution.
The Probability density function for a Normal distribution returning None on overflow.
Computes the sine of a number (in radians). Panics upon overflow.
Computes the checked sine of a number (in radians).
Computes the cosine of a number (in radians). Panics upon overflow.
Computes the checked cosine of a number (in radians).
Computes the tangent of a number (in radians). Panics upon overflow or upon approaching a limit.
Computes the checked tangent of a number (in radians). Returns None on limit.
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
Convert from a string and radix (typically 2..=36). Read more
Returns the multiplicative identity element of Self, 1. Read more
Sets self to the multiplicative identity element of Self, 1.
Returns true if self is equal to the multiplicative identity. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The result after applying the operator.
Returns self to the power rhs. Read more
The result after applying the operator.
Returns self to the power rhs. Read more
The result after applying the operator.
Returns self to the power rhs. Read more
The result after applying the operator.
Returns self to the power rhs. Read more

Panics if out-of-bounds

Panics if out-of-bounds

The Rust type you’d like to map from. Read more
Construct an instance of this type
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more
The UniformSampler implementation supporting type X.
Writes the dependencies for the object and returns a resolver that can create the archived type.
Serialize this value into the given Serde serializer. Read more
Computes the absolute value. Read more
The positive difference of two numbers. Read more
Returns the sign of the number. Read more
Returns true if the number is positive and false if the number is zero or negative.
Returns true if the number is negative and false if the number is zero or positive.
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Method which takes an iterator and generates Self from the elements by “summing up” the items.
Method which takes an iterator and generates Self from the elements by “summing up” the items.
Converts the value of self to an i64. If the value cannot be represented by an i64, then None is returned.
Converts the value of self to an i128. If the value cannot be represented by an i128 (i64 under the default implementation), then None is returned. Read more
Converts the value of self to a u64. If the value cannot be represented by a u64, then None is returned.
Converts the value of self to a u128. If the value cannot be represented by a u128 (u64 under the default implementation), then None is returned. Read more
Converts the value of 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 more
Converts the value of self to an isize. If the value cannot be represented by an isize, then None is returned.
Converts the value of self to an i8. If the value cannot be represented by an i8, then None is returned.
Converts the value of self to an i16. If the value cannot be represented by an i16, then None is returned.
Converts the value of self to an i32. If the value cannot be represented by an i32, then None is returned.
Converts the value of self to a usize. If the value cannot be represented by a usize, then None is returned.
Converts the value of self to a u8. If the value cannot be represented by a u8, then None is returned.
Converts the value of self to a u16. If the value cannot be represented by a u16, then None is returned.
Converts the value of self to a u32. If the value cannot be represented by a u32, then None is returned.
Converts the value of self to an f32. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f32.
See the trait documentation.
See the trait documentation.
See the trait documentation.
Converts the value of self into the binary format of the specified Postgres Type, appending it to out. Read more
Determines if a value of this type can be converted to the specified Postgres Type.
An adaptor method used internally by Rust-Postgres. Read more
Specify the encode format
The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a &str into a Decimal.

Can fail if the value is out of range for Decimal.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to f32.

Can fail if the Decimal is out of range for f32.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to f64.

Can fail if the Decimal is out of range for f64.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to i128 by truncating and returning the integer component.

Can fail if the Decimal is out of range for i128.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to i16 by truncating and returning the integer component.

Can fail if the Decimal is out of range for i16.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to i32 by truncating and returning the integer component.

Can fail if the Decimal is out of range for i32.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to i64 by truncating and returning the integer component.

Can fail if the Decimal is out of range for i64.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to i8 by truncating and returning the integer component.

Can fail if the Decimal is out of range for i8.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to isize by truncating and returning the integer component.

Can fail if the Decimal is out of range for isize.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to u128 by truncating and returning the integer component.

Can fail if the Decimal is out of range for u128.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to u16 by truncating and returning the integer component.

Can fail if the Decimal is out of range for u16.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to u32 by truncating and returning the integer component.

Can fail if the Decimal is out of range for u32.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to u64 by truncating and returning the integer component.

Can fail if the Decimal is out of range for u64.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to u8 by truncating and returning the integer component.

Can fail if the Decimal is out of range for u8.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a Decimal to usize by truncating and returning the integer component.

Can fail if the Decimal is out of range for usize.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a f32 into a Decimal.

Can fail if the value is out of range for Decimal.

The type returned in the event of a conversion error.
Performs the conversion.

Try to convert a f64 into a Decimal.

Can fail if the value is out of range for Decimal.

The type returned in the event of a conversion error.
Performs the conversion.
Formats the value using the given formatter.
Returns the additive identity element of Self, 0. Read more
Returns true if self is equal to the additive identity.
Sets self to the additive identity element of Self, 0.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
The resolver for the metadata of this type. Read more
Creates the archived version of the metadata for this value at the given position and writes it to the given output. Read more
Resolves a relative pointer to this value with the given from and to and writes it to the given output. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Returns a reference to self as a ToSql trait object.
Deserializes using the given deserializer
Compare self to key and return true if they are equal.

Returns the argument unchanged.

The form guard’s parsing context.
Initializes and returns the parsing context for Self.
Processes the value field field.
Processes the data field field.
Finalizes parsing. Returns the parsed value when successful or collection of Errors otherwise.
Processes the external form or field error _error. Read more
Returns a default value, if any, to use when a value is desired and parsing fails. Read more
See the trait documentation.
See the trait documentation
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts self into a collection.
Convert self to an expression for Diesel’s query builder. Read more
Convert &self to an expression for Diesel’s query builder. Read more
Convert self to an expression for Diesel’s query builder. Read more
Convert &self to an expression for Diesel’s query builder. Read more
Gets the layout of the type.
The type for metadata in pointers and references to Self.
Should always be Self
Immutably borrows from an owned value. See Borrow::borrow
Writes the object and returns the position of the archived type.
Serializes the metadata for the given type.
The number of fields that this type will consume.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more