Trait Float

Source
pub trait Float:
    Copy
    + Debug
    + PartialEq
    + PartialOrd
    + AddAssign
    + MulAssign
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Div<Output = Self>
    + Rem<Output = Self>
    + Neg<Output = Self>
    + 'static {
    type Int: Int<OtherSign = Self::SignedInt, Unsigned = Self::Int>;
    type SignedInt: Int + MinInt<OtherSign = Self::Int, Unsigned = Self::Int> + Neg<Output = Self::SignedInt>;
Show 27 associated constants and 19 methods const ZERO: Self; const NEG_ZERO: Self; const ONE: Self; const NEG_ONE: Self; const INFINITY: Self; const NEG_INFINITY: Self; const NAN: Self; const NEG_NAN: Self; const MAX: Self; const MIN: Self; const EPSILON: Self; const PI: Self; const NEG_PI: Self; const FRAC_PI_2: Self; const MIN_POSITIVE_NORMAL: Self; const BITS: u32; const SIG_BITS: u32; const SIGN_MASK: Self::Int; const SIG_MASK: Self::Int; const EXP_MASK: Self::Int; const IMPLICIT_BIT: Self::Int; const EXP_BITS: u32 = _; const EXP_SAT: u32 = _; const EXP_BIAS: u32 = _; const EXP_MAX: i32 = _; const EXP_MIN: i32 = _; const EXP_MIN_SUBNORM: i32 = _; // Required methods fn to_bits(self) -> Self::Int; fn is_nan(self) -> bool; fn is_infinite(self) -> bool; fn is_sign_negative(self) -> bool; fn from_bits(a: Self::Int) -> Self; fn abs(self) -> Self; fn copysign(self, other: Self) -> Self; fn fma(self, y: Self, z: Self) -> Self; fn normalize(significand: Self::Int) -> (i32, Self::Int); // Provided methods fn to_bits_signed(self) -> Self::SignedInt { ... } fn biteq(self, rhs: Self) -> bool { ... } fn eq_repr(self, rhs: Self) -> bool { ... } fn is_sign_positive(self) -> bool { ... } fn is_subnormal(self) -> bool { ... } fn ex(self) -> u32 { ... } fn exp_unbiased(self) -> i32 { ... } fn frac(self) -> Self::Int { ... } fn from_parts(negative: bool, exponent: u32, significand: Self::Int) -> Self { ... } fn signum(self) -> Self { ... }
}
Expand description

Trait for some basic operations on floats

Required Associated Constants§

Source

const ZERO: Self

Source

const NEG_ZERO: Self

Source

const ONE: Self

Source

const NEG_ONE: Self

Source

const INFINITY: Self

Source

const NEG_INFINITY: Self

Source

const NAN: Self

Source

const NEG_NAN: Self

Source

const MAX: Self

Source

const MIN: Self

Source

const EPSILON: Self

Source

const PI: Self

Source

const NEG_PI: Self

Source

const FRAC_PI_2: Self

Source

const MIN_POSITIVE_NORMAL: Self

Source

const BITS: u32

The bitwidth of the float type

Source

const SIG_BITS: u32

The bitwidth of the significand

Source

const SIGN_MASK: Self::Int

A mask for the sign bit

Source

const SIG_MASK: Self::Int

A mask for the significand

Source

const EXP_MASK: Self::Int

A mask for the exponent

Source

const IMPLICIT_BIT: Self::Int

The implicit bit of the float format

Provided Associated Constants§

Source

const EXP_BITS: u32 = _

The bitwidth of the exponent

Source

const EXP_SAT: u32 = _

The saturated (maximum bitpattern) value of the exponent, i.e. the infinite representation.

This shifted fully right, use EXP_MASK for the shifted value.

Source

const EXP_BIAS: u32 = _

The exponent bias value

Source

const EXP_MAX: i32 = _

Maximum unbiased exponent value.

Source

const EXP_MIN: i32 = _

Minimum NORMAL unbiased exponent value.

Source

const EXP_MIN_SUBNORM: i32 = _

Minimum subnormal exponent value.

Required Associated Types§

Source

type Int: Int<OtherSign = Self::SignedInt, Unsigned = Self::Int>

A uint of the same width as the float

Source

type SignedInt: Int + MinInt<OtherSign = Self::Int, Unsigned = Self::Int> + Neg<Output = Self::SignedInt>

A int of the same width as the float

Required Methods§

Source

fn to_bits(self) -> Self::Int

Returns self transmuted to Self::Int

Source

fn is_nan(self) -> bool

Returns true if the value is NaN.

Source

fn is_infinite(self) -> bool

Returns true if the value is +inf or -inf.

Source

fn is_sign_negative(self) -> bool

Returns true if the sign is negative. Extracts the sign bit regardless of zero or NaN.

Source

fn from_bits(a: Self::Int) -> Self

Returns a Self::Int transmuted back to Self

Source

fn abs(self) -> Self

Source

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

Returns a number composed of the magnitude of self and the sign of sign.

Source

fn fma(self, y: Self, z: Self) -> Self

Fused multiply add, rounding once.

Source

fn normalize(significand: Self::Int) -> (i32, Self::Int)

Returns (normalized exponent, normalized significand)

Provided Methods§

Source

fn to_bits_signed(self) -> Self::SignedInt

Returns self transmuted to Self::SignedInt

Source

fn biteq(self, rhs: Self) -> bool

Check bitwise equality.

Source

fn eq_repr(self, rhs: Self) -> bool

Checks if two floats have the same bit representation. Except for NaNs! NaN can be represented in multiple different ways.

This method returns true if two NaNs are compared. Use biteq instead if NaN should not be treated separately.

Source

fn is_sign_positive(self) -> bool

Returns true if the sign is positive. Extracts the sign bit regardless of zero or NaN.

Source

fn is_subnormal(self) -> bool

Returns if self is subnormal.

Source

fn ex(self) -> u32

Returns the exponent, not adjusting for bias, not accounting for subnormals or zero.

Source

fn exp_unbiased(self) -> i32

Extract the exponent and adjust it for bias, not accounting for subnormals or zero.

Source

fn frac(self) -> Self::Int

Returns the significand with no implicit bit (or the “fractional” part)

Source

fn from_parts(negative: bool, exponent: u32, significand: Self::Int) -> Self

Constructs a Self from its parts. Inputs are treated as bits and shifted into position.

Source

fn signum(self) -> Self

Returns a number that represents the sign of self.

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 f32

Source§

const ZERO: Self = 0f32

Source§

const NEG_ZERO: Self = -0f32

Source§

const ONE: Self = 1f32

Source§

const NEG_ONE: Self = -1f32

Source§

const INFINITY: Self = +Inf_f32

Source§

const NEG_INFINITY: Self = -Inf_f32

Source§

const NAN: Self = NaN_f32

Source§

const NEG_NAN: Self = NaN_f32

Source§

const MAX: Self = 3.40282347E+38f32

Source§

const MIN: Self = -3.40282347E+38f32

Source§

const EPSILON: Self = 1.1920929E-7f32

Source§

const MIN_POSITIVE_NORMAL: Self = 1.17549435E-38f32

Source§

const PI: Self = 3.14159274f32

Source§

const NEG_PI: Self = -3.14159274f32

Source§

const FRAC_PI_2: Self = 1.57079637f32

Source§

const BITS: u32 = 32u32

Source§

const SIG_BITS: u32 = 23u32

Source§

const SIGN_MASK: Self::Int = {transmute(0x80000000): <f32 as math::support::float_traits::Float>::Int}

Source§

const SIG_MASK: Self::Int = {transmute(0x007fffff): <f32 as math::support::float_traits::Float>::Int}

Source§

const EXP_MASK: Self::Int = {transmute(0x7f800000): <f32 as math::support::float_traits::Float>::Int}

Source§

const IMPLICIT_BIT: Self::Int = {transmute(0x00800000): <f32 as math::support::float_traits::Float>::Int}

Source§

type Int = u32

Source§

type SignedInt = i32

Source§

fn to_bits(self) -> Self::Int

Source§

fn is_nan(self) -> bool

Source§

fn is_infinite(self) -> bool

Source§

fn is_sign_negative(self) -> bool

Source§

fn from_bits(a: Self::Int) -> Self

Source§

fn abs(self) -> Self

Source§

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

Source§

fn fma(self, y: Self, z: Self) -> Self

Source§

fn normalize(significand: Self::Int) -> (i32, Self::Int)

Source§

impl Float for f64

Source§

const ZERO: Self = 0f64

Source§

const NEG_ZERO: Self = -0f64

Source§

const ONE: Self = 1f64

Source§

const NEG_ONE: Self = -1f64

Source§

const INFINITY: Self = +Inf_f64

Source§

const NEG_INFINITY: Self = -Inf_f64

Source§

const NAN: Self = NaN_f64

Source§

const NEG_NAN: Self = NaN_f64

Source§

const MAX: Self = 1.7976931348623157E+308f64

Source§

const MIN: Self = -1.7976931348623157E+308f64

Source§

const EPSILON: Self = 2.2204460492503131E-16f64

Source§

const MIN_POSITIVE_NORMAL: Self = 2.2250738585072014E-308f64

Source§

const PI: Self = 3.1415926535897931f64

Source§

const NEG_PI: Self = -3.1415926535897931f64

Source§

const FRAC_PI_2: Self = 1.5707963267948966f64

Source§

const BITS: u32 = 64u32

Source§

const SIG_BITS: u32 = 52u32

Source§

const SIGN_MASK: Self::Int = {transmute(0x8000000000000000): <f64 as math::support::float_traits::Float>::Int}

Source§

const SIG_MASK: Self::Int = {transmute(0x000fffffffffffff): <f64 as math::support::float_traits::Float>::Int}

Source§

const EXP_MASK: Self::Int = {transmute(0x7ff0000000000000): <f64 as math::support::float_traits::Float>::Int}

Source§

const IMPLICIT_BIT: Self::Int = {transmute(0x0010000000000000): <f64 as math::support::float_traits::Float>::Int}

Source§

type Int = u64

Source§

type SignedInt = i64

Source§

fn to_bits(self) -> Self::Int

Source§

fn is_nan(self) -> bool

Source§

fn is_infinite(self) -> bool

Source§

fn is_sign_negative(self) -> bool

Source§

fn from_bits(a: Self::Int) -> Self

Source§

fn abs(self) -> Self

Source§

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

Source§

fn fma(self, y: Self, z: Self) -> Self

Source§

fn normalize(significand: Self::Int) -> (i32, Self::Int)

Implementors§