Skip to main content

Floating

Trait 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 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 Associated Types§

Source

type Raw: Unsigned

The unsigned integer type of the same width as Self.

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Floating for f32

Source§

const RADIX: u32 = core::f32::RADIX

Source§

const MANTISSA_DIGITS: u32 = core::f32::MANTISSA_DIGITS

Source§

const DIGITS: u32 = core::f32::DIGITS

Source§

const EPSILON: Self = core::f32::EPSILON

Source§

const MIN: Self = core::f32::MIN

Source§

const MIN_POSITIVE: Self = core::f32::MIN_POSITIVE

Source§

const MAX: Self = core::f32::MAX

Source§

const MIN_EXP: i32 = core::f32::MIN_EXP

Source§

const MAX_EXP: i32 = core::f32::MAX_EXP

Source§

const MIN_10_EXP: i32 = core::f32::MIN_10_EXP

Source§

const MAX_10_EXP: i32 = core::f32::MAX_10_EXP

Source§

const NAN: Self = core::f32::NAN

Source§

const INFINITY: Self = core::f32::INFINITY

Source§

const NEG_INFINITY: Self = core::f32::NEG_INFINITY

Source§

const PI: Self = core::f32::consts::PI

Source§

const FRAC_PI_2: Self = core::f32::consts::FRAC_PI_2

Source§

const FRAC_PI_3: Self = core::f32::consts::FRAC_PI_3

Source§

const FRAC_PI_4: Self = core::f32::consts::FRAC_PI_4

Source§

const FRAC_PI_6: Self = core::f32::consts::FRAC_PI_6

Source§

const FRAC_PI_8: Self = core::f32::consts::FRAC_PI_8

Source§

const FRAC_1_PI: Self = core::f32::consts::FRAC_1_PI

Source§

const FRAC_2_PI: Self = core::f32::consts::FRAC_2_PI

Source§

const FRAC_2_SQRT_PI: Self = core::f32::consts::FRAC_2_SQRT_PI

Source§

const SQRT_2: Self = core::f32::consts::SQRT_2

Source§

const FRAC_1_SQRT_2: Self = core::f32::consts::FRAC_1_SQRT_2

Source§

const E: Self = core::f32::consts::E

Source§

const LOG2_E: Self = core::f32::consts::LOG2_E

Source§

const LOG10_E: Self = core::f32::consts::LOG10_E

Source§

const LN_2: Self = core::f32::consts::LN_2

Source§

const LN_10: Self = core::f32::consts::LN_10

Source§

type Raw = u32

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

Source§

const RADIX: u32 = core::f64::RADIX

Source§

const MANTISSA_DIGITS: u32 = core::f64::MANTISSA_DIGITS

Source§

const DIGITS: u32 = core::f64::DIGITS

Source§

const EPSILON: Self = core::f64::EPSILON

Source§

const MIN: Self = core::f64::MIN

Source§

const MIN_POSITIVE: Self = core::f64::MIN_POSITIVE

Source§

const MAX: Self = core::f64::MAX

Source§

const MIN_EXP: i32 = core::f64::MIN_EXP

Source§

const MAX_EXP: i32 = core::f64::MAX_EXP

Source§

const MIN_10_EXP: i32 = core::f64::MIN_10_EXP

Source§

const MAX_10_EXP: i32 = core::f64::MAX_10_EXP

Source§

const NAN: Self = core::f64::NAN

Source§

const INFINITY: Self = core::f64::INFINITY

Source§

const NEG_INFINITY: Self = core::f64::NEG_INFINITY

Source§

const PI: Self = core::f64::consts::PI

Source§

const FRAC_PI_2: Self = core::f64::consts::FRAC_PI_2

Source§

const FRAC_PI_3: Self = core::f64::consts::FRAC_PI_3

Source§

const FRAC_PI_4: Self = core::f64::consts::FRAC_PI_4

Source§

const FRAC_PI_6: Self = core::f64::consts::FRAC_PI_6

Source§

const FRAC_PI_8: Self = core::f64::consts::FRAC_PI_8

Source§

const FRAC_1_PI: Self = core::f64::consts::FRAC_1_PI

Source§

const FRAC_2_PI: Self = core::f64::consts::FRAC_2_PI

Source§

const FRAC_2_SQRT_PI: Self = core::f64::consts::FRAC_2_SQRT_PI

Source§

const SQRT_2: Self = core::f64::consts::SQRT_2

Source§

const FRAC_1_SQRT_2: Self = core::f64::consts::FRAC_1_SQRT_2

Source§

const E: Self = core::f64::consts::E

Source§

const LOG2_E: Self = core::f64::consts::LOG2_E

Source§

const LOG10_E: Self = core::f64::consts::LOG10_E

Source§

const LN_2: Self = core::f64::consts::LN_2

Source§

const LN_10: Self = core::f64::consts::LN_10

Source§

type Raw = u64

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§