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>
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>
sourcepub const MANTISSA_DIGITS: usize = _
pub const MANTISSA_DIGITS: usize = _
Number of significant digits in base 2.
sourcepub const IS_INT_IMPLICIT: bool = _
pub const IS_INT_IMPLICIT: bool = _
true
if the number contains an implicit integer bit
sourcepub 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
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
Converts from one custom floating-point number to another. Rounding errors may occurr.
sourcepub fn from_uint<I: UInt>(from: I) -> Self
pub fn from_uint<I: UInt>(from: I) -> Self
Converts an unsigned integer into a custom floating-point type.
sourcepub fn from_int<I: Int>(from: I) -> Self
pub fn from_int<I: Int>(from: I) -> Self
Converts a signed integer into a custom floating-point type.
sourcepub fn to_uint<I: UInt>(self) -> Option<I>
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.
sourcepub fn to_uint_wrapping<I: UInt>(self) -> I
pub fn to_uint_wrapping<I: UInt>(self) -> I
Converts a custom floating-point type into an unsigned integer.
Wraps if out of bounds.
sourcepub fn to_int<I: Int>(self) -> Option<I>
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.
sourcepub fn to_int_wrapping<I: Int>(self) -> I
pub fn to_int_wrapping<I: Int>(self) -> I
Converts a custom floating-point type into a signed integer.
Wraps if out of bounds.
sourcepub const fn from_bits(bits: U) -> Self
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));
sourcepub const fn to_bits(self) -> U
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);
sourcepub fn to_be_bytes(self) -> U::Byteswhere
U: ToBytes,
pub fn to_be_bytes(self) -> U::Byteswhere
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]);
sourcepub fn to_le_bytes(self) -> U::Byteswhere
U: ToBytes,
pub fn to_le_bytes(self) -> U::Byteswhere
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]);
sourcepub fn to_ne_bytes(self) -> U::Byteswhere
U: ToBytes,
pub fn to_ne_bytes(self) -> U::Byteswhere
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]
}
);
sourcepub fn from_be_bytes(bytes: &U::Bytes) -> Selfwhere
U: FromBytes,
pub fn from_be_bytes(bytes: &U::Bytes) -> Selfwhere
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));
sourcepub fn from_le_bytes(bytes: &U::Bytes) -> Selfwhere
U: FromBytes,
pub fn from_le_bytes(bytes: &U::Bytes) -> Selfwhere
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));
sourcepub fn from_ne_bytes(bytes: &U::Bytes) -> Selfwhere
U: FromBytes,
pub fn from_ne_bytes(bytes: &U::Bytes) -> Selfwhere
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));
sourcepub fn nan() -> Self
pub fn nan() -> Self
Returns the NaN
value.
§Examples
use custom_float::ieee754::FpSingle;
let nan = FpSingle::nan();
assert!(nan.is_nan());
sourcepub fn qnan() -> Self
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());
sourcepub fn snan() -> Self
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());
sourcepub fn is_snan(self) -> bool
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());
sourcepub fn infinity() -> Self
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());
sourcepub fn neg_infinity() -> Self
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());
sourcepub fn neg_zero() -> Self
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);
sourcepub fn min_value() -> Self
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));
sourcepub fn min_positive_value() -> Self
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));
sourcepub fn epsilon() -> Self
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));
sourcepub fn max_value() -> Self
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));
sourcepub fn is_nan(self) -> bool
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());
sourcepub fn is_infinite(self) -> bool
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());
sourcepub fn is_finite(self) -> bool
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());
sourcepub fn is_normal(self) -> bool
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());
sourcepub fn is_subnormal(self) -> bool
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());
sourcepub fn classify(self) -> FpCategory
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);
sourcepub fn floor(self) -> Self
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));
sourcepub fn ceil(self) -> Self
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));
sourcepub fn round(self) -> Self
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));
sourcepub fn round_ties_even(self) -> Self
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));
sourcepub fn trunc(self) -> Self
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));
sourcepub fn fract(self) -> Self
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));
sourcepub fn abs(self) -> Self
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());
sourcepub fn signum(self) -> Self
pub fn signum(self) -> Self
Returns a number that represents the sign of self
.
1.0
if the number is positive,+0.0
orinf
-1.0
if the number is negative,-0.0
or-inf
NaN
if the number isNaN
§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());
sourcepub fn is_sign_positive(self) -> bool
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());
sourcepub fn is_sign_negative(self) -> bool
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());
sourcepub fn next_up(self) -> Self
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 returnsself
; - if
self
isNEG_INFINITY
, this returnsMIN
; - if
self
is-TINY
, this returns -0.0; - if
self
is -0.0 or +0.0, this returnsTINY
; - if
self
isMAX
orINFINITY
, this returnsINFINITY
; - 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));
sourcepub fn next_down(self) -> Self
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 returnsself
; - if
self
isINFINITY
, this returnsMAX
; - if
self
isTINY
, this returns 0.0; - if
self
is -0.0 or +0.0, this returns-TINY
; - if
self
isMIN
orNEG_INFINITY
, this returnsNEG_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());
sourcepub fn maximum(self, other: Self) -> Self
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.
sourcepub fn minimum(self, other: Self) -> Self
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.
sourcepub fn midpoint(self, other: Self) -> Self
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));
sourcepub fn mul_add(self, a: Self, b: Self) -> Self
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));
sourcepub fn recip(self) -> Self
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));
sourcepub fn powi<I: Int>(self, n: I) -> Self
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));
sourcepub fn powu<I: UInt>(self, n: I) -> Self
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));
sourcepub fn powf(self, n: Self) -> Self
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));
sourcepub fn sqrt(self) -> Self
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());
sourcepub fn expb(self) -> Self
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));
sourcepub fn exp(self) -> Self
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));
sourcepub fn exp10(self) -> Self
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));
sourcepub fn exp2(self) -> Self
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));
sourcepub fn ln(self) -> Self
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));
sourcepub fn log(self, base: Self) -> Self
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));
sourcepub fn logb(self) -> Self
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));
sourcepub fn log2(self) -> Self
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));
sourcepub fn log10(self) -> Self
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));
sourcepub fn to_degrees(self) -> Self
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));
sourcepub fn to_radians(self) -> Self
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));
sourcepub fn max(self, other: Self) -> Self
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);
sourcepub fn min(self, other: Self) -> Self
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);
sourcepub 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).
pub fn abs_sub(self, other: Self) -> Self
(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));
sourcepub fn cbrt(self) -> Self
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));
sourcepub fn hypot(self, other: Self) -> Self
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));
sourcepub fn sin(self) -> Self
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));
sourcepub fn cos(self) -> Self
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));
sourcepub fn tan(self) -> Self
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));
sourcepub fn asin(self) -> Self
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));
sourcepub fn acos(self) -> Self
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));
sourcepub fn atan(self) -> Self
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));
sourcepub fn atan2(self, other: Self) -> Self
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));
sourcepub fn sin_cos(self) -> (Self, Self)
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));
sourcepub fn exp_m1(self) -> Self
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));
sourcepub fn ln_1p(self) -> Self
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));
sourcepub fn sinh(self) -> Self
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));
sourcepub fn cosh(self) -> Self
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));
sourcepub fn tanh(self) -> Self
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));
sourcepub fn asinh(self) -> Self
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));
sourcepub fn acosh(self) -> Self
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));
sourcepub fn atanh(self) -> Self
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));
sourcepub fn ln_gamma(self) -> (Self, i32)
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));
sourcepub fn gamma(self) -> Self
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));
sourcepub fn copysign(self, sign: Self) -> Self
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());
sourcepub fn div_euclid(self, rhs: Self) -> Self
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
sourcepub fn rem_euclid(self, rhs: Self) -> Self
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));
sourcepub fn total_cmp(self, other: Self) -> Ordering
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);
sourcepub fn mulb(self) -> Self
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));
sourcepub fn divb(self) -> Self
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));
sourcepub fn clamp(self, min: Self, max: Self) -> Self
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());
sourcepub fn erf(self) -> Self
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)
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>
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>
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>
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>
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresource§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>
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>
source§fn div_euclid(&self, rhs: &Self) -> Self
fn div_euclid(&self, rhs: &Self) -> Self
rem_euclid
. Read moresource§fn rem_euclid(&self, rhs: &Self) -> Self
fn rem_euclid(&self, rhs: &Self) -> Self
self (mod v)
. Read moresource§fn div_rem_euclid(&self, v: &Self) -> (Self, Self)
fn div_rem_euclid(&self, v: &Self) -> (Self, Self)
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>
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>
source§fn neg_infinity() -> Self
fn neg_infinity() -> Self
source§fn min_value() -> Self
fn min_value() -> Self
source§fn min_positive_value() -> Self
fn min_positive_value() -> Self
source§fn max_value() -> Self
fn max_value() -> Self
source§fn is_infinite(self) -> bool
fn is_infinite(self) -> bool
true
if this value is positive infinity or negative infinity and
false otherwise. Read moresource§fn classify(self) -> FpCategory
fn classify(self) -> FpCategory
source§fn ceil(self) -> Self
fn ceil(self) -> Self
source§fn round(self) -> Self
fn round(self) -> Self
0.0
. Read moresource§fn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
source§fn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
true
if self
is negative, including -0.0
,
Float::neg_infinity()
, and -Float::nan()
. Read moresource§fn mul_add(self, a: Self, b: Self) -> Self
fn mul_add(self, a: Self, b: Self) -> Self
(self * a) + b
with only one rounding
error, yielding a more accurate result than an unfused multiply-add. Read moresource§fn log(self, base: Self) -> Self
fn log(self, base: Self) -> Self
source§fn hypot(self, other: Self) -> Self
fn hypot(self, other: Self) -> Self
x
and y
. Read moresource§fn asin(self) -> Self
fn asin(self) -> Self
source§fn acos(self) -> Self
fn acos(self) -> Self
source§fn atan(self) -> Self
fn atan(self) -> Self
source§fn sin_cos(self) -> (Self, Self)
fn sin_cos(self) -> (Self, Self)
source§fn exp_m1(self) -> Self
fn exp_m1(self) -> Self
e^(self) - 1
in a way that is accurate even if the
number is close to zero. Read moresource§fn ln_1p(self) -> Self
fn ln_1p(self) -> Self
ln(1+n)
(natural logarithm) more accurately than if
the operations were performed separately. Read moresource§fn integer_decode(self) -> (u64, i16, i8)
fn integer_decode(self) -> (u64, i16, i8)
sign * mantissa * 2 ^ exponent
. Read moresource§fn to_degrees(self) -> Self
fn to_degrees(self) -> Self
source§fn to_radians(self) -> Self
fn to_radians(self) -> Self
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>
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>
source§fn FRAC_1_SQRT_2() -> Self
fn FRAC_1_SQRT_2() -> Self
Return 1.0 / sqrt(2.0)
.
source§fn FRAC_2_SQRT_PI() -> Self
fn FRAC_2_SQRT_PI() -> Self
Return 2.0 / sqrt(π)
.
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>
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>
source§fn neg_infinity() -> Self
fn neg_infinity() -> Self
source§fn min_value() -> Self
fn min_value() -> Self
source§fn min_positive_value() -> Self
fn min_positive_value() -> Self
source§fn max_value() -> Self
fn max_value() -> Self
source§fn classify(self) -> FpCategory
fn classify(self) -> FpCategory
source§fn to_degrees(self) -> Self
fn to_degrees(self) -> Self
source§fn to_radians(self) -> Self
fn to_radians(self) -> Self
source§fn integer_decode(self) -> (u64, i16, i8)
fn integer_decode(self) -> (u64, i16, i8)
sign * mantissa * 2 ^ exponent
. Read moresource§fn is_infinite(self) -> bool
fn is_infinite(self) -> bool
true
if the number is infinite. Read moresource§fn is_normal(self) -> bool
fn is_normal(self) -> bool
true
if the number is neither zero, infinite, subnormal or NaN. Read moresource§fn ceil(self) -> Self
fn ceil(self) -> Self
source§fn round(self) -> Self
fn round(self) -> Self
0.0
. Read moresource§fn abs(self) -> Self
fn abs(self) -> Self
self
. Returns FloatCore::nan()
if the
number is FloatCore::nan()
. Read moresource§fn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
true
if self
is positive, including +0.0
and
FloatCore::infinity()
, and FloatCore::nan()
. Read moresource§fn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
true
if self
is negative, including -0.0
and
FloatCore::neg_infinity()
, and -FloatCore::nan()
. Read moresource§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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
type Bytes = <U as FromBytes>::Bytes
source§fn from_be_bytes(bytes: &Self::Bytes) -> Self
fn from_be_bytes(bytes: &Self::Bytes) -> Self
source§fn from_le_bytes(bytes: &Self::Bytes) -> Self
fn from_le_bytes(bytes: &Self::Bytes) -> Self
source§fn from_ne_bytes(bytes: &Self::Bytes) -> Self
fn from_ne_bytes(bytes: &Self::Bytes) -> Self
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>
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>
source§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
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>
fn from_i8(n: i8) -> Option<Self>
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>
fn from_i16(n: i16) -> Option<Self>
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>
fn from_i32(n: i32) -> Option<Self>
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>
fn from_i64(n: i64) -> Option<Self>
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>
fn from_i128(n: i128) -> Option<Self>
i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
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>
fn from_u8(n: u8) -> Option<Self>
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>
fn from_u16(n: u16) -> Option<Self>
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>
fn from_u32(n: u32) -> Option<Self>
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>
fn from_u64(n: u64) -> Option<Self>
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>
fn from_u128(n: u128) -> Option<Self>
u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moresource§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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
source§fn mul_add_assign(&mut self, a: Self, b: Self)
fn mul_add_assign(&mut self, a: Self, b: Self)
*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>
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>
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresource§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>
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>
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>
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>
type FromStrRadixErr = ParseFloatError
source§fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36
). Read moresource§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>
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>
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>
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>
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>
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>
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>
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>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%=
operation. Read moresource§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>
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>
source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
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>
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>
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>
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>
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moresource§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>
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>
type Bytes = <U as ToBytes>::Bytes
source§fn to_be_bytes(&self) -> Self::Bytes
fn to_be_bytes(&self) -> Self::Bytes
source§fn to_le_bytes(&self) -> Self::Bytes
fn to_le_bytes(&self) -> Self::Bytes
source§fn to_ne_bytes(&self) -> Self::Bytes
fn to_ne_bytes(&self) -> Self::Bytes
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>
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>
source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self
to an i8
. If the value cannot be
represented by an i8
, then None
is returned.source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self
to a u8
. If the value cannot be
represented by a u8
, then None
is returned.source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self
to an i16
. If the value cannot be
represented by an i16
, then None
is returned.source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self
to a u16
. If the value cannot be
represented by a u16
, then None
is returned.source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self
to an i32
. If the value cannot be
represented by an i32
, then None
is returned.source§fn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
self
to a u32
. If the value cannot be
represented by a u32
, then None
is returned.source§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self
to an isize
. If the value cannot be
represented by an isize
, then None
is returned.source§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self
to a usize
. If the value cannot be
represented by a usize
, then None
is returned.source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self
to an i64
. If the value cannot be
represented by an i64
, then None
is returned.source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self
to a u64
. If the value cannot be
represented by a u64
, then None
is returned.source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self
to an i128
. If the value cannot be
represented by an i128
(i64
under the default implementation), then
None
is returned. Read moresource§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self
to a u128
. If the value cannot be
represented by a u128
(u64
under the default implementation), then
None
is returned. Read moresource§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>
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>
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>
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>
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>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> ComplexFloat for Twhere
T: Float + FloatConst,
impl<T> ComplexFloat for Twhere
T: Float + FloatConst,
source§fn re(self) -> <T as ComplexFloat>::Real
fn re(self) -> <T as ComplexFloat>::Real
source§fn im(self) -> <T as ComplexFloat>::Real
fn im(self) -> <T as ComplexFloat>::Real
source§fn l1_norm(&self) -> <T as ComplexFloat>::Real
fn l1_norm(&self) -> <T as ComplexFloat>::Real
|re| + |im|
– the Manhattan distance from the origin.source§fn arg(self) -> <T as ComplexFloat>::Real
fn arg(self) -> <T as ComplexFloat>::Real
source§fn powc(
self,
exp: Complex<<T as ComplexFloat>::Real>
) -> Complex<<T as ComplexFloat>::Real>
fn powc( self, exp: Complex<<T as ComplexFloat>::Real> ) -> Complex<<T as ComplexFloat>::Real>
self
to a complex power.source§fn expf(self, base: <T as ComplexFloat>::Real) -> T
fn expf(self, base: <T as ComplexFloat>::Real) -> T
base^(self)
.source§fn is_infinite(self) -> bool
fn is_infinite(self) -> bool
true
if this value is positive infinity or negative infinity and
false otherwise.source§fn recip(self) -> T
fn recip(self) -> T
1/x
. See also Complex::finv.source§fn log(self, base: T) -> T
fn log(self, base: T) -> T
source§fn asin(self) -> T
fn asin(self) -> T
source§fn acos(self) -> T
fn acos(self) -> T
source§fn atan(self) -> T
fn atan(self) -> T
source§fn abs(self) -> T
fn abs(self) -> T
source§impl<T> Real for Twhere
T: Float,
impl<T> Real for Twhere
T: Float,
source§fn min_positive_value() -> T
fn min_positive_value() -> T
source§fn round(self) -> T
fn round(self) -> T
0.0
. Read moresource§fn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
true
if self
is positive, including +0.0
,
Float::infinity()
, and with newer versions of Rust f64::NAN
. Read moresource§fn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
true
if self
is negative, including -0.0
,
Float::neg_infinity()
, and with newer versions of Rust -f64::NAN
. Read moresource§fn mul_add(self, a: T, b: T) -> T
fn mul_add(self, a: T, b: T) -> T
(self * a) + b
with only one rounding
error, yielding a more accurate result than an unfused multiply-add. Read moresource§fn log(self, base: T) -> T
fn log(self, base: T) -> T
source§fn to_degrees(self) -> T
fn to_degrees(self) -> T
source§fn to_radians(self) -> T
fn to_radians(self) -> T
source§fn hypot(self, other: T) -> T
fn hypot(self, other: T) -> T
x
and y
. Read moresource§fn asin(self) -> T
fn asin(self) -> T
source§fn acos(self) -> T
fn acos(self) -> T
source§fn atan(self) -> T
fn atan(self) -> T
source§fn exp_m1(self) -> T
fn exp_m1(self) -> T
e^(self) - 1
in a way that is accurate even if the
number is close to zero. Read more