[][src]Trait funty::IsFloat

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

    pub const RADIX: u32;
    pub const MANTISSA_DIGITS: u32;
    pub const DIGITS: u32;
    pub const EPSILON: Self;
    pub const MIN: Self;
    pub const MIN_POSITIVE: Self;
    pub const MAX: Self;
    pub const MIN_EXP: i32;
    pub const MAX_EXP: i32;
    pub const MIN_10_EXP: i32;
    pub const MAX_10_EXP: i32;
    pub const NAN: Self;
    pub const INFINITY: Self;
    pub const NEG_INFINITY: Self;
    pub const PI: Self;
    pub const FRAC_PI_2: Self;
    pub const FRAC_PI_3: Self;
    pub const FRAC_PI_4: Self;
    pub const FRAC_PI_6: Self;
    pub const FRAC_PI_8: Self;
    pub const FRAC_1_PI: Self;
    pub const FRAC_2_PI: Self;
    pub const FRAC_2_SQRT_PI: Self;
    pub const SQRT_2: Self;
    pub const FRAC_1_SQRT_2: Self;
    pub const E: Self;
    pub const LOG2_E: Self;
    pub const LOG10_E: Self;
    pub const LN_2: Self;
    pub const LN_10: Self;

    pub fn floor(self) -> Self;
pub fn ceil(self) -> Self;
pub fn round(self) -> Self;
pub fn trunc(self) -> Self;
pub fn fract(self) -> Self;
pub fn abs(self) -> Self;
pub fn signum(self) -> Self;
pub fn copysign(self, sign: Self) -> Self;
pub fn mul_add(self, a: Self, b: Self) -> Self;
pub fn div_euclid(self, rhs: Self) -> Self;
pub fn rem_euclid(self, rhs: Self) -> Self;
pub fn powi(self, n: i32) -> Self;
pub fn powf(self, n: Self) -> Self;
pub fn sqrt(self) -> Self;
pub fn exp(self) -> Self;
pub fn exp2(self) -> Self;
pub fn ln(self) -> Self;
pub fn log(self, base: Self) -> Self;
pub fn log2(self) -> Self;
pub fn log10(self) -> Self;
pub fn cbrt(self) -> Self;
pub fn hypot(self, other: Self) -> Self;
pub fn sin(self) -> Self;
pub fn cos(self) -> Self;
pub fn tan(self) -> Self;
pub fn asin(self) -> Self;
pub fn acos(self) -> Self;
pub fn atan(self) -> Self;
pub fn atan2(self, other: Self) -> Self;
pub fn sin_cos(self) -> (Self, Self);
pub fn exp_m1(self) -> Self;
pub fn ln_1p(self) -> Self;
pub fn sinh(self) -> Self;
pub fn cosh(self) -> Self;
pub fn tanh(self) -> Self;
pub fn asinh(self) -> Self;
pub fn acosh(self) -> Self;
pub fn atanh(self) -> Self;
pub fn is_nan(self) -> bool;
pub fn is_infinite(self) -> bool;
pub fn is_finite(self) -> bool;
pub fn is_normal(self) -> bool;
pub fn classify(self) -> FpCategory;
pub fn is_sign_positive(self) -> bool;
pub fn is_sign_negative(self) -> bool;
pub fn recip(self) -> Self;
pub fn to_degrees(self) -> Self;
pub fn to_radians(self) -> Self;
pub fn max(self, other: Self) -> Self;
pub fn min(self, other: Self) -> Self;
pub fn to_bits(self) -> Self::Raw;
pub 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

pub const RADIX: u32[src]

The radix or base of the internal representation of f32.

pub const MANTISSA_DIGITS: u32[src]

Number of significant digits in base 2.

pub const DIGITS: u32[src]

Approximate number of significant digits in base 10.

pub const EPSILON: Self[src]

Machine epsilon value for f32.

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

pub const MIN: Self[src]

Smallest finite f32 value.

pub const MIN_POSITIVE: Self[src]

Smallest positive normal f32 value.

pub const MAX: Self[src]

Largest finite f32 value.

pub const MIN_EXP: i32[src]

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

pub const MAX_EXP: i32[src]

Maximum possible power of 2 exponent.

pub const MIN_10_EXP: i32[src]

Minimum possible normal power of 10 exponent.

pub const MAX_10_EXP: i32[src]

Maximum possible power of 10 exponent.

pub const NAN: Self[src]

Not a Number (NaN).

pub const INFINITY: Self[src]

Infinity (∞).

pub const NEG_INFINITY: Self[src]

Negative infinity (−∞).

pub const PI: Self[src]

Archimedes' constant (π)

pub const FRAC_PI_2: Self[src]

π/2

pub const FRAC_PI_3: Self[src]

π/3

pub const FRAC_PI_4: Self[src]

π/4

pub const FRAC_PI_6: Self[src]

π/6

pub const FRAC_PI_8: Self[src]

π/8

pub const FRAC_1_PI: Self[src]

1/π

pub const FRAC_2_PI: Self[src]

2/π

pub const FRAC_2_SQRT_PI: Self[src]

2/sqrt(π)

pub const SQRT_2: Self[src]

sqrt(2)

pub const FRAC_1_SQRT_2: Self[src]

1/sqrt(2)

pub const E: Self[src]

Euler’s number (e)

pub const LOG2_E: Self[src]

log2(e)

pub const LOG10_E: Self[src]

log10(e)

pub const LN_2: Self[src]

ln(2)

pub const LN_10: Self[src]

ln(10)

Loading content...

Required methods

pub fn floor(self) -> Self[src]

Returns the largest integer less than or equal to a number.

pub fn ceil(self) -> Self[src]

Returns the smallest integer greater than or equal to a number.

pub fn round(self) -> Self[src]

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

pub fn trunc(self) -> Self[src]

Returns the integer part of a number.

pub fn fract(self) -> Self[src]

Returns the fractional part of a number.

pub fn abs(self) -> Self[src]

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

pub fn signum(self) -> Self[src]

Returns a number that represents the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NAN

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

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 of sign is returned.

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

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

Using mul_add can be more performant than an unfused multiply-add if the target architecture has a dedicated fma CPU instruction.

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

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.

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

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) approximatively.

pub fn powi(self, n: i32) -> Self[src]

Raises a number to an integer power.

Using this function is generally faster than using powf

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

Raises a number to a floating point power.

pub fn sqrt(self) -> Self[src]

Returns the square root of a number.

Returns NaN if self is a negative number.

pub fn exp(self) -> Self[src]

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

pub fn exp2(self) -> Self[src]

Returns 2^(self).

pub fn ln(self) -> Self[src]

Returns the natural logarithm of the number.

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

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

The result may 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.

pub fn log2(self) -> Self[src]

Returns the base 2 logarithm of the number.

pub fn log10(self) -> Self[src]

Returns the base 10 logarithm of the number.

pub fn cbrt(self) -> Self[src]

Returns the cubic root of a number.

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

Computes the sine of a number (in radians).

pub fn sin(self) -> Self[src]

Computes the sine of a number (in radians).

pub fn cos(self) -> Self[src]

Computes the cosine of a number (in radians).

pub fn tan(self) -> Self[src]

Computes the tangent of a number (in radians).

pub fn asin(self) -> Self[src]

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].

pub fn acos(self) -> Self[src]

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].

pub fn atan(self) -> Self[src]

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

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

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

  • 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)

pub fn sin_cos(self) -> (Self, Self)[src]

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

pub fn exp_m1(self) -> Self[src]

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

pub fn ln_1p(self) -> Self[src]

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

pub fn sinh(self) -> Self[src]

Hyperbolic sine function.

pub fn cosh(self) -> Self[src]

Hyperbolic cosine function.

pub fn tanh(self) -> Self[src]

Hyperbolic tangent function.

pub fn asinh(self) -> Self[src]

Inverse hyperbolic sine function.

pub fn acosh(self) -> Self[src]

Inverse hyperbolic cosine function.

pub fn atanh(self) -> Self[src]

Inverse hyperbolic tangent function.

pub fn is_nan(self) -> bool[src]

Returns true if this value is NaN.

pub fn is_infinite(self) -> bool[src]

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

pub fn is_finite(self) -> bool[src]

Returns true if this number is neither infinite nor NaN.

pub fn is_normal(self) -> bool[src]

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

pub 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.

pub 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.

pub 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.

pub fn recip(self) -> Self[src]

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

pub fn to_degrees(self) -> Self[src]

Converts radians to degrees.

pub fn to_radians(self) -> Self[src]

Converts degrees to radians.

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

Returns the maximum of the two numbers.

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

Returns the minimum of the two numbers.

pub 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.

pub 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...

Implementations on Foreign Types

impl IsFloat for f32[src]

type Raw = u32

impl IsFloat for f64[src]

type Raw = u64

Loading content...

Implementors

Loading content...