F64

Struct F64 

Source
#[repr(transparent)]
pub struct F64 { pub bits: u64, }
Expand description

A newtype containing the raw bits of an IEEE 754 binary64 floating point number.

Values of this type are hashable and have a well-defined total order: the one given by Self::total_cmp. As a consequence, +0.0 is not equal to -0.0, and NaN compares equal to NaN if both NaN values have exactly the same bit pattern.

Fields§

§bits: u64

The raw bits representing this float value.

Implementations§

Source§

impl F64

Source

pub const fn from_bits(bits: u64) -> Self

Constructs a wrapped float from the raw float bits.

Source

pub const fn to_bits(&self) -> u64

Returns the raw float bits.

Source§

impl F64

Source

pub const fn from_float(float: f64) -> Self

Constructs a wrapped float from a Rust float.

Source

pub const fn to_float(&self) -> f64

Returns the Rust float which this wrapped float represents.

Source§

impl F64

Source

pub const BITS: usize = 64usize

Number of total bits in the representation.

Source

pub const EXP_BITS: usize = 11usize

Number of bits in the exponent representation.

Source

pub const MANTISSA_BITS: usize = 52usize

Number of bits in the mantissa representation.

Source

pub const MANTISSA_DIGITS: usize = 53usize

Number of significant digits in base 2.

Note that the size of the mantissa in the bitwise representation is one smaller than this, since the leading 1 is not stored explicitly.

Source

pub const ZERO: Self

Positive zero (+0.0).

Source

pub const ONE: Self

Positive one (+1.0).

Source

pub const INFINITY: Self

Positive infinity (+∞).

Source

pub const SNAN: Self

Not a Number (NaN) with sign bit 0, is_quiet bit 0, and arbitrary payload.

Source

pub const QNAN: Self

Not a Number (NaN) with sign bit 0, is_quiet bit 1, and arbitrary payload.

Source

pub const NEG_ZERO: Self

Negative zero (−0.0).

Source

pub const NEG_ONE: Self

Negative one (−1.0).

Source

pub const NEG_INFINITY: Self

Negative infinity (−∞).

Source

pub const NEG_SNAN: Self

Not a Number (NaN) with sign bit 1, is_quiet bit 0, and arbitrary payload.

Source

pub const NEG_QNAN: Self

Not a Number (NaN) with sign bit 1, is_quiet bit 1, and arbitrary payload.

Source

pub const MAX: Self

The positive normal value with the greatest possible absolute magnitude.

Source

pub const MIN: Self

The negative normal value with the greatest possible absolute magnitude.

Source

pub const MIN_POSITIVE: Self

The positive normal value with the least possible absolute magnitude.

Source

pub const MAX_NEGATIVE: Self

The negative normal value with the least possible absolute magnitude.

Source

pub const fn is_sign_positive(&self) -> bool

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

Source

pub const fn is_sign_negative(&self) -> bool

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

Source

pub const fn classify(&self) -> FpCategory

Returns the floating point category of the number.

Source

pub const fn is_zero(&self) -> bool

Returns true if the number is +0.0 or -0.0.

Source

pub const fn is_subnormal(&self) -> bool

Returns true if the number is subnormal.

Source

pub const fn is_normal(&self) -> bool

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

Source

pub const fn is_infinite(&self) -> bool

Returns true if the number is subnormal.

Source

pub const fn is_nan(&self) -> bool

Returns true if this value is NaN.

Source

pub const fn is_finite(&self) -> bool

Returns true if this number is neither infinite nor NaN.

Source

pub const fn abs(&self) -> Self

Computes the absolute value of self.

The result is always exact. The result will always test true with Self::is_sign_positive.

Source

pub const fn neg(&self) -> Self

Computes the negation of self.

The result is always exact.

Source

pub const fn signum(&self) -> Self

Returns a number that represents the sign of self.

  • Self::ONE if the number is positive, including +0.0 or +∞
  • Self::NEG_ONE if the number is negative, including -0.0 or -∞
  • self if the number is NaN
Source

pub const fn copysign(&self, sign: Self) -> Self

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

Source

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

Returns the ordering between self and rhs.

Unlike the standard partial comparison between floating point numbers, this comparison always produces an ordering in accordance to the totalOrder predicate as defined in the IEEE 754 (2008 revision) floating point standard. The values are ordered in the following sequence:

  • negative quiet NaN
  • negative signaling NaN
  • negative infinity
  • negative numbers
  • negative subnormal numbers
  • negative zero
  • positive zero
  • positive subnormal numbers
  • positive numbers
  • positive infinity
  • positive signaling NaN
  • positive quiet NaN
Source

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

Restrict a value to a certain interval unless it is NaN.

Returns max if self is greater than max, and min if self is less than min. Otherwise this returns self.

Note that this function returns NaN if the initial value was NaN as well.

§Panics

Panics if min > max, min is NaN, or max is NaN.

Trait Implementations§

Source§

impl Clone for F64

Source§

fn clone(&self) -> F64

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for F64

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for F64

Source§

fn default() -> Self

Returns Self::ZERO.

Source§

impl Display for F64

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<F64> for f64

Source§

fn from(val: F64) -> f64

Converts to this type from the input type.
Source§

impl From<f64> for F64

Source§

fn from(float: f64) -> Self

Converts to this type from the input type.
Source§

impl FromStr for F64

Source§

type Err = ParseFloatError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for F64

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for F64

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for F64

Source§

fn eq(&self, other: &F64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for F64

Source§

fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for F64

Source§

impl Eq for F64

Source§

impl StructuralPartialEq for F64

Auto Trait Implementations§

§

impl Freeze for F64

§

impl RefUnwindSafe for F64

§

impl Send for F64

§

impl Sync for F64

§

impl Unpin for F64

§

impl UnwindSafe for F64

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.