Skip to main content

FloatBits

Trait FloatBits 

Source
pub trait FloatBits: Sized {
    type Bits;

    // Required methods
    fn to_bits(self) -> Self::Bits;
    fn from_bits(bits: Self::Bits) -> Self;
}
Expand description

Raw IEEE 754 bit-pattern access.

Required Associated Types§

Source

type Bits

The unsigned integer type with the same width (u32 for f32, u64 for f64).

Required Methods§

Source

fn to_bits(self) -> Self::Bits

Raw transmutation to the bit representation.

use const_num_traits::FloatBits;

assert_eq!(FloatBits::to_bits(1.0f32), 0x3F80_0000);
Source

fn from_bits(bits: Self::Bits) -> Self

Raw transmutation from the bit representation.

use const_num_traits::FloatBits;

let f: f32 = FloatBits::from_bits(0x4148_0000u32);
assert_eq!(f, 12.5);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FloatBits for f32

Source§

impl FloatBits for f64

Implementors§