pub unsafe trait Floatwhere
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 byf128;From<f16>: Not implement byf32;FromStr: Not implement byf128;LowerExp: Not implement byf128;Product: Not implement byf16orf128;Sum: Not implement byf16orf128;UpperExp: Not implement byf128.
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§
Sourceconst RADIX: u32
const RADIX: u32
See f64::RADIX.
Sourceconst MANTISSA_DIGITS: u32
const MANTISSA_DIGITS: u32
See f64::MANTISSA_DIGITS.
Sourceconst DIGITS: u32
const DIGITS: u32
See f64::DIGITS.
Sourceconst EPSILON: Self
const EPSILON: Self
See f64::EPSILON.
Sourceconst MIN_POSITIVE: Self
const MIN_POSITIVE: Self
See f64::MIN_POSITIVE.
Sourceconst INFINITY: Self
const INFINITY: Self
See f64::INFINITY.
Sourceconst NEG_INFINITY: Self
const NEG_INFINITY: Self
See f64::NEG_INFINITY.
Sourceconst LOG2_10: Self
const LOG2_10: Self
See f64::LOG2_10.
Sourceconst LOG2_E: Self
const LOG2_E: Self
See f64::LOG2_E.
Sourceconst LN_10: Self
const LN_10: Self
See f64::LN_10.
Sourceconst LOG10_2: Self
const LOG10_2: Self
See f64::LOG10_2.
Sourceconst LOG10_E: Self
const LOG10_E: Self
See f64::LOG10_E.
Sourceconst SQRT_2: Self
const SQRT_2: Self
See f64::SQRT_2.
Sourceconst FRAC_1_PI: Self
const FRAC_1_PI: Self
See f64::FRAC_1_PI.
Sourceconst FRAC_1_SQRT_2: Self
const FRAC_1_SQRT_2: Self
See f64::FRAC_1_SQRT_2.
Sourceconst FRAC_2_PI: Self
const FRAC_2_PI: Self
See f64::FRAC_2_PI.
Sourceconst FRAC_2_SQRT_PI: Self
const FRAC_2_SQRT_PI: Self
See f64::FRAC_2_SQRT_PI.
Sourceconst FRAC_PI_2: Self
const FRAC_PI_2: Self
See f64::FRAC_PI_2.
Sourceconst FRAC_PI_3: Self
const FRAC_PI_3: Self
See f64::FRAC_PI_3.
Sourceconst FRAC_PI_4: Self
const FRAC_PI_4: Self
See f64::FRAC_PI_4.
Sourceconst FRAC_PI_6: Self
const FRAC_PI_6: Self
See f64::FRAC_PI_6.
Sourceconst FRAC_PI_8: Self
const FRAC_PI_8: Self
See f64::FRAC_PI_8.
Required Associated Types§
Required Methods§
Sourcefn from_f16(value: f16) -> Self
Available on crate feature f16 only.
fn from_f16(value: f16) -> Self
f16 only.Losslessly constructs a new, floating-point real from an f16 value.
Sourcefn from_f64_lossy(value: f64) -> Self
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
MINor greater thanMAXbecome 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.
Sourcefn from_f128_lossy(value: f128) -> Self
Available on crate feature f128 only.
fn from_f128_lossy(value: f128) -> Self
f128 only.Lossily constructs a new, floating-point real from an f128 value.
See also from_f64_lossy.
Sourcefn from_u8(value: u8) -> Self
fn from_u8(value: u8) -> Self
Losslessly constructs a new, floating-point real from a u8 value.
Sourcefn from_i8(value: i8) -> Self
fn from_i8(value: i8) -> Self
Losslessly constructs a new, floating-point real from an i8 value.
Sourcefn from_ne_bytes(bytes: Self::Bytes) -> Self
fn from_ne_bytes(bytes: Self::Bytes) -> Self
See f64::from_ne_bytes.
Sourcefn from_le_bytes(bytes: Self::Bytes) -> Self
fn from_le_bytes(bytes: Self::Bytes) -> Self
See f64::from_le_bytes.
Sourcefn from_be_bytes(bytes: Self::Bytes) -> Self
fn from_be_bytes(bytes: Self::Bytes) -> Self
See f64::from_be_bytes.
Sourcefn from_bits(bits: Self::Bits) -> Self
fn from_bits(bits: Self::Bits) -> Self
See f64::from_bits.
Sourcefn recip(self) -> Self
fn recip(self) -> Self
See f64::recip.
Sourcefn midpoint(self, other: Self) -> Self
fn midpoint(self, other: Self) -> Self
See f64::midpoint.
Sourcefn to_radians(self) -> Self
fn to_radians(self) -> Self
See f64::to_radians.
Sourcefn to_degrees(self) -> Self
fn to_degrees(self) -> Self
See f64::to_degrees.
Sourcefn next_down(self) -> Self
fn next_down(self) -> Self
See f64::next_down.
Sourcefn next_up(self) -> Self
fn next_up(self) -> Self
See f64::next_up.
Sourcefn signum(self) -> Self
fn signum(self) -> Self
See f64::signum.
Sourcefn copysign(self, sign: Self) -> Self
fn copysign(self, sign: Self) -> Self
See f64::copysign.
Sourcefn classify(self) -> FpCategory
fn classify(self) -> FpCategory
See f64::classify.
Sourcefn is_nan(self) -> bool
fn is_nan(self) -> bool
See f64::is_nan.
Sourcefn is_infinite(self) -> bool
fn is_infinite(self) -> bool
See f64::is_infinite.
Sourcefn is_finite(self) -> bool
fn is_finite(self) -> bool
See f64::is_finite.
Sourcefn is_normal(self) -> bool
fn is_normal(self) -> bool
See f64::is_normal.
Sourcefn is_subnormal(self) -> bool
fn is_subnormal(self) -> bool
See f64::is_subnormal.
Sourcefn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
Sourcefn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
Sourcefn clamp(self, min: Self, max: Self) -> Self
fn clamp(self, min: Self, max: Self) -> Self
See f64::clamp.
Sourcefn total_cmp(&self, rhs: &Self) -> Ordering
fn total_cmp(&self, rhs: &Self) -> Ordering
See f64::total_cmp.
Sourceunsafe fn to_int_unchecked<T>(self) -> Twhere
Self: FloatToInt<T>,
unsafe fn to_int_unchecked<T>(self) -> Twhere
Self: FloatToInt<T>,
Sourcefn to_bits(self) -> Self::Bits
fn to_bits(self) -> Self::Bits
See f64::to_bits.
Sourcefn to_ne_bytes(self) -> Self::Bytes
fn to_ne_bytes(self) -> Self::Bytes
See f64::to_ne_bytes.
Sourcefn to_le_bytes(self) -> Self::Bytes
fn to_le_bytes(self) -> Self::Bytes
See f64::to_le_bytes.
Sourcefn to_be_bytes(self) -> Self::Bytes
fn to_be_bytes(self) -> Self::Bytes
See f64::to_be_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.
impl Float for f16
f16 only.const RADIX: u32 = 2u32
const MANTISSA_DIGITS: u32 = 11u32
const DIGITS: u32 = 3u32
const EPSILON: Self = 9.7656E-4f16
const MIN: Self = -65504f16
const MIN_POSITIVE: Self = 6.1035E-5f16
const MAX: Self = 65504f16
const INFINITY: Self = +Inf_f16
const NEG_INFINITY: Self = -Inf_f16
const NAN: Self = NaN_f16
const E: Self = 2.7188f16
const PI: Self = 3.1406f16
const TAU: Self = 6.2813f16
const LOG2_10: Self = 3.3223f16
const LOG2_E: Self = 1.4424f16
const LN_2: Self = 0.69336f16
const LN_10: Self = 2.3027f16
const LOG10_2: Self = 0.30103f16
const LOG10_E: Self = 0.43433f16
const SQRT_2: Self = 1.4141f16
const FRAC_1_PI: Self = 0.31836f16
const FRAC_1_SQRT_2: Self = 0.70703f16
const FRAC_2_PI: Self = 0.63672f16
const FRAC_2_SQRT_PI: Self = 1.1279f16
const FRAC_PI_2: Self = 1.5703f16
const FRAC_PI_3: Self = 1.0469f16
const FRAC_PI_4: Self = 0.78515f16
const FRAC_PI_6: Self = 0.52344f16
const FRAC_PI_8: Self = 0.39258f16
type Bytes = [u8; 2]
type Bits = u16
fn from_f16(value: f16) -> Self
fn from_f64_lossy(value: f64) -> Self
Source§fn from_f128_lossy(value: f128) -> Self
fn from_f128_lossy(value: f128) -> Self
f128 only.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) -> Twhere
Self: FloatToInt<T>,
fn to_ne_bytes(self) -> Self::Bytes
fn to_le_bytes(self) -> Self::Bytes
fn to_be_bytes(self) -> Self::Bytes
fn to_bits(self) -> Self::Bits
Source§impl Float for f32
impl Float for f32
const RADIX: u32 = 2u32
const MANTISSA_DIGITS: u32 = 24u32
const DIGITS: u32 = 6u32
const EPSILON: Self = 1.1920929E-7f32
const MIN: Self = -3.40282347E+38f32
const MIN_POSITIVE: Self = 1.17549435E-38f32
const MAX: Self = 3.40282347E+38f32
const INFINITY: Self = +Inf_f32
const NEG_INFINITY: Self = -Inf_f32
const NAN: Self = NaN_f32
const E: Self = 2.71828175f32
const PI: Self = 3.14159274f32
const TAU: Self = 6.28318548f32
const LOG2_10: Self = 3.32192802f32
const LOG2_E: Self = 1.44269502f32
const LN_2: Self = 0.693147182f32
const LN_10: Self = 2.30258512f32
const LOG10_2: Self = 0.30103001f32
const LOG10_E: Self = 0.434294492f32
const SQRT_2: Self = 1.41421354f32
const FRAC_1_PI: Self = 0.318309873f32
const FRAC_1_SQRT_2: Self = 0.707106769f32
const FRAC_2_PI: Self = 0.636619746f32
const FRAC_2_SQRT_PI: Self = 1.12837923f32
const FRAC_PI_2: Self = 1.57079637f32
const FRAC_PI_3: Self = 1.04719758f32
const FRAC_PI_4: Self = 0.785398185f32
const FRAC_PI_6: Self = 0.52359879f32
const FRAC_PI_8: Self = 0.392699093f32
type Bytes = [u8; 4]
type Bits = u32
fn from_f64_lossy(value: f64) -> Self
Source§fn from_f128_lossy(value: f128) -> Self
fn from_f128_lossy(value: f128) -> Self
f128 only.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) -> Twhere
Self: FloatToInt<T>,
fn to_ne_bytes(self) -> Self::Bytes
fn to_le_bytes(self) -> Self::Bytes
fn to_be_bytes(self) -> Self::Bytes
fn to_bits(self) -> Self::Bits
Source§impl Float for f64
impl Float for f64
const RADIX: u32 = 2u32
const MANTISSA_DIGITS: u32 = 53u32
const DIGITS: u32 = 15u32
const EPSILON: Self = 2.2204460492503131E-16f64
const MIN: Self = -1.7976931348623157E+308f64
const MIN_POSITIVE: Self = 2.2250738585072014E-308f64
const MAX: Self = 1.7976931348623157E+308f64
const INFINITY: Self = +Inf_f64
const NEG_INFINITY: Self = -Inf_f64
const NAN: Self = NaN_f64
const E: Self = 2.7182818284590451f64
const PI: Self = 3.1415926535897931f64
const TAU: Self = 6.2831853071795862f64
const LOG2_10: Self = 3.3219280948873622f64
const LOG2_E: Self = 1.4426950408889634f64
const LN_2: Self = 0.69314718055994529f64
const LN_10: Self = 2.3025850929940459f64
const LOG10_2: Self = 0.3010299956639812f64
const LOG10_E: Self = 0.43429448190325182f64
const SQRT_2: Self = 1.4142135623730951f64
const FRAC_1_PI: Self = 0.31830988618379069f64
const FRAC_1_SQRT_2: Self = 0.70710678118654757f64
const FRAC_2_PI: Self = 0.63661977236758138f64
const FRAC_2_SQRT_PI: Self = 1.1283791670955126f64
const FRAC_PI_2: Self = 1.5707963267948966f64
const FRAC_PI_3: Self = 1.0471975511965979f64
const FRAC_PI_4: Self = 0.78539816339744828f64
const FRAC_PI_6: Self = 0.52359877559829893f64
const FRAC_PI_8: Self = 0.39269908169872414f64
type Bytes = [u8; 8]
type Bits = u64
fn from_f64_lossy(value: f64) -> Self
Source§fn from_f128_lossy(value: f128) -> Self
fn from_f128_lossy(value: f128) -> Self
f128 only.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) -> Twhere
Self: FloatToInt<T>,
fn to_ne_bytes(self) -> Self::Bytes
fn to_le_bytes(self) -> Self::Bytes
fn to_be_bytes(self) -> Self::Bytes
fn to_bits(self) -> Self::Bits
Source§impl Float for f128
Available on crate feature f128 only.
impl Float for f128
f128 only.