Float classification and bits v0.1.0

Source
Whether a float is NaN, infinite or finite, and the bits it is stored as.

IsNan

pub func IsNan(value: float16) -> bool
pub func IsNan(value: float32) -> bool
pub func IsNan(value: float64) -> bool
pub func IsNan(value: float8) -> bool

Provides the public IsNan operation.

Source

Parameters

NameTypeDescription
valuefloat16 / float32 / float64 / float8the value to act on

Returns: whether the value is a NaN

IsInfinite

pub func IsInfinite(value: float16) -> bool
pub func IsInfinite(value: float32) -> bool
pub func IsInfinite(value: float64) -> bool
pub func IsInfinite(value: float8) -> bool

Provides the public IsInfinite operation.

Source

Parameters

NameTypeDescription
valuefloat16 / float32 / float64 / float8the value to act on

Returns: whether the value is either infinity

IsFinite

pub func IsFinite(value: float16) -> bool
pub func IsFinite(value: float32) -> bool
pub func IsFinite(value: float64) -> bool
pub func IsFinite(value: float8) -> bool

Provides the public IsFinite operation.

Source

Parameters

NameTypeDescription
valuefloat16 / float32 / float64 / float8the value to act on

Returns: whether the value is neither infinite nor a NaN

BitsOfFloat64

pub func BitsOfFloat64(value: float64) -> uint64

The bits of value, as they are stored. Reads the value's storage as an integer of the same width through a raw pointer. This is the representation rather than the value: there is no conversion that preserves the bits, since a cast asks for the number.

Source

Parameters

NameTypeDescription
valuefloat64the float to read

Returns: its sixty-four bits

BitsOfFloat32

pub func BitsOfFloat32(value: float32) -> uint32

The bits of value, as they are stored. As BitsOfFloat64, at the narrower width.

Source

Parameters

NameTypeDescription
valuefloat32the float to read

Returns: its thirty-two bits

BitsOfFloat16

pub func BitsOfFloat16(value: float16) -> uint16

The bits of value, as they are stored. As BitsOfFloat64, at the half-precision width.

Source

Parameters

NameTypeDescription
valuefloat16the float to read

Returns: its sixteen bits

BitsOfFloat8

pub func BitsOfFloat8(value: float8) -> uint8

The bits of value, as they are stored. As BitsOfFloat64, at the eight-bit width: a sign, four exponent bits and three stored significand bits.

Source

Parameters

NameTypeDescription
valuefloat8the float to read

Returns: its eight bits

Float64FromBits

pub func Float64FromBits(bits: uint64) -> float64

The float64 whose bits are bits. Writes the value's storage from an integer of the same width through a raw pointer, which is the inverse of BitsOfFloat64 and unsafe for the same reason: there is no conversion that preserves a representation.

Source

Parameters

NameTypeDescription
bitsuint64the sixty-four bits to read as a value

Returns: the value they spell

Float32FromBits

pub func Float32FromBits(bits: uint32) -> float32

The float32 whose bits are bits. As Float64FromBits, at the narrower width.

Source

Parameters

NameTypeDescription
bitsuint32the thirty-two bits to read as a value

Returns: the value they spell