Struct fixnum::FixedPoint[][src]

pub struct FixedPoint<I, P> { /* fields omitted */ }
This is supported on crate features i128 or i64 or i32 or i16 only.
Expand description

Abstraction over fixed point numbers of arbitrary (but only compile-time specified) size and precision.

The internal representation is a fixed point decimal number, an integer value pre-multiplied by 10 ^ PRECISION, where PRECISION is a compile-time-defined decimal places count.

Maximal possible value: MAX = (2 ^ (BITS_COUNT - 1) - 1) / 10 ^ PRECISION Maximal possible calculation error: ERROR_MAX = 0.5 / (10 ^ PRECISION)

E.g. for i64 with 9 decimal places:

MAX = (2 ^ (64 - 1) - 1) / 1e9 = 9223372036.854775807 ~ 9.2e9
ERROR_MAX = 0.5 / 1e9 = 5e-10

Implementations

This is supported on crate feature i16 only.
This is supported on crate feature i16 only.
This is supported on crate feature i16 only.
This is supported on crate feature i16 only.

Checked negation. Returns Err on overflow (you can’t negate MIN value).

This is supported on crate feature i16 only.
This is supported on crate feature i16 only.

Takes rounded integral part of the number.

use fixnum::{FixedPoint, typenum::U9, ops::RoundMode::*};

type Amount = FixedPoint<i64, U9>;

let a: Amount = "8273.519".parse()?;
assert_eq!(a.integral(Floor), 8273);
assert_eq!(a.integral(Ceil), 8274);

let a: Amount = "-8273.519".parse()?;
assert_eq!(a.integral(Floor), -8274);
assert_eq!(a.integral(Ceil), -8273);
This is supported on crate feature i16 only.
This is supported on crate feature i16 only.
👎 Deprecated since 0.6.0:

Use TryFrom instead

This is supported on crate features i16 and std only.
👎 Deprecated since 0.6.0:

Use From instead

This is supported on crate feature i16 only.
This is supported on crate feature i16 only.
This is supported on crate feature i16 only.
This is supported on crate feature i16 only.
This is supported on crate feature i32 only.
This is supported on crate feature i32 only.
This is supported on crate feature i32 only.
This is supported on crate feature i32 only.

Checked negation. Returns Err on overflow (you can’t negate MIN value).

This is supported on crate feature i32 only.
This is supported on crate feature i32 only.

Takes rounded integral part of the number.

use fixnum::{FixedPoint, typenum::U9, ops::RoundMode::*};

type Amount = FixedPoint<i64, U9>;

let a: Amount = "8273.519".parse()?;
assert_eq!(a.integral(Floor), 8273);
assert_eq!(a.integral(Ceil), 8274);

let a: Amount = "-8273.519".parse()?;
assert_eq!(a.integral(Floor), -8274);
assert_eq!(a.integral(Ceil), -8273);
This is supported on crate feature i32 only.
This is supported on crate feature i32 only.
👎 Deprecated since 0.6.0:

Use TryFrom instead

This is supported on crate features i32 and std only.
👎 Deprecated since 0.6.0:

Use From instead

This is supported on crate feature i32 only.
This is supported on crate feature i32 only.
This is supported on crate feature i32 only.
This is supported on crate feature i32 only.
This is supported on crate feature i64 only.
This is supported on crate feature i64 only.
This is supported on crate feature i64 only.
This is supported on crate feature i64 only.

Checked negation. Returns Err on overflow (you can’t negate MIN value).

This is supported on crate feature i64 only.
This is supported on crate feature i64 only.

Takes rounded integral part of the number.

use fixnum::{FixedPoint, typenum::U9, ops::RoundMode::*};

type Amount = FixedPoint<i64, U9>;

let a: Amount = "8273.519".parse()?;
assert_eq!(a.integral(Floor), 8273);
assert_eq!(a.integral(Ceil), 8274);

let a: Amount = "-8273.519".parse()?;
assert_eq!(a.integral(Floor), -8274);
assert_eq!(a.integral(Ceil), -8273);
This is supported on crate feature i64 only.
This is supported on crate feature i64 only.
👎 Deprecated since 0.6.0:

Use TryFrom instead

This is supported on crate features i64 and std only.
👎 Deprecated since 0.6.0:

Use From instead

This is supported on crate feature i64 only.
This is supported on crate feature i64 only.
This is supported on crate feature i64 only.
This is supported on crate feature i64 only.
This is supported on crate feature i128 only.
This is supported on crate feature i128 only.
This is supported on crate feature i128 only.
This is supported on crate feature i128 only.

Checked negation. Returns Err on overflow (you can’t negate MIN value).

This is supported on crate feature i128 only.
This is supported on crate feature i128 only.

Takes rounded integral part of the number.

use fixnum::{FixedPoint, typenum::U9, ops::RoundMode::*};

type Amount = FixedPoint<i64, U9>;

let a: Amount = "8273.519".parse()?;
assert_eq!(a.integral(Floor), 8273);
assert_eq!(a.integral(Ceil), 8274);

let a: Amount = "-8273.519".parse()?;
assert_eq!(a.integral(Floor), -8274);
assert_eq!(a.integral(Ceil), -8273);
This is supported on crate feature i128 only.
This is supported on crate feature i128 only.
👎 Deprecated since 0.6.0:

Use TryFrom instead

This is supported on crate features i128 and std only.
👎 Deprecated since 0.6.0:

Use From instead

This is supported on crate feature i128 only.
This is supported on crate feature i128 only.
This is supported on crate feature i128 only.
This is supported on crate feature i128 only.

Trait Implementations

Checked addition. Returns Err on overflow. Read more

Saturating addition. Computes self + rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Read more

Checked addition. Returns Err on overflow. Read more

Saturating addition. Computes self + rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Read more

Checked addition. Returns Err on overflow. Read more

Saturating addition. Computes self + rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Read more

Checked addition. Returns Err on overflow. Read more

Saturating addition. Computes self + rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Read more

Checked multiplication. Returns Err on overflow. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Saturating multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Checked multiplication. Returns Err on overflow. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Saturating multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Checked multiplication. Returns Err on overflow. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Saturating multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Checked multiplication. Returns Err on overflow. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Saturating multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Checked multiplication. Returns Err on overflow. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Saturating multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Checked multiplication. Returns Err on overflow. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Saturating multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Checked multiplication. Returns Err on overflow. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Saturating multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Checked multiplication. Returns Err on overflow. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Saturating multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. This is multiplication without rounding, hence it’s available only when at least one operand is integer. Read more

Checked subtraction. Returns Err on overflow. Read more

Saturating subtraction. Computes self - rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Read more

Checked subtraction. Returns Err on overflow. Read more

Saturating subtraction. Computes self - rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Read more

Checked subtraction. Returns Err on overflow. Read more

Saturating subtraction. Computes self - rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Read more

Checked subtraction. Returns Err on overflow. Read more

Saturating subtraction. Computes self - rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

A compact-encodable type that should be used as the encoding.

Returns the compact-encodable type.

Decode Self from the compact-decoded type.

A compact-encodable type that should be used as the encoding.

Returns the compact-encodable type.

Decode Self from the compact-decoded type.

A compact-encodable type that should be used as the encoding.

Returns the compact-encodable type.

Decode Self from the compact-decoded type.

A compact-encodable type that should be used as the encoding.

Returns the compact-encodable type.

Decode Self from the compact-decoded type.

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Attempt to deserialise the value from input.

Attempt to skip the encoded value from input. Read more

Returns the fixed encoded size of the type. Read more

Attempt to deserialise the value from input.

Attempt to skip the encoded value from input. Read more

Returns the fixed encoded size of the type. Read more

Attempt to deserialise the value from input.

Attempt to skip the encoded value from input. Read more

Returns the fixed encoded size of the type. Read more

Attempt to deserialise the value from input.

Attempt to skip the encoded value from input. Read more

Returns the fixed encoded size of the type. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Convert self to a slice and append it to the destination.

If possible give a hint of expected size of the encoding. Read more

Convert self to an owned vector.

Convert self to a slice and then invoke the given closure with it.

Calculates the encoded size. Read more

Convert self to a slice and append it to the destination.

If possible give a hint of expected size of the encoding. Read more

Convert self to an owned vector.

Convert self to a slice and then invoke the given closure with it.

Calculates the encoded size. Read more

Convert self to a slice and append it to the destination.

If possible give a hint of expected size of the encoding. Read more

Convert self to an owned vector.

Convert self to a slice and then invoke the given closure with it.

Calculates the encoded size. Read more

Convert self to a slice and append it to the destination.

If possible give a hint of expected size of the encoding. Read more

Convert self to an owned vector.

Convert self to a slice and then invoke the given closure with it.

Calculates the encoded size. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The associated error which can be returned from parsing.

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

The associated error which can be returned from parsing.

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

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. 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

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 ==. Read more

This method tests for !=.

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

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded division. Returns Err on overflow or attempt to divide by zero. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded multiplication. Returns Err on overflow. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Saturating rounding multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded multiplication. Returns Err on overflow. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Saturating rounding multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded multiplication. Returns Err on overflow. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Saturating rounding multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounded multiplication. Returns Err on overflow. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Saturating rounding multiplication. Computes self * rhs, saturating at the numeric bounds (MIN, MAX) instead of overflowing. Because of provided RoundMode it’s possible to perform across the FixedPoint values. Read more

Checked rounding square root. Returns Err for negative argument. Read more

Checked rounding square root. Returns Err for negative argument. Read more

Checked rounding square root. Returns Err for negative argument. Read more

Checked rounding square root. Returns Err for negative argument. Read more

Serialize this value into the given Serde serializer. 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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Decode Self and consume all of the given input data. Read more

Decode Self and consume all of the given input data. Read more

Decode Self and advance input by the number of bytes consumed. Read more

Decode Self with the given maximum recursion depth. Read more

Performs the conversion.

The compact type; this can be

Performs the conversion.

Return an encoding of Self prepended by given slice.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.