Skip to main content

FloatKind

Enum FloatKind 

Source
pub enum FloatKind {
    Float16,
    Float,
    Float32,
    Double,
    Float32x,
    Float64,
    LongDouble,
    Float64x,
    Float128,
}
Expand description

The real floating types.

Nine of them, which is three standard ones and six from C23 Annex H. The interchange types _Float16, _Float32, _Float64 and _Float128 name an IEEE format outright, and the extended types _Float32x and _Float64x name whatever the target has that is wider than the interchange type they are named after, which makes _Float64x the x87 format on x86 and quad precision on AArch64. None of them is the standard type it shares a format with: _Float64 and double are both binary64 and are two types, which _Generic can tell apart and which decides what _Float64 + double is.

_Float128x is a type no target gcc supports has, so it is not here. The decimal floating types from C23 are deferred past 1.0 by spec/19-open-questions.md and are deliberately absent rather than present and unimplemented.

Variants§

§

Float16

_Float16, always the binary16 format.

§

Float

float, always the binary32 format.

§

Float32

_Float32, always the binary32 format, and not the same type as float.

§

Double

double, always the binary64 format.

§

Float32x

_Float32x, the format the target has that is wider than _Float32, which is binary64 everywhere this compiles for.

§

Float64

_Float64, always the binary64 format, and not the same type as double.

§

LongDouble

long double, whose format is a target property and is not always distinct from double. It is 80 bits of x87 on SysV x86-64, quad precision on AArch64 Linux, and the same as double on Apple and Windows.

§

Float64x

_Float64x, the format the target has that is wider than _Float64. That is the x87 eighty bit format on x86-64 and quad precision on AArch64 and RISC-V, and unlike long double it does not become a double on Apple or on Windows.

§

Float128

_Float128, always the binary128 format.

Implementations§

Source§

impl FloatKind

Source

pub const ALL: [FloatKind; 9]

Every real floating type, in the order they are written above.

Not in rank order, because there is no such order to put them in: which of long double and _Float64x is the wider one is a question about the target, and on Apple the answer is the second.

Source

pub const fn tie_break(self) -> u8

What decides between two of these when they have the same format.

Two real floating types can be the same format and still be two types, and then the format cannot say which of them an operation on both of them produces. C23 answers with the family first: an interchange type wins over the standard type it shares a format with, and the standard type wins over an extended one, so double + _Float64 is a _Float64 and double + _Float32x is a double. Inside a family it is the usual order, which only ever comes up between double and long double on the targets where the second one is the first one.

Higher wins. This is not an ordering on the types on its own, because it says nothing about the formats: _Float32 sits above long double here and loses to it everywhere it meets it.

Source

pub const fn as_str(self) -> &'static str

How the type is spelled in a diagnostic.

Trait Implementations§

Source§

impl Clone for FloatKind

Source§

fn clone(&self) -> FloatKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for FloatKind

Source§

impl Debug for FloatKind

Source§

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

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

impl Eq for FloatKind

Source§

impl Hash for FloatKind

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 FloatKind

Source§

fn cmp(&self, other: &FloatKind) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for FloatKind

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for FloatKind

Source§

fn partial_cmp(&self, other: &FloatKind) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for FloatKind

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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.