Trait funty::IsFloat[][src]

pub trait IsFloat: IsNumber + LowerExp + UpperExp + Neg + From<f32> + From<i8> + From<i16> + From<u8> + From<u16> {
    type Raw: IsUnsigned;

    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;

    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; }

Declare that a type is a floating-point number.

Associated Types

type Raw: IsUnsigned[src]

The unsigned integer type of the same width as Self.

Loading content...

Associated Constants

const RADIX: u32[src]

The radix or base of the internal representation of f32.

const MANTISSA_DIGITS: u32[src]

Number of significant digits in base 2.

const DIGITS: u32[src]

Approximate number of significant digits in base 10.

const EPSILON: Self[src]

Machine epsilon value for f32.

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

const MIN: Self[src]

Smallest finite f32 value.

const MIN_POSITIVE: Self[src]

Smallest positive normal f32 value.

const MAX: Self[src]

Largest finite f32 value.

const MIN_EXP: i32[src]

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

const MAX_EXP: i32[src]

Maximum possible power of 2 exponent.

const MIN_10_EXP: i32[src]

Minimum possible normal power of 10 exponent.

const MAX_10_EXP: i32[src]

Maximum possible power of 10 exponent.

const NAN: Self[src]

Not a Number (NaN).

const INFINITY: Self[src]

Infinity (∞).

const NEG_INFINITY: Self[src]

Negative infinity (−∞).

const PI: Self[src]

Archimedes’ constant (π)

const FRAC_PI_2: Self[src]

π/2

const FRAC_PI_3: Self[src]

π/3

const FRAC_PI_4: Self[src]

π/4

const FRAC_PI_6: Self[src]

π/6

const FRAC_PI_8: Self[src]

π/8

const FRAC_1_PI: Self[src]

1/π

const FRAC_2_PI: Self[src]

2/π

const FRAC_2_SQRT_PI: Self[src]

2/sqrt(π)

const SQRT_2: Self[src]

sqrt(2)

const FRAC_1_SQRT_2: Self[src]

1/sqrt(2)

const E: Self[src]

Euler’s number (e)

const LOG2_E: Self[src]

log2(e)

const LOG10_E: Self[src]

log10(e)

const LN_2: Self[src]

ln(2)

const LN_10: Self[src]

ln(10)

Loading content...

Required methods

fn is_nan(self) -> bool[src]

Returns true if this value is NaN.

fn is_infinite(self) -> bool[src]

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

fn is_finite(self) -> bool[src]

Returns true if this number is neither infinite nor NaN.

fn is_normal(self) -> bool[src]

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

fn classify(self) -> FpCategory[src]

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.

fn is_sign_positive(self) -> bool[src]

Returns true if self has a positive sign, including +0.0, NaNs with positive sign bit and positive infinity.

fn is_sign_negative(self) -> bool[src]

Returns true if self has a negative sign, including -0.0, NaNs with negative sign bit and negative infinity.

fn recip(self) -> Self[src]

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

fn to_degrees(self) -> Self[src]

Converts radians to degrees.

fn to_radians(self) -> Self[src]

Converts degrees to radians.

fn max(self, other: Self) -> Self[src]

Returns the maximum of the two numbers.

fn min(self, other: Self) -> Self[src]

Returns the minimum of the two numbers.

fn to_bits(self) -> Self::Raw[src]

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.

fn from_bits(bits: Self::Raw) -> Self[src]

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.

Loading content...

Implementors

impl IsFloat for f32[src]

type Raw = u32

impl IsFloat for f64[src]

type Raw = u64

Loading content...