Float

Trait Float 

Source
pub unsafe trait Float
where Self: SealedFloat + 'static + Any + Copy + Debug + Default + From<i8> + From<u8> + PartialEq + PartialOrd + RefUnwindSafe + Send + Sync + Unpin + UnwindSafe + Add<Output = Self> + Div<Output = Self> + Mul<Output = Self> + Neg<Output = Self> + Rem<Output = Self> + Sub<Output = Self> + AddAssign + DivAssign + MulAssign + RemAssign + SubAssign,
{ type Bytes: Array<Scalar = u8>; type Bits: Uint;
Show 29 associated constants and 33 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 INFINITY: Self; const NEG_INFINITY: Self; const NAN: Self; const E: Self; const PI: Self; const TAU: Self; const LOG2_10: Self; const LOG2_E: Self; const LN_2: Self; const LN_10: Self; const LOG10_2: Self; const LOG10_E: Self; const SQRT_2: Self; const FRAC_1_PI: Self; const FRAC_1_SQRT_2: Self; const FRAC_2_PI: Self; const FRAC_2_SQRT_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; // Required methods fn from_f16(value: f16) -> Self; fn from_f64_lossy(value: f64) -> Self; fn from_f128_lossy(value: f128) -> Self; fn from_u8(value: u8) -> Self; fn from_i8(value: i8) -> Self; fn from_ne_bytes(bytes: Self::Bytes) -> Self; fn from_le_bytes(bytes: Self::Bytes) -> Self; fn from_be_bytes(bytes: Self::Bytes) -> Self; fn from_bits(bits: Self::Bits) -> Self; fn abs(self) -> Self; fn recip(self) -> Self; fn midpoint(self, other: Self) -> Self; fn to_radians(self) -> Self; fn to_degrees(self) -> Self; fn next_down(self) -> Self; fn next_up(self) -> Self; fn signum(self) -> Self; fn copysign(self, sign: Self) -> Self; fn classify(self) -> FpCategory; fn is_nan(self) -> bool; fn is_infinite(self) -> bool; fn is_finite(self) -> bool; fn is_normal(self) -> bool; fn is_subnormal(self) -> bool; fn is_sign_negative(self) -> bool; fn is_sign_positive(self) -> bool; fn clamp(self, min: Self, max: Self) -> Self; fn total_cmp(&self, rhs: &Self) -> Ordering; unsafe fn to_int_unchecked<T>(self) -> T where Self: FloatToInt<T>; fn to_bits(self) -> Self::Bits; fn to_ne_bytes(self) -> Self::Bytes; fn to_le_bytes(self) -> Self::Bytes; fn to_be_bytes(self) -> Self::Bytes;
}
Expand description

A generic, floating-point real.

This trait abstracts the interfaces defined by f16, f32, f64, and f128 so that these may be used as a single type.

The following traits are not required due to some floating-point types not implementing them:

  • Display: Not implement by f128;
  • From<f16>: Not implement by f32;
  • FromStr: Not implement by f128;
  • LowerExp: Not implement by f128;
  • Product: Not implement by f16 or f128;
  • Sum: Not implement by f16 or f128;
  • UpperExp: Not implement by f128.

These trait will be required when standard support arrives.

See also FloatLeast32 and FloatLeast64. See also StdFloat.

§Safety

Bits must be an unsigned, integral type of the same width as Self so that transmutations between the two is always valid.

Furthermore, all items must behave exactly as their standard counterparts.

Required Associated Constants§

Source

const RADIX: u32

Source

const MANTISSA_DIGITS: u32

Source

const DIGITS: u32

Source

const EPSILON: Self

Source

const MIN: Self

See f64::MIN.

Source

const MIN_POSITIVE: Self

Source

const MAX: Self

See f64::MAX.

Source

const INFINITY: Self

Source

const NEG_INFINITY: Self

Source

const NAN: Self

See f64::NAN.

Source

const E: Self

See f64::E.

Source

const PI: Self

See f64::PI.

Source

const TAU: Self

See f64::TAU.

Source

const LOG2_10: Self

Source

const LOG2_E: Self

Source

const LN_2: Self

See f64::LN_2.

Source

const LN_10: Self

Source

const LOG10_2: Self

Source

const LOG10_E: Self

Source

const SQRT_2: Self

Source

const FRAC_1_PI: Self

Source

const FRAC_1_SQRT_2: Self

Source

const FRAC_2_PI: Self

Source

const FRAC_2_SQRT_PI: Self

Source

const FRAC_PI_2: Self

Source

const FRAC_PI_3: Self

Source

const FRAC_PI_4: Self

Source

const FRAC_PI_6: Self

Source

const FRAC_PI_8: Self

Required Associated Types§

Source

type Bytes: Array<Scalar = u8>

The array type that represents the bytes of this type.

Source

type Bits: Uint

The scalar type that represents the bits of this type.

Required Methods§

Source

fn from_f16(value: f16) -> Self

Available on crate feature f16 only.

Losslessly constructs a new, floating-point real from an f16 value.

Source

fn from_f64_lossy(value: f64) -> Self

Lossily constructs a new, floating-point real from an f64 value.

The value value is transformed into the destination type on a best-case basis:

  • Non-numbers are preserved (except their payloads);
  • Values less than MIN or greater than MAX become negative infinity or positive infinity, respectively;
  • Finite values in range are truncated to fit.

Note that when f128 stabilises (see #116909), users of this function should prepare for its removal.

Source

fn from_f128_lossy(value: f128) -> Self

Available on crate feature f128 only.

Lossily constructs a new, floating-point real from an f128 value.

See also from_f64_lossy.

Source

fn from_u8(value: u8) -> Self

Losslessly constructs a new, floating-point real from a u8 value.

Source

fn from_i8(value: i8) -> Self

Losslessly constructs a new, floating-point real from an i8 value.

Source

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source

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

Source

fn abs(self) -> Self

See f64::abs.

Source

fn recip(self) -> Self

Source

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

Source

fn to_radians(self) -> Self

Source

fn to_degrees(self) -> Self

Source

fn next_down(self) -> Self

Source

fn next_up(self) -> Self

Source

fn signum(self) -> Self

Source

fn copysign(self, sign: Self) -> Self

Source

fn classify(self) -> FpCategory

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 is_subnormal(self) -> bool

Source

fn is_sign_negative(self) -> bool

Source

fn is_sign_positive(self) -> bool

Source

fn clamp(self, min: Self, max: Self) -> Self

Source

fn total_cmp(&self, rhs: &Self) -> Ordering

Source

unsafe fn to_int_unchecked<T>(self) -> T
where Self: FloatToInt<T>,

Source

fn to_bits(self) -> Self::Bits

Source

fn to_ne_bytes(self) -> Self::Bytes

Source

fn to_le_bytes(self) -> Self::Bytes

Source

fn to_be_bytes(self) -> Self::Bytes

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 Float for f16

Available on crate feature f16 only.
Source§

const RADIX: u32 = 2u32

Source§

const MANTISSA_DIGITS: u32 = 11u32

Source§

const DIGITS: u32 = 3u32

Source§

const EPSILON: Self = 9.7656E-4f16

Source§

const MIN: Self = -65504f16

Source§

const MIN_POSITIVE: Self = 6.1035E-5f16

Source§

const MAX: Self = 65504f16

Source§

const INFINITY: Self = +Inf_f16

Source§

const NEG_INFINITY: Self = -Inf_f16

Source§

const NAN: Self = NaN_f16

Source§

const E: Self = 2.7188f16

Source§

const PI: Self = 3.1406f16

Source§

const TAU: Self = 6.2813f16

Source§

const LOG2_10: Self = 3.3223f16

Source§

const LOG2_E: Self = 1.4424f16

Source§

const LN_2: Self = 0.69336f16

Source§

const LN_10: Self = 2.3027f16

Source§

const LOG10_2: Self = 0.30103f16

Source§

const LOG10_E: Self = 0.43433f16

Source§

const SQRT_2: Self = 1.4141f16

Source§

const FRAC_1_PI: Self = 0.31836f16

Source§

const FRAC_1_SQRT_2: Self = 0.70703f16

Source§

const FRAC_2_PI: Self = 0.63672f16

Source§

const FRAC_2_SQRT_PI: Self = 1.1279f16

Source§

const FRAC_PI_2: Self = 1.5703f16

Source§

const FRAC_PI_3: Self = 1.0469f16

Source§

const FRAC_PI_4: Self = 0.78515f16

Source§

const FRAC_PI_6: Self = 0.52344f16

Source§

const FRAC_PI_8: Self = 0.39258f16

Source§

type Bytes = [u8; 2]

Source§

type Bits = u16

Source§

fn from_f16(value: f16) -> Self

Source§

fn from_f64_lossy(value: f64) -> Self

Source§

fn from_f128_lossy(value: f128) -> Self

Available on crate feature f128 only.
Source§

fn from_u8(value: u8) -> Self

Source§

fn from_i8(value: i8) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

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

Source§

fn abs(self) -> Self

Source§

fn recip(self) -> Self

Source§

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

Source§

fn to_radians(self) -> Self

Source§

fn to_degrees(self) -> Self

Source§

fn next_down(self) -> Self

Source§

fn next_up(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn copysign(self, sign: Self) -> Self

Source§

fn classify(self) -> FpCategory

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 is_subnormal(self) -> bool

Source§

fn is_sign_negative(self) -> bool

Source§

fn is_sign_positive(self) -> bool

Source§

fn clamp(self, min: Self, max: Self) -> Self

Source§

fn total_cmp(&self, rhs: &Self) -> Ordering

Source§

unsafe fn to_int_unchecked<T>(self) -> T
where Self: FloatToInt<T>,

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_bits(self) -> Self::Bits

Source§

impl Float for f32

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 INFINITY: Self = +Inf_f32

Source§

const NEG_INFINITY: Self = -Inf_f32

Source§

const NAN: Self = NaN_f32

Source§

const E: Self = 2.71828175f32

Source§

const PI: Self = 3.14159274f32

Source§

const TAU: Self = 6.28318548f32

Source§

const LOG2_10: Self = 3.32192802f32

Source§

const LOG2_E: Self = 1.44269502f32

Source§

const LN_2: Self = 0.693147182f32

Source§

const LN_10: Self = 2.30258512f32

Source§

const LOG10_2: Self = 0.30103001f32

Source§

const LOG10_E: Self = 0.434294492f32

Source§

const SQRT_2: Self = 1.41421354f32

Source§

const FRAC_1_PI: Self = 0.318309873f32

Source§

const FRAC_1_SQRT_2: Self = 0.707106769f32

Source§

const FRAC_2_PI: Self = 0.636619746f32

Source§

const FRAC_2_SQRT_PI: Self = 1.12837923f32

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§

type Bytes = [u8; 4]

Source§

type Bits = u32

Source§

fn from_f16(value: f16) -> Self

Available on crate feature f16 only.
Source§

fn from_f64_lossy(value: f64) -> Self

Source§

fn from_f128_lossy(value: f128) -> Self

Available on crate feature f128 only.
Source§

fn from_u8(value: u8) -> Self

Source§

fn from_i8(value: i8) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

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

Source§

fn abs(self) -> Self

Source§

fn recip(self) -> Self

Source§

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

Source§

fn to_radians(self) -> Self

Source§

fn to_degrees(self) -> Self

Source§

fn next_down(self) -> Self

Source§

fn next_up(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn copysign(self, sign: Self) -> Self

Source§

fn classify(self) -> FpCategory

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 is_subnormal(self) -> bool

Source§

fn is_sign_negative(self) -> bool

Source§

fn is_sign_positive(self) -> bool

Source§

fn clamp(self, min: Self, max: Self) -> Self

Source§

fn total_cmp(&self, rhs: &Self) -> Ordering

Source§

unsafe fn to_int_unchecked<T>(self) -> T
where Self: FloatToInt<T>,

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_bits(self) -> Self::Bits

Source§

impl Float for f64

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 INFINITY: Self = +Inf_f64

Source§

const NEG_INFINITY: Self = -Inf_f64

Source§

const NAN: Self = NaN_f64

Source§

const E: Self = 2.7182818284590451f64

Source§

const PI: Self = 3.1415926535897931f64

Source§

const TAU: Self = 6.2831853071795862f64

Source§

const LOG2_10: Self = 3.3219280948873622f64

Source§

const LOG2_E: Self = 1.4426950408889634f64

Source§

const LN_2: Self = 0.69314718055994529f64

Source§

const LN_10: Self = 2.3025850929940459f64

Source§

const LOG10_2: Self = 0.3010299956639812f64

Source§

const LOG10_E: Self = 0.43429448190325182f64

Source§

const SQRT_2: Self = 1.4142135623730951f64

Source§

const FRAC_1_PI: Self = 0.31830988618379069f64

Source§

const FRAC_1_SQRT_2: Self = 0.70710678118654757f64

Source§

const FRAC_2_PI: Self = 0.63661977236758138f64

Source§

const FRAC_2_SQRT_PI: Self = 1.1283791670955126f64

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§

type Bytes = [u8; 8]

Source§

type Bits = u64

Source§

fn from_f16(value: f16) -> Self

Available on crate feature f16 only.
Source§

fn from_f64_lossy(value: f64) -> Self

Source§

fn from_f128_lossy(value: f128) -> Self

Available on crate feature f128 only.
Source§

fn from_u8(value: u8) -> Self

Source§

fn from_i8(value: i8) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

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

Source§

fn abs(self) -> Self

Source§

fn recip(self) -> Self

Source§

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

Source§

fn to_radians(self) -> Self

Source§

fn to_degrees(self) -> Self

Source§

fn next_down(self) -> Self

Source§

fn next_up(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn copysign(self, sign: Self) -> Self

Source§

fn classify(self) -> FpCategory

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 is_subnormal(self) -> bool

Source§

fn is_sign_negative(self) -> bool

Source§

fn is_sign_positive(self) -> bool

Source§

fn clamp(self, min: Self, max: Self) -> Self

Source§

fn total_cmp(&self, rhs: &Self) -> Ordering

Source§

unsafe fn to_int_unchecked<T>(self) -> T
where Self: FloatToInt<T>,

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_bits(self) -> Self::Bits

Source§

impl Float for f128

Available on crate feature f128 only.
Source§

const RADIX: u32 = 2u32

Source§

const MANTISSA_DIGITS: u32 = 113u32

Source§

const DIGITS: u32 = 33u32

Source§

const EPSILON: Self = 1.92592994438723585305597794258492732E-34f128

Source§

const MIN: Self = -1.18973149535723176508575932662800702E+4932f128

Source§

const MIN_POSITIVE: Self = 3.3621031431120935062626778173217526E-4932f128

Source§

const MAX: Self = 1.18973149535723176508575932662800702E+4932f128

Source§

const INFINITY: Self = +Inf_f128

Source§

const NEG_INFINITY: Self = -Inf_f128

Source§

const NAN: Self = NaN_f128

Source§

const E: Self = 2.71828182845904523536028747135266231f128

Source§

const PI: Self = 3.1415926535897932384626433832795028f128

Source§

const TAU: Self = 6.28318530717958647692528676655900559f128

Source§

const LOG2_10: Self = 3.32192809488736234787031942948939029f128

Source§

const LOG2_E: Self = 1.44269504088896340735992468100189204f128

Source§

const LN_2: Self = 0.693147180559945309417232121458176575f128

Source§

const LN_10: Self = 2.30258509299404568401799145468436418f128

Source§

const LOG10_2: Self = 0.30102999566398119521373889472449302f128

Source§

const LOG10_E: Self = 0.434294481903251827651128918916605096f128

Source§

const SQRT_2: Self = 1.41421356237309504880168872420969798f128

Source§

const FRAC_1_PI: Self = 0.318309886183790671537767526745028737f128

Source§

const FRAC_1_SQRT_2: Self = 0.707106781186547524400844362104848992f128

Source§

const FRAC_2_PI: Self = 0.636619772367581343075535053490057474f128

Source§

const FRAC_2_SQRT_PI: Self = 1.12837916709551257389615890312154526f128

Source§

const FRAC_PI_2: Self = 1.5707963267948966192313216916397514f128

Source§

const FRAC_PI_3: Self = 1.04719755119659774615421446109316766f128

Source§

const FRAC_PI_4: Self = 0.785398163397448309615660845819875699f128

Source§

const FRAC_PI_6: Self = 0.523598775598298873077107230546583832f128

Source§

const FRAC_PI_8: Self = 0.39269908169872415480783042290993785f128

Source§

type Bytes = [u8; 16]

Source§

type Bits = u128

Source§

fn from_f16(value: f16) -> Self

Available on crate feature f16 only.
Source§

fn from_f64_lossy(value: f64) -> Self

Source§

fn from_f128_lossy(value: f128) -> Self

Source§

fn from_u8(value: u8) -> Self

Source§

fn from_i8(value: i8) -> Self

Source§

fn from_ne_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_le_bytes(bytes: Self::Bytes) -> Self

Source§

fn from_be_bytes(bytes: Self::Bytes) -> Self

Source§

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

Source§

fn abs(self) -> Self

Source§

fn recip(self) -> Self

Source§

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

Source§

fn to_radians(self) -> Self

Source§

fn to_degrees(self) -> Self

Source§

fn next_down(self) -> Self

Source§

fn next_up(self) -> Self

Source§

fn signum(self) -> Self

Source§

fn copysign(self, sign: Self) -> Self

Source§

fn classify(self) -> FpCategory

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 is_subnormal(self) -> bool

Source§

fn is_sign_negative(self) -> bool

Source§

fn is_sign_positive(self) -> bool

Source§

fn clamp(self, min: Self, max: Self) -> Self

Source§

fn total_cmp(&self, rhs: &Self) -> Ordering

Source§

unsafe fn to_int_unchecked<T>(self) -> T
where Self: FloatToInt<T>,

Source§

fn to_ne_bytes(self) -> Self::Bytes

Source§

fn to_le_bytes(self) -> Self::Bytes

Source§

fn to_be_bytes(self) -> Self::Bytes

Source§

fn to_bits(self) -> Self::Bits

Implementors§