Struct custom_float::Fp

source ·
pub struct Fp<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize>(/* private fields */)
where
    [(); { _ }]:;
Expand description

A custom floating point type, where the bit size of the exponent and mantissa can be set separately.

U is the underlying unsigned integer type which is used to represent the number.

SIGN_BIT is wether or not the number has a sign bit.

EXP_SIZE is the size of the exponent in bits.

INT_SIZE is the size of the integer part of the mantissa in bits. If zero, then the integer bit is implicit.

FRAC_SIZE is the size of the fractional part of the mantissa in bits.

EXP_BASE is the base of the exponent.

The total bit size of U must be greater or equal to SIGN_BIT + EXP_SIZE + INT_SIZE + FRAC_SIZE to contain the entire number.

The bit layout is as follows:

No data: | Sign:      | Exponent:  | Integer:   | Fractional: |
<  ..  > | <SIGN_BIT> | <EXP_SIZE> | <INT_SIZE> | <FRAC_SIZE> |

The value of a real floating-point number is the following:

x = (-1)**sign*EXP_BASE**(exponent - bias)*mantissa

where the bias equals

bias = 2**(EXP_SIZE - 1) - 1

If the exponent has the maximum value, the number is either infinity or NaN.

The number then automatically implements num::Float, and supports all ordinary floating point operations.

This allows simple implementation of special floating point types, such as TensorFloat, IEEE754 Quadruple/binary128, Fp80, and BFloat16.

The accuracy of all of the floating point operations are not perfect, but work well enough to be usable. Various plots showing the accuracy of basic functions are shown in the plots subfolder.

All floats can be converted into each other painlessly, though the conversion may produce rounding errors or unbounded outputs when converting to a float with lesser resolution.

§Examples

#![feature(generic_const_exprs)]

use custom_float::Fp;

type FpSingle = Fp<u32, true, 8, 0, 23, 2>;

let two = FpSingle::from(2);
let four = FpSingle::from(4);
 
assert_eq!(two + two, four);

Implementations§

source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source

pub const BIT_SIZE: usize = _

Size of floating-point number in bits

source

pub const SIGN_SIZE: usize = _

Size of the sign bit

source

pub const SIGN_POS: usize = _

Position of the sign bit

source

pub const EXP_POS: usize = _

Position of the first exponent bit

source

pub const INT_POS: usize = FRAC_SIZE

Position of the first integer bit

source

pub const FRAC_POS: usize = 0usize

Position of the first fractional bit

source

pub const MANTISSA_DIGITS: usize = _

Number of significant digits in base 2.

source

pub const IS_INT_IMPLICIT: bool = _

true if the number contains an implicit integer bit

source

pub fn from<T>(from: T) -> Self
where Self: From<T>,

Converts to this type from the input type.

source

pub fn from_fp<V: UInt, const S: bool, const E: usize, const I: usize, const F: usize, const B: usize>( fp: Fp<V, S, E, I, F, B> ) -> Self
where [(); { _ }]:,

Converts from one custom floating-point number to another. Rounding errors may occurr.

source

pub fn from_uint<I: UInt>(from: I) -> Self

Converts an unsigned integer into a custom floating-point type.

source

pub fn from_int<I: Int>(from: I) -> Self

Converts a signed integer into a custom floating-point type.

source

pub fn to_uint<I: UInt>(self) -> Option<I>

Converts a custom floating-point type into an unsigned integer.

Returns None if out of bounds.

source

pub fn to_uint_wrapping<I: UInt>(self) -> I

Converts a custom floating-point type into an unsigned integer.

Wraps if out of bounds.

source

pub fn to_int<I: Int>(self) -> Option<I>

Converts a custom floating-point type into a signed integer.

Returns None if out of bounds.

source

pub fn to_int_wrapping<I: Int>(self) -> I

Converts a custom floating-point type into a signed integer.

Wraps if out of bounds.

source

pub const fn from_bits(bits: U) -> Self

Raw transmutation from bits.

Note that this function is distinct from Fp::from_uint, which attempts to preserve the numeric value, and not the bitwise value.

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

let v = FpSingle::from_bits(0x41480000);
assert_eq!(v, FpSingle::from(12.5));
source

pub const fn to_bits(self) -> U

Raw transmutation to bits.

Note that this function is distinct from Fp::to_uint, which attempts to preserve the numeric value, and not the bitwise value.

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

assert_ne!(FpSingle::from(1.0).to_bits(), FpSingle::from(1.0).to_uint().unwrap()); // to_bits() is not casting!
assert_eq!(FpSingle::from(12.5).to_bits(), 0x41480000);
source

pub fn to_be_bytes(self) -> U::Bytes
where U: ToBytes,

Return the memory representation of this floating point number as a byte array in big-endian (network) byte order.

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

let bytes = FpSingle::from(12.5).to_be_bytes();
assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
source

pub fn to_le_bytes(self) -> U::Bytes
where U: ToBytes,

Return the memory representation of this floating point number as a byte array in little-endian byte order.

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

let bytes = FpSingle::from(12.5).to_le_bytes();
assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
source

pub fn to_ne_bytes(self) -> U::Bytes
where U: ToBytes,

Return the memory representation of this floating point number as a byte array in native byte order.

As the target platform’s native endianness is used, portable code should use to_be_bytes or to_le_bytes, as appropriate, instead.

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

let bytes = FpSingle::from(12.5).to_ne_bytes();
assert_eq!(
    bytes,
    if cfg!(target_endian = "big") {
        [0x41, 0x48, 0x00, 0x00]
    } else {
        [0x00, 0x00, 0x48, 0x41]
    }
);
source

pub fn from_be_bytes(bytes: &U::Bytes) -> Self
where U: FromBytes,

Create a floating point value from its representation as a byte array in big endian.

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

let value = FpSingle::from_be_bytes(&[0x41, 0x48, 0x00, 0x00]);
assert_eq!(value, FpSingle::from(12.5));
source

pub fn from_le_bytes(bytes: &U::Bytes) -> Self
where U: FromBytes,

Create a floating point value from its representation as a byte array in little endian.

See from_bits for some discussion of the portability of this operation (there are almost no issues).

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

let value = FpSingle::from_le_bytes(&[0x00, 0x00, 0x48, 0x41]);
assert_eq!(value, FpSingle::from(12.5));
source

pub fn from_ne_bytes(bytes: &U::Bytes) -> Self
where U: FromBytes,

Create a floating point value from its representation as a byte array in native endian.

As the target platform’s native endianness is used, portable code likely wants to use from_be_bytes or from_le_bytes, as appropriate instead.

See from_bits for some discussion of the portability of this operation (there are almost no issues).

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

let value = FpSingle::from_ne_bytes(if cfg!(target_endian = "big") {
    &[0x41, 0x48, 0x00, 0x00]
} else {
    &[0x00, 0x00, 0x48, 0x41]
});
assert_eq!(value, FpSingle::from(12.5));
source

pub fn sign_bit(self) -> U

Returns the sign bit of the custom floating-point number.

source

pub fn exp_bits(self) -> U

Returns the exponent bits of the custom floating-point number.

source

pub fn int_bits(self) -> U

Returns the integer bits of the custom floating-point number.

source

pub fn frac_bits(self) -> U

Returns the fractional bits of the custom floating-point number.

source

pub fn exp_bias() -> U

Returns the exponent bias

source

pub fn nan() -> Self

Returns the NaN value.

§Examples
use custom_float::ieee754::FpSingle;

let nan = FpSingle::nan();

assert!(nan.is_nan());
source

pub fn qnan() -> Self

Returns the qNaN value.

§Examples
use custom_float::ieee754::FpSingle;

let qnan = FpSingle::qnan();

assert!(qnan.is_nan());
assert!(!qnan.is_snan());
source

pub fn snan() -> Self

Returns the sNaN value.

§Examples
use custom_float::ieee754::FpSingle;

let snan = FpSingle::snan();

assert!(snan.is_nan());
assert!(snan.is_snan());
source

pub fn is_snan(self) -> bool

Returns true if the number is a signaling NaN.

§Examples
use custom_float::ieee754::FpSingle;

let snan = FpSingle::snan();
let qnan = FpSingle::qnan();

assert!(snan.is_snan());
assert!(!qnan.is_snan());
source

pub fn infinity() -> Self

Returns the infinite value.

§Examples
use custom_float::ieee754::FpSingle;

let infinity = FpSingle::infinity();

assert!(infinity.is_infinite());
assert!(!infinity.is_finite());
assert!(infinity > FpSingle::max_value());
source

pub fn neg_infinity() -> Self

Returns the negative infinite value.

§Examples
#![feature(generic_const_exprs)]

use custom_float::ieee754::FpSingle;

let neg_infinity = FpSingle::neg_infinity();

assert!(neg_infinity.is_infinite());
assert!(!neg_infinity.is_finite());
assert!(neg_infinity < FpSingle::min_value());
source

pub fn neg_zero() -> Self

Returns -0.0.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;

let inf = FpSingle::infinity();
let zero = FpSingle::zero();
let neg_zero = FpSingle::neg_zero();

assert_eq!(zero, neg_zero);
assert_eq!(FpSingle::from(7.0)/inf, zero);
assert_eq!(zero * FpSingle::from(10.0), zero);
source

pub fn min_value() -> Self

Returns the smallest finite value.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use std::f64;

let x = FpDouble::min_value();

assert_eq!(x, FpDouble::from(f64::MIN));
source

pub fn min_positive_value() -> Self

Returns the smallest positive, normal value.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use std::f64;

let x = FpDouble::min_positive_value();

assert_eq!(x, FpDouble::from(f64::MIN_POSITIVE));
source

pub fn epsilon() -> Self

Machine epsilon value.

This is the difference between 1.0 and the next larger representable number.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use std::f64;

let x = FpDouble::epsilon();

assert_eq!(x, FpDouble::from(f64::EPSILON));
source

pub fn max_value() -> Self

Returns the largest finite value.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use std::f64;

let x = FpDouble::max_value();
assert_eq!(x, FpDouble::from(f64::MAX));
source

pub fn is_nan(self) -> bool

Returns true if this value is NaN.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let nan = FpDouble::nan();
let f = FpDouble::from(7.0);

assert!(nan.is_nan());
assert!(!f.is_nan());
source

pub fn is_infinite(self) -> bool

Returns true if this value is positive infinity or negative infinity, and false otherwise.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;

let f = FpSingle::from(7.0);
let inf = FpSingle::infinity();
let neg_inf = FpSingle::neg_infinity();
let nan = FpSingle::nan();

assert!(!f.is_infinite());
assert!(!nan.is_infinite());

assert!(inf.is_infinite());
assert!(neg_inf.is_infinite());
source

pub fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;

let f = FpSingle::from(7.0);
let inf = FpSingle::infinity();
let neg_inf = FpSingle::neg_infinity();
let nan = FpSingle::nan();

assert!(f.is_finite());

assert!(!nan.is_finite());
assert!(!inf.is_finite());
assert!(!neg_inf.is_finite());
source

pub fn is_normal(self) -> bool

Returns true if the number is neither zero, infinite, subnormal, or NaN.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;

let min = FpSingle::min_positive_value(); // 1.17549435e-38f32
let max = FpSingle::max_value();
let lower_than_min = FpSingle::from(1.0e-40_f32);
let zero = FpSingle::zero();

assert!(min.is_normal());
assert!(max.is_normal());

assert!(!zero.is_normal());
assert!(!FpSingle::nan().is_normal());
assert!(!FpSingle::infinity().is_normal());
// Values between `0` and `min` are Subnormal.
assert!(!lower_than_min.is_normal());
source

pub fn is_subnormal(self) -> bool

Returns true if the number is subnormal.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let min = FpDouble::min_positive_value(); // 2.2250738585072014e-308_f64
let max = FpDouble::max_value();
let lower_than_min = FpDouble::from(1.0e-308_f64);
let zero = FpDouble::zero();

assert!(!min.is_subnormal());
assert!(!max.is_subnormal());

assert!(!zero.is_subnormal());
assert!(!FpDouble::nan().is_subnormal());
assert!(!FpDouble::infinity().is_subnormal());
// Values between `0` and `min` are Subnormal.
assert!(lower_than_min.is_subnormal());
source

pub fn classify(self) -> FpCategory

Returns the floating point category of the number. If only one property is going to be tested, it is generally faster to use the specific predicate instead.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use std::num::FpCategory;

let num = FpDouble::from(12.4f32);
let inf = FpDouble::infinity();

assert_eq!(num.classify(), FpCategory::Normal);
assert_eq!(inf.classify(), FpCategory::Infinite);
source

pub fn floor(self) -> Self

Returns the largest integer less than or equal to self.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::from(3.99);
let g = FpDouble::from(3.0);

assert_eq!(f.floor(), FpDouble::from(3.0));
assert_eq!(g.floor(), FpDouble::from(3.0));
source

pub fn ceil(self) -> Self

Returns the smallest integer greater than or equal to self.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::from(3.01);
let g = FpDouble::from(4.0);

assert_eq!(f.ceil(), FpDouble::from(4.0));
assert_eq!(g.ceil(), FpDouble::from(4.0));
source

pub fn round(self) -> Self

Returns the nearest integer to self. If a value is half-way between two integers, round away from 0.0.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::from(3.3);
let g = FpDouble::from(-3.3);

assert_eq!(f.round(), FpDouble::from(3.0));
assert_eq!(g.round(), FpDouble::from(-3.0));
source

pub fn round_ties_even(self) -> Self

Returns the nearest integer to a number. Rounds half-way cases to the number with an even least significant digit.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;

let f = FpSingle::from(3.3);
let g = FpSingle::from(-3.3);
let h = FpSingle::from(3.5);
let i = FpSingle::from(4.5);

assert_eq!(f.round_ties_even(), FpSingle::from(3.0));
assert_eq!(g.round_ties_even(), FpSingle::from(-3.0));
assert_eq!(h.round_ties_even(), FpSingle::from(4.0));
assert_eq!(i.round_ties_even(), FpSingle::from(4.0));
source

pub fn trunc(self) -> Self

Returns the integer part of self. This means that non-integer numbers are always truncated towards zero.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::from(3.3);
let g = FpDouble::from(-3.7);

assert_eq!(f.trunc(), FpDouble::from(3.0));
assert_eq!(g.trunc(), FpDouble::from(-3.0));
source

pub fn fract(self) -> Self

Returns the fractional part of a number.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(3.5);
let y = FpDouble::from(-3.5);
let abs_difference_x = (x.fract() - FpDouble::from(0.5)).abs();
let abs_difference_y = (y.fract() - FpDouble::from(-0.5)).abs();

assert!(abs_difference_x < FpDouble::from(1e-10));
assert!(abs_difference_y < FpDouble::from(1e-10));
source

pub fn abs(self) -> Self

Computes the absolute value of self. Returns NaN if the number is NaN.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(3.5);
let y = FpDouble::from(-3.5);

let abs_difference_x = (x.abs() - x).abs();
let abs_difference_y = (y.abs() - (-y)).abs();

assert!(abs_difference_x < FpDouble::from(1e-10));
assert!(abs_difference_y < FpDouble::from(1e-10));

assert!(FpDouble::nan().abs().is_nan());
source

pub fn signum(self) -> Self

Returns a number that represents the sign of self.

  • 1.0 if the number is positive, +0.0 or inf
  • -1.0 if the number is negative, -0.0 or -inf
  • NaN if the number is NaN
§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::from(3.5);

assert_eq!(f.signum(), FpDouble::one());
assert_eq!(FpDouble::neg_infinity().signum(), -FpDouble::one());

assert!(FpDouble::nan().signum().is_nan());
source

pub fn is_sign_positive(self) -> bool

Returns true if self has a positive sign, including +0.0, NaNs with positive sign bit and positive infinity. Note that IEEE 754 doesn’t assign any meaning to the sign bit in case of a NaN, and as Rust doesn’t guarantee that the bit pattern of NaNs are conserved over arithmetic operations, the result of is_sign_positive on a NaN might produce an unexpected result in some cases. See explanation of NaN as a special value for more info.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let nan = FpDouble::nan();
let neg_nan = -FpDouble::nan();

let f = FpDouble::from(7.0);
let g = FpDouble::from(-7.0);

assert!(f.is_sign_positive());
assert!(!g.is_sign_positive());
assert!(nan.is_sign_positive());
assert!(!neg_nan.is_sign_positive());
source

pub fn is_sign_negative(self) -> bool

Returns true if self has a negative sign, including -0.0, NaNs with negative sign bit and negative infinity. Note that IEEE 754 doesn’t assign any meaning to the sign bit in case of a NaN, and as Rust doesn’t guarantee that the bit pattern of NaNs are conserved over arithmetic operations, the result of is_sign_negative on a NaN might produce an unexpected result in some cases. See explanation of NaN as a special value for more info.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let nan = FpDouble::nan();
let neg_nan = -FpDouble::nan();

let f = FpDouble::from(7.0);
let g = FpDouble::from(-7.0);

assert!(!f.is_sign_negative());
assert!(g.is_sign_negative());
assert!(!nan.is_sign_negative());
assert!(neg_nan.is_sign_negative());
source

pub fn next_up(self) -> Self

Returns the least number greater than self.

Let TINY be the smallest representable positive value. Then,

  • if self.is_nan(), this returns self;
  • if self is NEG_INFINITY, this returns MIN;
  • if self is -TINY, this returns -0.0;
  • if self is -0.0 or +0.0, this returns TINY;
  • if self is MAX or INFINITY, this returns INFINITY;
  • otherwise the unique least value greater than self is returned.

The identity x.next_up() == -(-x).next_down() holds for all non-NaN x. When x is finite and the radix is 2, x == x.next_up().next_down() also holds.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;
 
// epsilon is the difference between 1.0 and the next number up.
assert_eq!(FpSingle::one().next_up(), FpSingle::one() + FpSingle::epsilon());
// But not for most numbers.
assert!(FpSingle::from(0.1).next_up() < FpSingle::from(0.1) + FpSingle::epsilon());
assert_eq!(FpSingle::from(16777216.0).next_up(), FpSingle::from(16777218.0));
source

pub fn next_down(self) -> Self

Returns the greatest number less than self.

Let TINY be the smallest representable positive value. Then,

  • if self.is_nan(), this returns self;
  • if self is INFINITY, this returns MAX;
  • if self is TINY, this returns 0.0;
  • if self is -0.0 or +0.0, this returns -TINY;
  • if self is MIN or NEG_INFINITY, this returns NEG_INFINITY;
  • otherwise the unique greatest value less than self is returned.

The identity x.next_down() == -(-x).next_up() holds for all non-NaN x. When x is finite x == x.next_down().next_up() also holds.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;

let x = FpSingle::one();
// Clamp value into range [0, 1).
let clamped = x.clamp(FpSingle::zero(), FpSingle::one().next_down());
assert!(clamped < FpSingle::one());
assert_eq!(clamped.next_up(), FpSingle::one());
source

pub fn maximum(self, other: Self) -> Self

Returns the maximum of the two numbers, propagating NaN.

This returns NaN when either argument is NaN, as opposed to Fp::max which only returns NaN when both arguments are NaN.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;
 
let x = FpSingle::from(1.0);
let y = FpSingle::from(2.0);

assert_eq!(x.maximum(y), y);
assert!(x.maximum(FpSingle::nan()).is_nan());

If one of the arguments is NaN, then NaN is returned. Otherwise this returns the greater of the two numbers. For this operation, -0.0 is considered to be less than +0.0. Note that this follows the semantics specified in IEEE 754-2019.

Also note that “propagation” of NaNs here doesn’t necessarily mean that the bitpattern of a NaN operand is conserved; see explanation of NaN as a special value for more info.

source

pub fn minimum(self, other: Self) -> Self

Returns the minimum of the two numbers, propagating NaN.

This returns NaN when either argument is NaN, as opposed to Fp::min which only returns NaN when both arguments are NaN.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;
 
let x = FpSingle::from(1.0);
let y = FpSingle::from(2.0);

assert_eq!(x.minimum(y), x);
assert!(x.minimum(FpSingle::nan()).is_nan());

If one of the arguments is NaN, then NaN is returned. Otherwise this returns the lesser of the two numbers. For this operation, -0.0 is considered to be less than +0.0. Note that this follows the semantics specified in IEEE 754-2019.

Also note that “propagation” of NaNs here doesn’t necessarily mean that the bitpattern of a NaN operand is conserved; see explanation of NaN as a special value for more info.

source

pub fn midpoint(self, other: Self) -> Self

Calculates the middle point of self and rhs.

This returns NaN when either argument is NaN or if a combination of +inf and -inf is provided as arguments.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;
 
assert_eq!(FpSingle::from(1.0).midpoint(FpSingle::from(4.0)), FpSingle::from(2.5));
assert_eq!(FpSingle::from(-5.5).midpoint(FpSingle::from(8.0)), FpSingle::from(1.25));
source

pub fn mul_add(self, a: Self, b: Self) -> Self

Fused multiply-add. Computes (self * a) + b.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let m = FpDouble::from(10.0);
let x = FpDouble::from(4.0);
let b = FpDouble::from(60.0);

// 100.0
let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn recip(self) -> Self

Take the reciprocal (inverse) of a number, 1/x.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(2.0);
let abs_difference = (x.recip() - (FpDouble::one()/x)).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn powi<I: Int>(self, n: I) -> Self

Raises a number to an integer power.

Using this function is generally faster than using powf. It might have a different sequence of rounding operations than powf, so the results are not guaranteed to agree.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(2.0);
let abs_difference = (x.powi(2) - x*x).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn powu<I: UInt>(self, n: I) -> Self

Raise a number to an unsigned integer power.

Using this function is generally faster than using powf. It might have a different sequence of rounding operations than powf, so the results are not guaranteed to agree.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(2.0);
let abs_difference = (x.powu(2u32) - x*x).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn powf(self, n: Self) -> Self

Raises a number to a floating point power.

This implementation is based on the Apple Libm-315 implementation of powf

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(2.0);
let abs_difference = (x.powf(FpDouble::from(2.0)) - x*x).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn sqrt(self) -> Self

Returns the square root of a number.

Returns NaN if self is a negative number other than -0.0.

This implementation is based on the fast sqrt described in: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Approximations_that_depend_on_the_floating_point_representation

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let positive = FpDouble::from(4.0);
let negative = FpDouble::from(-4.0);

let abs_difference = (positive.sqrt() - FpDouble::from(2.0)).abs();

assert!(abs_difference < FpDouble::from(1e-10));
assert!(negative.sqrt().is_nan());
source

pub fn expb(self) -> Self

Returns EXP_BASE^(self).

This implementation is roughly based on the exp2 implementation described here: https://stackoverflow.com/questions/65554112/fast-double-exp2-function-in-c.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::{FpDouble, DecDouble};

let f = FpDouble::from(2.0);
let d = DecDouble::from(2.0);

// 2^2 - 4 == 0
let abs_difference_f = (f.expb() - FpDouble::from(4.0)).abs();

// 10^2 - 100 == 0
let abs_difference_d = (d.expb() - DecDouble::from(100.0)).abs();

assert!(abs_difference_f < FpDouble::from(1e-10));
assert!(abs_difference_d < DecDouble::from(1e-10));
source

pub fn exp(self) -> Self

Returns e^(self), (the exponential function).

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let one = FpDouble::one();
// e^1
let e = one.exp();
 
// ln(e) - 1 == 0
let abs_difference = (e.ln() - FpDouble::one()).abs();

assert!(abs_difference < FpDouble::from(1e-9));
source

pub fn exp10(self) -> Self

Returns 10^(self).

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::from(2.0);

// 10^2 - 100 == 0
let abs_difference = (f.exp10() - FpDouble::from(100.0)).abs();

assert!(abs_difference < FpDouble::from(1e-6));
source

pub fn exp2(self) -> Self

Returns 2^(self).

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::from(2.0);

// 2^2 - 4 == 0
let abs_difference = (f.exp2() - FpDouble::from(4.0)).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn ln(self) -> Self

Returns the natural logarithm of the number.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let one = FpDouble::one();
// e^1
let e = one.exp();
 
// ln(e) - 1 == 0
let abs_difference = (e.ln() - FpDouble::one()).abs();

assert!(abs_difference < FpDouble::from(1e-9));
source

pub fn log(self, base: Self) -> Self

Returns the logarithm of the number with respect to an arbitrary base.

The result might not be correctly rounded owing to implementation details; self.log2() can produce more accurate results for base 2, and self.log10() can produce more accurate results for base 10.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let ten = FpDouble::from(10.0);
let two = FpDouble::from(2.0);

// log10(10) - 1 == 0
let abs_difference_10 = (ten.log(FpDouble::from(10.0)) - FpDouble::one()).abs();

// log2(2) - 1 == 0
let abs_difference_2 = (two.log(FpDouble::from(2.0)) - FpDouble::one()).abs();

assert!(abs_difference_10 < FpDouble::from(1e-10));
assert!(abs_difference_2 < FpDouble::from(1e-10));
source

pub fn logb(self) -> Self

Returns the logarithm base EXP_BASE of the number.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::{FpDouble, DecDouble};

let two = FpDouble::from(2.0);
let ten = DecDouble::from(10.0);

// log2(2) - 1 == 0
let abs_difference_2 = (two.logb() - FpDouble::one()).abs();
 
// log10(10) - 1 == 0
let abs_difference_10 = (ten.logb() - DecDouble::one()).abs();

assert!(abs_difference_2 < FpDouble::from(1e-10));
assert!(abs_difference_10 < DecDouble::from(1e-10));
source

pub fn log2(self) -> Self

Returns the base 2 logarithm of the number.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let two = FpDouble::from(2.0);

// log2(2) - 1 == 0
let abs_difference = (two.log2() - FpDouble::one()).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn log10(self) -> Self

Returns the base 10 logarithm of the number.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let ten = FpDouble::from(10.0);

// log10(10) - 1 == 0
let abs_difference = (ten.log10() - FpDouble::one()).abs();

assert!(abs_difference < FpDouble::from(1e-4));
source

pub fn to_degrees(self) -> Self

Converts radians to degrees.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let angle = FpDouble::PI();

let abs_difference = (angle.to_degrees() - FpDouble::from(180.0)).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn to_radians(self) -> Self

Converts degrees to radians.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let angle = FpDouble::from(180.0);

let abs_difference = (angle.to_radians() - FpDouble::PI()).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn max(self, other: Self) -> Self

Returns the maximum of the two numbers.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(1.0);
let y = FpDouble::from(2.0);

assert_eq!(x.max(y), y);
source

pub fn min(self, other: Self) -> Self

Returns the minimum of the two numbers.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(1.0);
let y = FpDouble::from(2.0);

assert_eq!(x.min(y), x);
source

pub fn abs_sub(self, other: Self) -> Self

👎Deprecated: you probably meant (self - other).abs(): this operation is (self - other).max(0.0) except that abs_sub also propagates NaNs (also known as fdimf in C). If you truly need the positive difference, consider using that expression or the C function fdimf, depending on how you wish to handle NaN (please consider filing an issue describing your use-case too).

The positive difference of two numbers.

  • If self <= other: 0:0
  • Else: self - other
§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(3.0);
let y = FpDouble::from(-3.0);

let abs_difference_x = (x.abs_sub(FpDouble::one()) - FpDouble::from(2.0)).abs();
let abs_difference_y = (y.abs_sub(FpDouble::one()) - FpDouble::zero()).abs();

assert!(abs_difference_x < FpDouble::from(1e-10));
assert!(abs_difference_y < FpDouble::from(1e-10));
source

pub fn cbrt(self) -> Self

Take the cubic root of a number.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(8.0);

// x^(1/3) - 2 == 0
let abs_difference = (x.cbrt() - FpDouble::from(2.0)).abs();

assert!(abs_difference < FpDouble::from(1e-9));
source

pub fn hypot(self, other: Self) -> Self

Compute the distance between the origin and a point (x, y) on the Euclidean plane. Equivalently, compute the length of the hypotenuse of a right-angle triangle with other sides having length x.abs() and y.abs().

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(2.0);
let y = FpDouble::from(3.0);

// sqrt(x^2 + y^2)
let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn sin(self) -> Self

Computes the sine of a number (in radians).

This implementation is based on Harvey M. Wagner’s Polynomial approximations to elementary functions.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let x = FpDouble::FRAC_PI_2();

let abs_difference = (x.sin() - FpDouble::one()).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn cos(self) -> Self

Computes the cosine of a number (in radians).

This implementation is based on Harvey M. Wagner’s Polynomial approximations to elementary functions.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let x = FpDouble::TAU();

let abs_difference = (x.cos() - FpDouble::one()).abs();

assert!(abs_difference < FpDouble::from(1e-10));
source

pub fn tan(self) -> Self

Computes the tangent of a number (in radians).

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let x = FpDouble::FRAC_PI_4();
 
let abs_difference = (x.tan() - FpDouble::one()).abs();

assert!(abs_difference < FpDouble::from(1e-9));
source

pub fn asin(self) -> Self

Computes the arcsine of a number. Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1].

This implementation is based on Harvey M. Wagner’s Polynomial approximations to elementary functions.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let f = FpDouble::FRAC_PI_2();

// asin(sin(pi/2))
let abs_difference = (f.sin().asin() - f).abs();

assert!(abs_difference < FpDouble::from(1e-4));
source

pub fn acos(self) -> Self

Computes the arccosine of a number. Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1].

This implementation is based on Harvey M. Wagner’s Polynomial approximations to elementary functions.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let f = FpDouble::FRAC_PI_4();

// acos(cos(pi/4))
let abs_difference = (f.cos().acos() - f).abs();

assert!(abs_difference < FpDouble::from(1e-9));
source

pub fn atan(self) -> Self

Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2];

This implementation is based on Harvey M. Wagner’s Polynomial approximations to elementary functions.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::one();

// atan(tan(1))
let abs_difference = (f.tan().atan() - f).abs();

assert!(abs_difference < FpDouble::from(1e-5));
source

pub fn atan2(self, other: Self) -> Self

Computes the four quadrant arctangent of self (y) and other (x).

  • x = 0, y = 0: 0
  • x >= 0: arctan(y/x) -> [-pi/2, pi/2]
  • y >= 0: arctan(y/x) + pi -> (pi/2, pi]
  • y < 0: arctan(y/x) - pi -> (-pi, -pi/2)
§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

// All angles from horizontal right (+x)
// 45 deg counter-clockwise
let x1 = FpDouble::from(3.0);
let y1 = FpDouble::from(-3.0);

// 135 deg clockwise
let x2 = FpDouble::from(-3.0);
let y2 = FpDouble::from(3.0);

let abs_difference_1 = (y1.atan2(x1) - (-FpDouble::FRAC_PI_4())).abs();
let abs_difference_2 = (y2.atan2(x2) - (FpDouble::PI() - FpDouble::FRAC_PI_4())).abs();

assert!(abs_difference_1 < FpDouble::from(1e-5));
assert!(abs_difference_2 < FpDouble::from(1e-5));
source

pub fn sin_cos(self) -> (Self, Self)

Simultaneously computes the sine and cosine of the number, x. Returns (sin(x), cos(x)).

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let x = FpDouble::FRAC_PI_4();
let f = x.sin_cos();

let abs_difference_0 = (f.0 - x.sin()).abs();
let abs_difference_1 = (f.1 - x.cos()).abs();

assert!(abs_difference_0 < FpDouble::from(1e-10));
assert!(abs_difference_1 < FpDouble::from(1e-10));
source

pub fn exp_m1(self) -> Self

Returns e^(self) - 1.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::from(7.0);

// e^(ln(7)) - 1
let abs_difference = (x.ln().exp_m1() - FpDouble::from(6.0)).abs();

assert!(abs_difference < FpDouble::from(1e-8));
source

pub fn ln_1p(self) -> Self

Returns ln(1+n) (natural logarithm) more accurately than if the operations were performed separately.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let x = FpDouble::E() - FpDouble::one();

// ln(1 + (e - 1)) == ln(e) == 1
let abs_difference = (x.ln_1p() - FpDouble::one()).abs();

assert!(abs_difference < FpDouble::from(1e-9));
source

pub fn sinh(self) -> Self

Hyperbolic sine function.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let e = FpDouble::E();
let x = FpDouble::one();

let f = x.sinh();
// Solving sinh() at 1 gives `(e^2-1)/(2e)`
let g = (e*e - FpDouble::one())/(FpDouble::from(2.0)*e);
let abs_difference = (f - g).abs();

assert!(abs_difference < FpDouble::from(1e-3));
source

pub fn cosh(self) -> Self

Hyperbolic cosine function.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let e = FpDouble::E();
let x = FpDouble::one();
 
let f = x.cosh();
// Solving cosh() at 1 gives this result
let g = (e*e + FpDouble::one())/(FpDouble::from(2.0)*e);
let abs_difference = (f - g).abs();

// Same result
assert!(abs_difference < FpDouble::from(1.0e-3));
source

pub fn tanh(self) -> Self

Hyperbolic tangent function.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let e = FpDouble::E();
let x = FpDouble::one();

let f = x.tanh();
// Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))`
let g = (FpDouble::one() - e.powi(-2))/(FpDouble::one() + e.powi(-2));
let abs_difference = (f - g).abs();

assert!(abs_difference < FpDouble::from(1.0e-3));
source

pub fn asinh(self) -> Self

Inverse hyperbolic sine function.

This implementation is based on the glibc implementation of asinhf.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::one();
let f = x.sinh().asinh();

let abs_difference = (f - x).abs();

assert!(abs_difference < FpDouble::from(1.0e-3));
source

pub fn acosh(self) -> Self

Inverse hyperbolic cosine function.

This implementation is based on the glibc implementation of acoshf.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let x = FpDouble::one();
let f = x.cosh().acosh();

let abs_difference = (f - x).abs();

assert!(abs_difference < FpDouble::from(1.0e-3));
source

pub fn atanh(self) -> Self

Inverse hyperbolic tangent function.

This implementation is based on the glibc implementation of atanhf.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
use num::traits::FloatConst;

let e = FpDouble::E();
let f = e.tanh().atanh();

let abs_difference = (f - e).abs();

assert!(abs_difference < FpDouble::from(1.0e-2));
source

pub fn ln_gamma(self) -> (Self, i32)

Natural logarithm of the absolute value of the gamma function

The integer part of the tuple indicates the sign of the gamma function.

This implementation is based on the libstdc++ implementation of the gamma function.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
 
let x = FpDouble::from(2.0);

let abs_difference = (x.ln_gamma().0 - FpDouble::zero()).abs();

assert!(abs_difference <= FpDouble::from(1e-2));
source

pub fn gamma(self) -> Self

Gamma function.

This implementation is based on the libstdc++ implementation of the gamma function.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
 
let x = FpDouble::from(5.0f32);

let abs_difference = (x.gamma() - FpDouble::from(24.0)).abs();

assert!(abs_difference <= FpDouble::from(1e-1));
source

pub fn copysign(self, sign: Self) -> Self

Returns a number composed of the magnitude of self and the sign of sign.

Equal to self if the sign of self and sign are the same, otherwise equal to -self. If self is a NaN, then a NaN with the sign bit of sign is returned. Note, however, that conserving the sign bit on NaN across arithmetical operations is not generally guaranteed.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;

let f = FpDouble::from(3.5);
let s = FpDouble::from(0.42);

assert_eq!(f.copysign(s), f);
assert_eq!(f.copysign(-s), -f);
assert_eq!((-f).copysign(s), f);
assert_eq!((-f).copysign(-s), -f);

assert!(FpDouble::nan().copysign(FpDouble::one()).is_nan());
source

pub fn zero() -> Self

Returns the additive identity element of Self, 0.

source

pub fn is_zero(self) -> bool

Returns true if self is equal to the additive identity.

source

pub fn one() -> Self

Returns the multiplicative identity element of Self, 1.

source

pub fn is_one(self) -> bool

Returns true if self is equal to the multiplicative identity.

source

pub fn div_euclid(self, rhs: Self) -> Self

Calculates Euclidean division, the matching method for rem_euclid.

This computes the integer n such that self = n * rhs + self.rem_euclid(rhs). In other words, the result is self / rhs rounded to the integer n such that self >= n * rhs.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
 
let a = FpDouble::from(7.0);
let b = FpDouble::from(4.0);
assert_eq!(a.div_euclid(b), FpDouble::from(1.0)); // 7.0 > 4.0 * 1.0
assert_eq!((-a).div_euclid(b), FpDouble::from(-2.0)); // -7.0 >= 4.0 * -2.0
assert_eq!(a.div_euclid(-b), FpDouble::from(-1.0)); // 7.0 >= -4.0 * -1.0
assert_eq!((-a).div_euclid(-b), FpDouble::from(2.0)); // -7.0 >= -4.0 * 2.0
source

pub fn rem_euclid(self, rhs: Self) -> Self

Calculates the least nonnegative remainder of self (mod rhs).

In particular, the return value r satisfies 0.0 <= r < rhs.abs() in most cases. However, due to a floating point round-off error it can result in r == rhs.abs(), violating the mathematical definition, if self is much smaller than rhs.abs() in magnitude and self < 0.0. This result is not an element of the function’s codomain, but it is the closest floating point number in the real numbers and thus fulfills the property self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs) approximately.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpDouble;
 
let a = FpDouble::from(7.0);
let b = FpDouble::from(4.0);
assert_eq!(a.rem_euclid(b), FpDouble::from(3.0));
assert_eq!((-a).rem_euclid(b), FpDouble::from(1.0));
assert_eq!(a.rem_euclid(-b), FpDouble::from(3.0));
assert_eq!((-a).rem_euclid(-b), FpDouble::from(1.0));
// limitation due to round-off error
assert!((-FpDouble::epsilon()).rem_euclid(FpDouble::from(3.0)) != FpDouble::from(0.0));
source

pub fn total_cmp(self, other: Self) -> Ordering

Return the ordering between self and other.

Unlike the standard partial comparison between floating point numbers, this comparison always produces an ordering in accordance to the totalOrder predicate as defined in the IEEE 754 (2008 revision) floating point standard. The values are ordered in the following sequence:

  • negative quiet NaN
  • negative signaling NaN
  • negative infinity
  • negative numbers
  • negative subnormal numbers
  • negative zero
  • positive zero
  • positive subnormal numbers
  • positive numbers
  • positive infinity
  • positive signaling NaN
  • positive quiet NaN.

The ordering established by this function does not always agree with the PartialOrd and PartialEq implementations. For example, they consider negative and positive zero equal, while total_cmp doesn’t.

The interpretation of the signaling NaN bit follows the definition in the IEEE 754 standard, which may not match the interpretation by some of the older, non-conformant (e.g. MIPS) hardware implementations.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::{FpSingle, FpDouble};
use std::cmp::Ordering;

assert_eq!(FpDouble::nan().total_cmp(FpDouble::nan()), Ordering::Equal);
assert_eq!(FpSingle::nan().total_cmp(FpSingle::nan()), Ordering::Equal);

assert_eq!((-FpDouble::nan()).total_cmp(FpDouble::nan()), Ordering::Less);
assert_eq!(FpDouble::infinity().total_cmp(FpDouble::nan()), Ordering::Less);
assert_eq!((-FpDouble::zero()).total_cmp(FpDouble::zero()), Ordering::Less);
source

pub fn mulb(self) -> Self

Returns self*EXP_BASE.

This is generally faster than using regular multiplication.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::{FpDouble, DecDouble};

let f = FpDouble::from(2.0);
let d = DecDouble::from(2.0);

// 2*2 - 4 == 0
let abs_difference_f = (f.mulb() - FpDouble::from(4.0)).abs();

// 2*10 - 20 == 0
let abs_difference_d = (d.mulb() - DecDouble::from(20.0)).abs();

assert!(abs_difference_f < FpDouble::from(1e-10));
assert!(abs_difference_d < DecDouble::from(1e-10));
source

pub fn divb(self) -> Self

Returns self/EXP_BASE.

This is generally faster than using regular division.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::{FpDouble, DecDouble};

let f = FpDouble::from(2.0);
let d = DecDouble::from(2.0);

// 2/2 - 1 == 0
let abs_difference_f = (f.divb() - FpDouble::from(1.0)).abs();

// 2/10 - 0.2 == 0
let abs_difference_d = (d.divb() - DecDouble::from(0.2)).abs();

assert!(abs_difference_f < FpDouble::from(1e-10));
assert!(abs_difference_d < DecDouble::from(1e-10));
source

pub fn clamp(self, min: Self, max: Self) -> Self

Restrict a value to a certain interval unless it is NaN.

Returns max if self is greater than max, and min if self is less than min. Otherwise this returns self.

Note that this function returns NaN if the initial value was NaN as well.

§Panics

Panics if min > max, min is NaN, or max is NaN.

§Examples
#![feature(generic_const_exprs)]
 
use custom_float::ieee754::FpSingle;

let min = FpSingle::from(-2.0);
let max = FpSingle::one();

assert_eq!(FpSingle::from(-3.0).clamp(min, max), FpSingle::from(-2.0));
assert_eq!(FpSingle::zero().clamp(min, max), FpSingle::zero());
assert_eq!(FpSingle::from(2.0).clamp(min, max), FpSingle::one());
assert!(FpSingle::nan().clamp(min, max).is_nan());
source

pub fn erf(self) -> Self

Error function (f64)

Calculates an approximation to the “error function”, which estimates the probability that an observation will fall within x standard deviations of the mean (assuming a normal distribution)

source

pub fn erfc(self) -> Self

Complementary error function

Calculates the complementary probability. Is 1 - erf(x). Is computed directly, so that you can use it to avoid the loss of precision that would result from subtracting large probabilities (on large x) from 1.

source

pub fn j0(self) -> Self

Bessel function of the first kind with α = 0.

source

pub fn y0(self) -> Self

Bessel function of the second kind with α = 0.

source

pub fn j1(self) -> Self

Bessel function of the first kind with α = 1.

source

pub fn y1(self) -> Self

Bessel function of the second kind with α = 1.

source

pub fn jn(self, n: i32) -> Self

Bessel function of the first kind with α = n.

source

pub fn yn(self, n: i32) -> Self

Bessel function of the second kind with α = n.

source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:, U: ConstZero + UInt,

source

pub const ZERO: Self = _

The additive identity element of Self, 0.

Trait Implementations§

source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Add for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AddAssign for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<f32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> f32

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<f64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> f64

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<i128> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> i128

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<i16> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> i16

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<i32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> i32

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<i64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> i64

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<i8> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> i8

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<isize> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> isize

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<u128> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> u128

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<u16> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> u16

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<u32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> u32

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<u64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> u64

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<u8> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> u8

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> AsPrimitive<usize> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn as_(self) -> usize

Convert a value to another, using the as operator.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Binary for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: Binary + UInt, [(); { _ }]:,

source§

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

Formats the value using the given formatter.
source§

impl<U: Clone + UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Clone for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn clone(&self) -> Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

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<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> ConstZero for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:, U: ConstZero + UInt,

source§

const ZERO: Self = Self::ZERO

The additive identity element of Self, 0.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Debug for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

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

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

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Default for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn default() -> Self

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

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Display for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

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

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

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Div for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> DivAssign for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Euclid for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn div_euclid(&self, rhs: &Self) -> Self

Calculates Euclidean division, the matching method for rem_euclid. Read more
source§

fn rem_euclid(&self, rhs: &Self) -> Self

Calculates the least nonnegative remainder of self (mod v). Read more
source§

fn div_rem_euclid(&self, v: &Self) -> (Self, Self)

Returns both the quotient and remainder from Euclidean division. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Float for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn nan() -> Self

Returns the NaN value. Read more
source§

fn infinity() -> Self

Returns the infinite value. Read more
source§

fn neg_infinity() -> Self

Returns the negative infinite value. Read more
source§

fn neg_zero() -> Self

Returns -0.0. Read more
source§

fn min_value() -> Self

Returns the smallest finite value that this type can represent. Read more
source§

fn min_positive_value() -> Self

Returns the smallest positive, normalized value that this type can represent. Read more
source§

fn max_value() -> Self

Returns the largest finite value that this type can represent. Read more
source§

fn is_nan(self) -> bool

Returns true if this value is NaN and false otherwise. Read more
source§

fn is_infinite(self) -> bool

Returns true if this value is positive infinity or negative infinity and false otherwise. Read more
source§

fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN. Read more
source§

fn is_normal(self) -> bool

Returns true if the number is neither zero, infinite, subnormal, or NaN. Read more
source§

fn classify(self) -> FpCategory

Returns the floating point category of the number. If only one property is going to be tested, it is generally faster to use the specific predicate instead. Read more
source§

fn floor(self) -> Self

Returns the largest integer less than or equal to a number. Read more
source§

fn ceil(self) -> Self

Returns the smallest integer greater than or equal to a number. Read more
source§

fn round(self) -> Self

Returns the nearest integer to a number. Round half-way cases away from 0.0. Read more
source§

fn trunc(self) -> Self

Return the integer part of a number. Read more
source§

fn fract(self) -> Self

Returns the fractional part of a number. Read more
source§

fn abs(self) -> Self

Computes the absolute value of self. Returns Float::nan() if the number is Float::nan(). Read more
source§

fn signum(self) -> Self

Returns a number that represents the sign of self. Read more
source§

fn is_sign_positive(self) -> bool

Returns true if self is positive, including +0.0, Float::infinity(), and Float::nan(). Read more
source§

fn is_sign_negative(self) -> bool

Returns true if self is negative, including -0.0, Float::neg_infinity(), and -Float::nan(). Read more
source§

fn mul_add(self, a: Self, b: Self) -> Self

Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add. Read more
source§

fn recip(self) -> Self

Take the reciprocal (inverse) of a number, 1/x. Read more
source§

fn powi(self, n: i32) -> Self

Raise a number to an integer power. Read more
source§

fn powf(self, n: Self) -> Self

Raise a number to a floating point power. Read more
source§

fn sqrt(self) -> Self

Take the square root of a number. Read more
source§

fn exp(self) -> Self

Returns e^(self), (the exponential function). Read more
source§

fn exp2(self) -> Self

Returns 2^(self). Read more
source§

fn ln(self) -> Self

Returns the natural logarithm of the number. Read more
source§

fn log(self, base: Self) -> Self

Returns the logarithm of the number with respect to an arbitrary base. Read more
source§

fn log2(self) -> Self

Returns the base 2 logarithm of the number. Read more
source§

fn log10(self) -> Self

Returns the base 10 logarithm of the number. Read more
source§

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

Returns the maximum of the two numbers. Read more
source§

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

Returns the minimum of the two numbers. Read more
source§

fn abs_sub(self, other: Self) -> Self

The positive difference of two numbers. Read more
source§

fn cbrt(self) -> Self

Take the cubic root of a number. Read more
source§

fn hypot(self, other: Self) -> Self

Calculate the length of the hypotenuse of a right-angle triangle given legs of length x and y. Read more
source§

fn sin(self) -> Self

Computes the sine of a number (in radians). Read more
source§

fn cos(self) -> Self

Computes the cosine of a number (in radians). Read more
source§

fn tan(self) -> Self

Computes the tangent of a number (in radians). Read more
source§

fn asin(self) -> Self

Computes the arcsine of a number. Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1]. Read more
source§

fn acos(self) -> Self

Computes the arccosine of a number. Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1]. Read more
source§

fn atan(self) -> Self

Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2]; Read more
source§

fn atan2(self, other: Self) -> Self

Computes the four quadrant arctangent of self (y) and other (x). Read more
source§

fn sin_cos(self) -> (Self, Self)

Simultaneously computes the sine and cosine of the number, x. Returns (sin(x), cos(x)). Read more
source§

fn exp_m1(self) -> Self

Returns e^(self) - 1 in a way that is accurate even if the number is close to zero. Read more
source§

fn ln_1p(self) -> Self

Returns ln(1+n) (natural logarithm) more accurately than if the operations were performed separately. Read more
source§

fn sinh(self) -> Self

Hyperbolic sine function. Read more
source§

fn cosh(self) -> Self

Hyperbolic cosine function. Read more
source§

fn tanh(self) -> Self

Hyperbolic tangent function. Read more
source§

fn asinh(self) -> Self

Inverse hyperbolic sine function. Read more
source§

fn acosh(self) -> Self

Inverse hyperbolic cosine function. Read more
source§

fn atanh(self) -> Self

Inverse hyperbolic tangent function. Read more
source§

fn integer_decode(self) -> (u64, i16, i8)

Returns the mantissa, base 2 exponent, and sign as integers, respectively. The original number can be recovered by sign * mantissa * 2 ^ exponent. Read more
source§

fn epsilon() -> Self

Returns epsilon, a small positive value. Read more
source§

fn copysign(self, sign: Self) -> Self

Returns a number composed of the magnitude of self and the sign of sign. Read more
source§

fn is_subnormal(self) -> bool

Returns true if the number is subnormal. Read more
source§

fn to_degrees(self) -> Self

Converts radians to degrees. Read more
source§

fn to_radians(self) -> Self

Converts degrees to radians. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> FloatConst for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn E() -> Self

Return Euler’s number.

source§

fn FRAC_1_PI() -> Self

Return 1.0 / π.

source§

fn FRAC_1_SQRT_2() -> Self

Return 1.0 / sqrt(2.0).

source§

fn FRAC_2_PI() -> Self

Return 2.0 / π.

source§

fn FRAC_2_SQRT_PI() -> Self

Return 2.0 / sqrt(π).

source§

fn FRAC_PI_2() -> Self

Return π / 2.0.

source§

fn FRAC_PI_3() -> Self

Return π / 3.0.

source§

fn FRAC_PI_4() -> Self

Return π / 4.0.

source§

fn FRAC_PI_6() -> Self

Return π / 6.0.

source§

fn FRAC_PI_8() -> Self

Return π / 8.0.

source§

fn LN_10() -> Self

Return ln(10.0).

source§

fn LN_2() -> Self

Return ln(2.0).

source§

fn LOG10_E() -> Self

Return log10(e).

source§

fn LOG2_E() -> Self

Return log2(e).

source§

fn PI() -> Self

Return Archimedes’ constant π.

source§

fn SQRT_2() -> Self

Return sqrt(2.0).

source§

fn TAU() -> Self
where Self: Sized + Add<Output = Self>,

Return the full circle constant τ.
source§

fn LOG10_2() -> Self
where Self: Sized + Div<Output = Self>,

Return log10(2.0).
source§

fn LOG2_10() -> Self
where Self: Sized + Div<Output = Self>,

Return log2(10.0).
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> FloatCore for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn infinity() -> Self

Returns positive infinity. Read more
source§

fn neg_infinity() -> Self

Returns negative infinity. Read more
source§

fn nan() -> Self

Returns NaN. Read more
source§

fn neg_zero() -> Self

Returns -0.0. Read more
source§

fn min_value() -> Self

Returns the smallest finite value that this type can represent. Read more
source§

fn min_positive_value() -> Self

Returns the smallest positive, normalized value that this type can represent. Read more
source§

fn epsilon() -> Self

Returns epsilon, a small positive value. Read more
source§

fn max_value() -> Self

Returns the largest finite value that this type can represent. Read more
source§

fn classify(self) -> FpCategory

Returns the floating point category of the number. If only one property is going to be tested, it is generally faster to use the specific predicate instead. Read more
source§

fn to_degrees(self) -> Self

Converts to degrees, assuming the number is in radians. Read more
source§

fn to_radians(self) -> Self

Converts to radians, assuming the number is in degrees. Read more
source§

fn integer_decode(self) -> (u64, i16, i8)

Returns the mantissa, base 2 exponent, and sign as integers, respectively. The original number can be recovered by sign * mantissa * 2 ^ exponent. Read more
source§

fn is_nan(self) -> bool

Returns true if the number is NaN. Read more
source§

fn is_infinite(self) -> bool

Returns true if the number is infinite. Read more
source§

fn is_finite(self) -> bool

Returns true if the number is neither infinite or NaN. Read more
source§

fn is_normal(self) -> bool

Returns true if the number is neither zero, infinite, subnormal or NaN. Read more
source§

fn is_subnormal(self) -> bool

Returns true if the number is subnormal. Read more
source§

fn floor(self) -> Self

Returns the largest integer less than or equal to a number. Read more
source§

fn ceil(self) -> Self

Returns the smallest integer greater than or equal to a number. Read more
source§

fn round(self) -> Self

Returns the nearest integer to a number. Round half-way cases away from 0.0. Read more
source§

fn trunc(self) -> Self

Return the integer part of a number. Read more
source§

fn fract(self) -> Self

Returns the fractional part of a number. Read more
source§

fn abs(self) -> Self

Computes the absolute value of self. Returns FloatCore::nan() if the number is FloatCore::nan(). Read more
source§

fn signum(self) -> Self

Returns a number that represents the sign of self. Read more
source§

fn is_sign_positive(self) -> bool

Returns true if self is positive, including +0.0 and FloatCore::infinity(), and FloatCore::nan(). Read more
source§

fn is_sign_negative(self) -> bool

Returns true if self is negative, including -0.0 and FloatCore::neg_infinity(), and -FloatCore::nan(). Read more
source§

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

Returns the minimum of the two numbers. Read more
source§

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

Returns the maximum of the two numbers. Read more
source§

fn recip(self) -> Self

Returns the reciprocal (multiplicative inverse) of the number. Read more
source§

fn powi(self, exp: i32) -> Self

Raise a number to an integer power. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<f32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(f: f32) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<f64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(f: f64) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<i128> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: i128) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<i16> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: i16) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<i32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: i32) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<i64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: i64) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<i8> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: i8) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<isize> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: isize) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<u128> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: u128) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<u16> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: u16) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<u32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: u32) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<u64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: u64) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<u8> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: u8) -> Self

Converts to this type from the input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> From<usize> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from(n: usize) -> Self

Converts to this type from the input type.
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> FromBytes for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:, U: FromBytes + UInt,

§

type Bytes = <U as FromBytes>::Bytes

source§

fn from_be_bytes(bytes: &Self::Bytes) -> Self

Create a number from its representation as a byte array in big endian. Read more
source§

fn from_le_bytes(bytes: &Self::Bytes) -> Self

Create a number from its representation as a byte array in little endian. Read more
source§

fn from_ne_bytes(bytes: &Self::Bytes) -> Self

Create a number from its memory representation as a byte array in native endianness. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> FromPrimitive for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from_isize(n: isize) -> Option<Self>

Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_i8(n: i8) -> Option<Self>

Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_i16(n: i16) -> Option<Self>

Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_i32(n: i32) -> Option<Self>

Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_i64(n: i64) -> Option<Self>

Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_i128(n: i128) -> Option<Self>

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

fn from_usize(n: usize) -> Option<Self>

Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u8(n: u8) -> Option<Self>

Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u16(n: u16) -> Option<Self>

Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u32(n: u32) -> Option<Self>

Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u64(n: u64) -> Option<Self>

Converts an u64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_u128(n: u128) -> Option<Self>

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

fn from_f32(n: f32) -> Option<Self>

Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
source§

fn from_f64(n: f64) -> Option<Self>

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

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Into<f32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn into(self) -> f32

Converts this type into the (usually inferred) input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Into<f64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn into(self) -> f64

Converts this type into the (usually inferred) input type.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Inv for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn inv(self) -> Self::Output

Returns the multiplicative inverse of self. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> LowerExp for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

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

Formats the value using the given formatter.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Mul for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> MulAdd for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The resulting type after applying the fused multiply-add.
source§

fn mul_add(self, a: Self, b: Self) -> Self::Output

Performs the fused multiply-add operation (self * a) + b
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> MulAddAssign for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn mul_add_assign(&mut self, a: Self, b: Self)

Performs the fused multiply-add assignment operation *self = (*self * a) + b
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> MulAssign for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Neg for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Num for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type FromStrRadixErr = ParseFloatError

source§

fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>

Convert from a string and radix (typically 2..=36). Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> NumCast for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn from<T: ToPrimitive>(n: T) -> Option<Self>

Creates a number from another value that can be converted into a primitive via the ToPrimitive trait. If the source value cannot be represented by the target type, then None is returned. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> One for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> PartialEq for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

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<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> PartialOrd for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

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<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

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

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<i128> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: i128) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<i16> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: i16) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<i32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: i32) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<i64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: i64) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<i8> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: i8) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<isize> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

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

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<u128> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: u128) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<u16> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: u16) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<u32> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: u32) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<u64> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: u64) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<u8> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: u8) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Pow<usize> for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The result after applying the operator.
source§

fn pow(self, rhs: usize) -> Self::Output

Returns self to the power rhs. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Rem for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The resulting type after applying the % operator.
source§

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

Performs the % operation. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> RemAssign for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Signed for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: 'static + UInt, [(); { _ }]:,

source§

fn abs(&self) -> Self

Computes the absolute value. Read more
source§

fn abs_sub(&self, other: &Self) -> Self

The positive difference of two numbers. Read more
source§

fn signum(&self) -> Self

Returns the sign of the number. Read more
source§

fn is_positive(&self) -> bool

Returns true if the number is positive and false if the number is zero or negative.
source§

fn is_negative(&self) -> bool

Returns true if the number is negative and false if the number is zero or positive.
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Sub for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

§

type Output = Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> SubAssign for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> ToBytes for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:, U: ToBytes + UInt,

§

type Bytes = <U as ToBytes>::Bytes

source§

fn to_be_bytes(&self) -> Self::Bytes

Return the memory representation of this number as a byte array in big-endian byte order. Read more
source§

fn to_le_bytes(&self) -> Self::Bytes

Return the memory representation of this number as a byte array in little-endian byte order. Read more
source§

fn to_ne_bytes(&self) -> Self::Bytes

Return the memory representation of this number as a byte array in native byte order. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> ToPrimitive for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn to_i8(&self) -> Option<i8>

Converts the value of self to an i8. If the value cannot be represented by an i8, then None is returned.
source§

fn to_u8(&self) -> Option<u8>

Converts the value of self to a u8. If the value cannot be represented by a u8, then None is returned.
source§

fn to_i16(&self) -> Option<i16>

Converts the value of self to an i16. If the value cannot be represented by an i16, then None is returned.
source§

fn to_u16(&self) -> Option<u16>

Converts the value of self to a u16. If the value cannot be represented by a u16, then None is returned.
source§

fn to_i32(&self) -> Option<i32>

Converts the value of self to an i32. If the value cannot be represented by an i32, then None is returned.
source§

fn to_u32(&self) -> Option<u32>

Converts the value of self to a u32. If the value cannot be represented by a u32, then None is returned.
source§

fn to_isize(&self) -> Option<isize>

Converts the value of self to an isize. If the value cannot be represented by an isize, then None is returned.
source§

fn to_usize(&self) -> Option<usize>

Converts the value of self to a usize. If the value cannot be represented by a usize, then None is returned.
source§

fn to_i64(&self) -> Option<i64>

Converts the value of self to an i64. If the value cannot be represented by an i64, then None is returned.
source§

fn to_u64(&self) -> Option<u64>

Converts the value of self to a u64. If the value cannot be represented by a u64, then None is returned.
source§

fn to_i128(&self) -> Option<i128>

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

fn to_u128(&self) -> Option<u128>

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

fn to_f32(&self) -> Option<f32>

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

fn to_f64(&self) -> Option<f64>

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

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> TotalOrder for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

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

Return the ordering between self and other. Read more
source§

impl<U: UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Zero for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

impl<U: Copy + UInt, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Copy for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where [(); { _ }]:,

Auto Trait Implementations§

§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> RefUnwindSafe for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: RefUnwindSafe,

§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Send for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: Send,

§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Sync for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: Sync,

§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> Unpin for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: Unpin,

§

impl<U, const SIGN_BIT: bool, const EXP_SIZE: usize, const INT_SIZE: usize, const FRAC_SIZE: usize, const EXP_BASE: usize> UnwindSafe for Fp<U, SIGN_BIT, EXP_SIZE, INT_SIZE, FRAC_SIZE, EXP_BASE>
where U: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> ComplexFloat for T
where T: Float + FloatConst,

§

type Real = T

The type used to represent the real coefficients of this complex number.
source§

fn re(self) -> <T as ComplexFloat>::Real

Returns the real part of the number.
source§

fn im(self) -> <T as ComplexFloat>::Real

Returns the imaginary part of the number.
source§

fn l1_norm(&self) -> <T as ComplexFloat>::Real

Returns the L1 norm |re| + |im| – the Manhattan distance from the origin.
source§

fn arg(self) -> <T as ComplexFloat>::Real

Computes the argument of the number.
source§

fn powc( self, exp: Complex<<T as ComplexFloat>::Real> ) -> Complex<<T as ComplexFloat>::Real>

Raises self to a complex power.
source§

fn conj(self) -> T

Computes the complex conjugate of the number. Read more
source§

fn expf(self, base: <T as ComplexFloat>::Real) -> T

Returns base^(self).
source§

fn is_normal(self) -> bool

Returns true if the number is neither zero, infinite, subnormal, or NaN.
source§

fn is_infinite(self) -> bool

Returns true if this value is positive infinity or negative infinity and false otherwise.
source§

fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.
source§

fn is_nan(self) -> bool

Returns true if this value is NaN and false otherwise.
source§

fn recip(self) -> T

Take the reciprocal (inverse) of a number, 1/x. See also Complex::finv.
source§

fn powi(self, n: i32) -> T

Raises self to a signed integer power.
source§

fn powf(self, f: T) -> T

Raises self to a real power.
source§

fn sqrt(self) -> T

Take the square root of a number.
source§

fn cbrt(self) -> T

Take the cubic root of a number.
source§

fn exp(self) -> T

Returns e^(self), (the exponential function).
source§

fn exp2(self) -> T

Returns 2^(self).
source§

fn ln(self) -> T

Returns the natural logarithm of the number.
source§

fn log(self, base: T) -> T

Returns the logarithm of the number with respect to an arbitrary base.
source§

fn log2(self) -> T

Returns the base 2 logarithm of the number.
source§

fn log10(self) -> T

Returns the base 10 logarithm of the number.
source§

fn sin(self) -> T

Computes the sine of a number (in radians).
source§

fn cos(self) -> T

Computes the cosine of a number (in radians).
source§

fn tan(self) -> T

Computes the tangent of a number (in radians).
source§

fn asin(self) -> T

Computes the arcsine of a number. Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1].
source§

fn acos(self) -> T

Computes the arccosine of a number. Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1].
source§

fn atan(self) -> T

Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2];
source§

fn sinh(self) -> T

Hyperbolic sine function.
source§

fn cosh(self) -> T

Hyperbolic cosine function.
source§

fn tanh(self) -> T

Hyperbolic tangent function.
source§

fn asinh(self) -> T

Inverse hyperbolic sine function.
source§

fn acosh(self) -> T

Inverse hyperbolic cosine function.
source§

fn atanh(self) -> T

Inverse hyperbolic tangent function.
source§

fn abs(self) -> T

Returns the absolute value of the number. See also Complex::norm
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where 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> Real for T
where T: Float,

source§

fn min_value() -> T

Returns the smallest finite value that this type can represent. Read more
source§

fn min_positive_value() -> T

Returns the smallest positive, normalized value that this type can represent. Read more
source§

fn epsilon() -> T

Returns epsilon, a small positive value. Read more
source§

fn max_value() -> T

Returns the largest finite value that this type can represent. Read more
source§

fn floor(self) -> T

Returns the largest integer less than or equal to a number. Read more
source§

fn ceil(self) -> T

Returns the smallest integer greater than or equal to a number. Read more
source§

fn round(self) -> T

Returns the nearest integer to a number. Round half-way cases away from 0.0. Read more
source§

fn trunc(self) -> T

Return the integer part of a number. Read more
source§

fn fract(self) -> T

Returns the fractional part of a number. Read more
source§

fn abs(self) -> T

Computes the absolute value of self. Returns Float::nan() if the number is Float::nan(). Read more
source§

fn signum(self) -> T

Returns a number that represents the sign of self. Read more
source§

fn is_sign_positive(self) -> bool

Returns true if self is positive, including +0.0, Float::infinity(), and with newer versions of Rust f64::NAN. Read more
source§

fn is_sign_negative(self) -> bool

Returns true if self is negative, including -0.0, Float::neg_infinity(), and with newer versions of Rust -f64::NAN. Read more
source§

fn mul_add(self, a: T, b: T) -> T

Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add. Read more
source§

fn recip(self) -> T

Take the reciprocal (inverse) of a number, 1/x. Read more
source§

fn powi(self, n: i32) -> T

Raise a number to an integer power. Read more
source§

fn powf(self, n: T) -> T

Raise a number to a real number power. Read more
source§

fn sqrt(self) -> T

Take the square root of a number. Read more
source§

fn exp(self) -> T

Returns e^(self), (the exponential function). Read more
source§

fn exp2(self) -> T

Returns 2^(self). Read more
source§

fn ln(self) -> T

Returns the natural logarithm of the number. Read more
source§

fn log(self, base: T) -> T

Returns the logarithm of the number with respect to an arbitrary base. Read more
source§

fn log2(self) -> T

Returns the base 2 logarithm of the number. Read more
source§

fn log10(self) -> T

Returns the base 10 logarithm of the number. Read more
source§

fn to_degrees(self) -> T

Converts radians to degrees. Read more
source§

fn to_radians(self) -> T

Converts degrees to radians. Read more
source§

fn max(self, other: T) -> T

Returns the maximum of the two numbers. Read more
source§

fn min(self, other: T) -> T

Returns the minimum of the two numbers. Read more
source§

fn abs_sub(self, other: T) -> T

The positive difference of two numbers. Read more
source§

fn cbrt(self) -> T

Take the cubic root of a number. Read more
source§

fn hypot(self, other: T) -> T

Calculate the length of the hypotenuse of a right-angle triangle given legs of length x and y. Read more
source§

fn sin(self) -> T

Computes the sine of a number (in radians). Read more
source§

fn cos(self) -> T

Computes the cosine of a number (in radians). Read more
source§

fn tan(self) -> T

Computes the tangent of a number (in radians). Read more
source§

fn asin(self) -> T

Computes the arcsine of a number. Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1]. Read more
source§

fn acos(self) -> T

Computes the arccosine of a number. Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1]. Read more
source§

fn atan(self) -> T

Computes the arctangent of a number. Return value is in radians in the range [-pi/2, pi/2]; Read more
source§

fn atan2(self, other: T) -> T

Computes the four quadrant arctangent of self (y) and other (x). Read more
source§

fn sin_cos(self) -> (T, T)

Simultaneously computes the sine and cosine of the number, x. Returns (sin(x), cos(x)). Read more
source§

fn exp_m1(self) -> T

Returns e^(self) - 1 in a way that is accurate even if the number is close to zero. Read more
source§

fn ln_1p(self) -> T

Returns ln(1+n) (natural logarithm) more accurately than if the operations were performed separately. Read more
source§

fn sinh(self) -> T

Hyperbolic sine function. Read more
source§

fn cosh(self) -> T

Hyperbolic cosine function. Read more
source§

fn tanh(self) -> T

Hyperbolic tangent function. Read more
source§

fn asinh(self) -> T

Inverse hyperbolic sine function. Read more
source§

fn acosh(self) -> T

Inverse hyperbolic cosine function. Read more
source§

fn atanh(self) -> T

Inverse hyperbolic tangent function. Read more
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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 T
where 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> NumAssign for T
where T: Num + NumAssignOps,

source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,