Trait funty::Floating

source ·
pub trait Floating: Numeric + LowerExp + UpperExp + Neg + From<f32> + From<i8> + From<i16> + From<u8> + From<u16> {
    type Raw: Unsigned;
Show 30 associated constants and 14 methods const RADIX: u32; const MANTISSA_DIGITS: u32; const DIGITS: u32; const EPSILON: Self; const MIN: Self; const MIN_POSITIVE: Self; const MAX: Self; const MIN_EXP: i32; const MAX_EXP: i32; const MIN_10_EXP: i32; const MAX_10_EXP: i32; const NAN: Self; const INFINITY: Self; const NEG_INFINITY: Self; const PI: Self; const FRAC_PI_2: Self; const FRAC_PI_3: Self; const FRAC_PI_4: Self; const FRAC_PI_6: Self; const FRAC_PI_8: Self; const FRAC_1_PI: Self; const FRAC_2_PI: Self; const FRAC_2_SQRT_PI: Self; const SQRT_2: Self; const FRAC_1_SQRT_2: Self; const E: Self; const LOG2_E: Self; const LOG10_E: Self; const LN_2: Self; const LN_10: Self; // Required methods fn is_nan(self) -> bool; fn is_infinite(self) -> bool; fn is_finite(self) -> bool; fn is_normal(self) -> bool; fn classify(self) -> FpCategory; fn is_sign_positive(self) -> bool; fn is_sign_negative(self) -> bool; fn recip(self) -> Self; fn to_degrees(self) -> Self; fn to_radians(self) -> Self; fn max(self, other: Self) -> Self; fn min(self, other: Self) -> Self; fn to_bits(self) -> Self::Raw; fn from_bits(bits: Self::Raw) -> Self;
}
Expand description

Declare that a type is a floating-point number.

Required Associated Types§

source

type Raw: Unsigned

The unsigned integer type of the same width as Self.

Required Associated Constants§

source

const RADIX: u32

The radix or base of the internal representation of f32.

source

const MANTISSA_DIGITS: u32

Number of significant digits in base 2.

source

const DIGITS: u32

Approximate number of significant digits in base 10.

source

const EPSILON: Self

Machine epsilon value for f32.

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

source

const MIN: Self

Smallest finite f32 value.

source

const MIN_POSITIVE: Self

Smallest positive normal f32 value.

source

const MAX: Self

Largest finite f32 value.

source

const MIN_EXP: i32

One greater than the minimum possible normal power of 2 exponent.

source

const MAX_EXP: i32

Maximum possible power of 2 exponent.

source

const MIN_10_EXP: i32

Minimum possible normal power of 10 exponent.

source

const MAX_10_EXP: i32

Maximum possible power of 10 exponent.

source

const NAN: Self

Not a Number (NaN).

source

const INFINITY: Self

Infinity (∞).

source

const NEG_INFINITY: Self

Negative infinity (−∞).

source

const PI: Self

Archimedes’ constant (π)

source

const FRAC_PI_2: Self

π/2

source

const FRAC_PI_3: Self

π/3

source

const FRAC_PI_4: Self

π/4

source

const FRAC_PI_6: Self

π/6

source

const FRAC_PI_8: Self

π/8

source

const FRAC_1_PI: Self

1/π

source

const FRAC_2_PI: Self

2/π

source

const FRAC_2_SQRT_PI: Self

2/sqrt(π)

source

const SQRT_2: Self

sqrt(2)

source

const FRAC_1_SQRT_2: Self

1/sqrt(2)

source

const E: Self

Euler’s number (e)

source

const LOG2_E: Self

log2(e)

source

const LOG10_E: Self

log10(e)

source

const LN_2: Self

ln(2)

source

const LN_10: Self

ln(10)

Required Methods§

source

fn is_nan(self) -> bool

Returns true if this value is NaN.

source

fn is_infinite(self) -> bool

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

source

fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.

source

fn is_normal(self) -> bool

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

source

fn classify(self) -> FpCategory

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

source

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.

source

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.

source

fn recip(self) -> Self

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

source

fn to_degrees(self) -> Self

Converts radians to degrees.

source

fn to_radians(self) -> Self

Converts degrees to radians.

source

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

Returns the maximum of the two numbers.

source

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

Returns the minimum of the two numbers.

source

fn to_bits(self) -> Self::Raw

Raw transmutation to u32.

This is currently identical to transmute::<f32, u32>(self) on all platforms.

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

Note that this function is distinct from as casting, which attempts to preserve the numeric value, and not the bitwise value.

source

fn from_bits(bits: Self::Raw) -> Self

Raw transmutation from u32.

This is currently identical to transmute::<u32, f32>(v) on all platforms. It turns out this is incredibly portable, for two reasons:

  • Floats and Ints have the same endianness on all supported platforms.
  • IEEE-754 very precisely specifies the bit layout of floats.

However there is one caveat: prior to the 2008 version of IEEE-754, how to interpret the NaN signaling bit wasn’t actually specified. Most platforms (notably x86 and ARM) picked the interpretation that was ultimately standardized in 2008, but some didn’t (notably MIPS). As a result, all signaling NaNs on MIPS are quiet NaNs on x86, and vice-versa.

Rather than trying to preserve signaling-ness cross-platform, this implementation favors preserving the exact bits. This means that any payloads encoded in NaNs will be preserved even if the result of this method is sent over the network from an x86 machine to a MIPS one.

If the results of this method are only manipulated by the same architecture that produced them, then there is no portability concern.

If the input isn’t NaN, then there is no portability concern.

If you don’t care about signalingness (very likely), then there is no portability concern.

Note that this function is distinct from as casting, which attempts to preserve the numeric value, and not the bitwise value.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Floating for f32

§

type Raw = u32

source§

const RADIX: u32 = 2u32

source§

const MANTISSA_DIGITS: u32 = 24u32

source§

const DIGITS: u32 = 6u32

source§

const EPSILON: Self = 1.1920929E-7f32

source§

const MIN: Self = -3.40282347E+38f32

source§

const MIN_POSITIVE: Self = 1.17549435E-38f32

source§

const MAX: Self = 3.40282347E+38f32

source§

const MIN_EXP: i32 = -125i32

source§

const MAX_EXP: i32 = 128i32

source§

const MIN_10_EXP: i32 = -37i32

source§

const MAX_10_EXP: i32 = 38i32

source§

const NAN: Self = NaNf32

source§

const INFINITY: Self = +Inff32

source§

const NEG_INFINITY: Self = -Inff32

source§

const PI: Self = 3.14159274f32

source§

const FRAC_PI_2: Self = 1.57079637f32

source§

const FRAC_PI_3: Self = 1.04719758f32

source§

const FRAC_PI_4: Self = 0.785398185f32

source§

const FRAC_PI_6: Self = 0.52359879f32

source§

const FRAC_PI_8: Self = 0.392699093f32

source§

const FRAC_1_PI: Self = 0.318309873f32

source§

const FRAC_2_PI: Self = 0.636619746f32

source§

const FRAC_2_SQRT_PI: Self = 1.12837923f32

source§

const SQRT_2: Self = 1.41421354f32

source§

const FRAC_1_SQRT_2: Self = 0.707106769f32

source§

const E: Self = 2.71828175f32

source§

const LOG2_E: Self = 1.44269502f32

source§

const LOG10_E: Self = 0.434294492f32

source§

const LN_2: Self = 0.693147182f32

source§

const LN_10: Self = 2.30258512f32

source§

fn is_nan(self) -> bool

source§

fn is_infinite(self) -> bool

source§

fn is_finite(self) -> bool

source§

fn is_normal(self) -> bool

source§

fn classify(self) -> FpCategory

source§

fn is_sign_positive(self) -> bool

source§

fn is_sign_negative(self) -> bool

source§

fn recip(self) -> Self

source§

fn to_degrees(self) -> Self

source§

fn to_radians(self) -> Self

source§

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

source§

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

source§

fn to_bits(self) -> Self::Raw

source§

fn from_bits(bits: Self::Raw) -> Self

source§

impl Floating for f64

§

type Raw = u64

source§

const RADIX: u32 = 2u32

source§

const MANTISSA_DIGITS: u32 = 53u32

source§

const DIGITS: u32 = 15u32

source§

const EPSILON: Self = 2.2204460492503131E-16f64

source§

const MIN: Self = -1.7976931348623157E+308f64

source§

const MIN_POSITIVE: Self = 2.2250738585072014E-308f64

source§

const MAX: Self = 1.7976931348623157E+308f64

source§

const MIN_EXP: i32 = -1_021i32

source§

const MAX_EXP: i32 = 1_024i32

source§

const MIN_10_EXP: i32 = -307i32

source§

const MAX_10_EXP: i32 = 308i32

source§

const NAN: Self = NaNf64

source§

const INFINITY: Self = +Inff64

source§

const NEG_INFINITY: Self = -Inff64

source§

const PI: Self = 3.1415926535897931f64

source§

const FRAC_PI_2: Self = 1.5707963267948966f64

source§

const FRAC_PI_3: Self = 1.0471975511965979f64

source§

const FRAC_PI_4: Self = 0.78539816339744828f64

source§

const FRAC_PI_6: Self = 0.52359877559829893f64

source§

const FRAC_PI_8: Self = 0.39269908169872414f64

source§

const FRAC_1_PI: Self = 0.31830988618379069f64

source§

const FRAC_2_PI: Self = 0.63661977236758138f64

source§

const FRAC_2_SQRT_PI: Self = 1.1283791670955126f64

source§

const SQRT_2: Self = 1.4142135623730951f64

source§

const FRAC_1_SQRT_2: Self = 0.70710678118654757f64

source§

const E: Self = 2.7182818284590451f64

source§

const LOG2_E: Self = 1.4426950408889634f64

source§

const LOG10_E: Self = 0.43429448190325182f64

source§

const LN_2: Self = 0.69314718055994529f64

source§

const LN_10: Self = 2.3025850929940459f64

source§

fn is_nan(self) -> bool

source§

fn is_infinite(self) -> bool

source§

fn is_finite(self) -> bool

source§

fn is_normal(self) -> bool

source§

fn classify(self) -> FpCategory

source§

fn is_sign_positive(self) -> bool

source§

fn is_sign_negative(self) -> bool

source§

fn recip(self) -> Self

source§

fn to_degrees(self) -> Self

source§

fn to_radians(self) -> Self

source§

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

source§

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

source§

fn to_bits(self) -> Self::Raw

source§

fn from_bits(bits: Self::Raw) -> Self

Implementors§