Trait Float

Source
pub trait Float:
    Copy
    + PartialEq
    + PartialOrd
    + AsBits
where Self::Bits: Cast<Self::BiasedExponent> + Cast<Self::Significand>, Self::BiasedExponent: Cast<Self::Exponent>, Self::Exponent: Sub<Output = Self::Exponent>, Self::Significand: Add<Output = Self::Significand>,
{ type BiasedExponent; type Exponent; type Significand; const EXP_BITS: u16; const SIGNIF_BITS: u16; const SIGN_MASK: Self::Bits; const EXP_MASK: Self::Bits; const SIGNIF_MASK: Self::Bits; const EXP_BIAS: Self::Exponent; const BITS: u16 = _; // Provided methods fn sign_bit(self) -> bool { ... } fn biased_exponent(self) -> Self::BiasedExponent { ... } fn exponent(self) -> Self::Exponent { ... } fn stored_significand(self) -> Self::Significand { ... } fn significand(self) -> Self::Significand { ... } fn fraction(self) -> Self::Significand { ... } fn raw_components(self) -> (bool, Self::BiasedExponent, Self::Significand) { ... } fn components(self) -> (bool, Self::Exponent, Self::Significand) { ... } fn explain(self) where Self: Debug, Self::BiasedExponent: Debug, Self::Exponent: Debug, Self::Significand: Debug { ... } }
Expand description

Types that represent a floating point number.

Required Associated Constants§

Source

const EXP_BITS: u16

The number of bits of the exponent.

Source

const SIGNIF_BITS: u16

The number of bits of the stored significand (not counting the implicit bit).

Source

const SIGN_MASK: Self::Bits

The mask for the sign bit.

Source

const EXP_MASK: Self::Bits

The mask for the biased exponent bits.

Source

const SIGNIF_MASK: Self::Bits

The mask for the stored significand bits (no implicit bit).

Source

const EXP_BIAS: Self::Exponent

The exponent bias.

Provided Associated Constants§

Source

const BITS: u16 = _

The number of bits (defaults to <Self as AsBits>::Bits::BITS).

Required Associated Types§

Source

type BiasedExponent

Type for the the biased exponent.

Source

type Exponent

Type for the true (unbiased) signed exponent.

Source

type Significand

Type for the significand, both with and without implicit bit.

Provided Methods§

Source

fn sign_bit(self) -> bool

True if the sign bit is set, false otherwise.

Source

fn biased_exponent(self) -> Self::BiasedExponent

The biased exponent, as it is stored in the bit representation.

Source

fn exponent(self) -> Self::Exponent

The true (unbiased) signed exponent.

Source

fn stored_significand(self) -> Self::Significand

The significand without the implicit bit, as it is stored in the bit representation.

Synonym of Float::fraction.

Source

fn significand(self) -> Self::Significand

The true significand, with the implicit bit added.

Source

fn fraction(self) -> Self::Significand

The significand without the implicit bit, as it is stored in the bit representation.

Synonym of Float::stored_significand.

Source

fn raw_components(self) -> (bool, Self::BiasedExponent, Self::Significand)

The triple of stored components: sign bit, biased exponent, significand without implicit bit.

Source

fn components(self) -> (bool, Self::Exponent, Self::Significand)

The triple of true components: sign bit, exponent, significand with implicit bit.

Source

fn explain(self)
where Self: Debug, Self::BiasedExponent: Debug, Self::Exponent: Debug, Self::Significand: Debug,

Nicely prints the components of a floating point number.

0.032_f32.explain();
value = 0.032
bits: 00111101000000110001001001101111
      ±^^^^^^^^_______________________
sign: +
exponent = 122 - 127 = -5
significand = 2^23 + 201327 = 8589935
Examples found in repository?
examples/simple.rs (line 5)
3fn main() {
4    println!("f32 example");
5    0.032_f32.explain();
6
7    println!();
8
9    println!("f64 example");
10    0.032_f64.explain();
11}

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 EXP_BITS: u16 = 8u16

Source§

const SIGNIF_BITS: u16 = 23u16

Source§

const SIGN_MASK: Self::Bits = {transmute(0x80000000): <f32 as AsBits>::Bits}

Source§

const EXP_MASK: Self::Bits = {transmute(0x7f800000): <f32 as AsBits>::Bits}

Source§

const SIGNIF_MASK: Self::Bits = {transmute(0x007fffff): <f32 as AsBits>::Bits}

Source§

const EXP_BIAS: Self::Exponent = {transmute(0x007f): <f32 as Float>::Exponent}

Source§

type BiasedExponent = u8

Source§

type Exponent = i16

Source§

type Significand = u32

Source§

impl Float for f64

Source§

const EXP_BITS: u16 = 11u16

Source§

const SIGNIF_BITS: u16 = 52u16

Source§

const SIGN_MASK: Self::Bits = {transmute(0x8000000000000000): <f64 as AsBits>::Bits}

Source§

const EXP_MASK: Self::Bits = {transmute(0x7ff0000000000000): <f64 as AsBits>::Bits}

Source§

const SIGNIF_MASK: Self::Bits = {transmute(0x000fffffffffffff): <f64 as AsBits>::Bits}

Source§

const EXP_BIAS: Self::Exponent = {transmute(0x03ff): <f64 as Float>::Exponent}

Source§

type BiasedExponent = u16

Source§

type Exponent = i16

Source§

type Significand = u64

Implementors§