Classification and special values v0.1.0

Source
Telling NaNs, infinities, zeros, subnormals and normal values apart, and making the special ones.

FloatClass

pub enum FloatClass: int32 {
    NotANumber = 0,
    Infinite = 1,
    Zero = 2,
    Subnormal = 3,
    Normal = 4
}

The five kinds IEEE 754 sorts every value into. Copy.

Source

Cases

NameValueDescription
NotANumber0Not a number: the result of an operation with no meaningful answer.
Infinite1One of the two infinities.
Zero2Positive or negative zero.
Subnormal3A value too small to carry a full significand, whose precision degrades toward zero.
Normal4An ordinary value at full precision.

IsNan

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

Whether value is a NaN. A NaN is the only value not equal to itself, which is why this needs no bit pattern.

OverloadSummary
pub func IsNan(value: float64) -> boolWhether value is a NaN.
pub func IsNan(value: float32) -> boolDetermines whether value is a NaN at float32 precision.

Source

Parameters

NameTypeDescription
valuefloat64 / float32value to test

Returns: true when value is a NaN

IsInfinite

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

Determines whether value is an infinity at float32 precision.

OverloadSummary
pub func IsInfinite(value: float64) -> boolWhether value is one of the two infinities.
pub func IsInfinite(value: float32) -> boolDetermines whether value is an infinity at float32 precision.

Source

Parameters

NameTypeDescription
valuefloat64 / float32value to test

Returns: true when value is positive or negative infinity

IsFinite

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

Whether value is an ordinary number: neither a NaN nor an infinity.

OverloadSummary
pub func IsFinite(value: float64) -> boolWhether value is an ordinary number: neither a NaN nor an infinity.
pub func IsFinite(value: float32) -> boolDetermines whether value is finite at float32 precision.

Source

Parameters

NameTypeDescription
valuefloat64 / float32value to test

Returns: true when value is neither a NaN nor an infinity

IsZero

pub func IsZero(value: float64) -> bool
pub func IsZero(value: float32) -> bool

Whether value is either zero. Both zeros answer true; SignBit is what tells them apart.

OverloadSummary
pub func IsZero(value: float64) -> boolWhether value is either zero.
pub func IsZero(value: float32) -> boolDetermines whether value is either signed zero at float32 precision.

Source

Parameters

NameTypeDescription
valuefloat64 / float32value to test

Returns: true when value is positive or negative zero

IsSubnormal

pub func IsSubnormal(value: float64) -> bool
pub func IsSubnormal(value: float32) -> bool

Whether value is subnormal: nonzero, but too small to carry a full significand.

OverloadSummary
pub func IsSubnormal(value: float64) -> boolWhether value is subnormal: nonzero, but too small to carry a full significand.
pub func IsSubnormal(value: float32) -> boolDetermines whether value is subnormal at float32 precision.

Source

Parameters

NameTypeDescription
valuefloat64 / float32value to test

Returns: true when value is subnormal

IsNormal

pub func IsNormal(value: float64) -> bool
pub func IsNormal(value: float32) -> bool

Whether value is an ordinary value at full precision. Zero is not normal, which surprises people and is the definition every IEEE 754 implementation uses.

OverloadSummary
pub func IsNormal(value: float64) -> boolWhether value is an ordinary value at full precision.
pub func IsNormal(value: float32) -> boolDetermines whether value is normal at float32 precision.

Source

Parameters

NameTypeDescription
valuefloat64 / float32value to test

Returns: true when value is normal

Classify

pub func Classify(value: float64) -> FloatClass
pub func Classify(value: float32) -> FloatClass

Which of the five kinds value belongs to.

OverloadSummary
pub func Classify(value: float64) -> FloatClassWhich of the five kinds value belongs to.
pub func Classify(value: float32) -> FloatClassClassifies value at float32 precision.

Source

Parameters

NameTypeDescription
valuefloat64 / float32value to classify

Returns: the IEEE-754 class of value

SignBit

pub func SignBit(value: float64) -> bool
pub func SignBit(value: float32) -> bool

Whether value's sign bit is set. This is the sign bit, not a comparison: SignBit(-0.0) is true where -0.0 < 0.0 is false, and a negative NaN answers true where every comparison against it answers false. That is the whole reason to ask by bit.

OverloadSummary
pub func SignBit(value: float64) -> boolWhether value's sign bit is set.
pub func SignBit(value: float32) -> boolDetermines whether the sign bit of value is set at float32 precision.

Source

Parameters

NameTypeDescription
valuefloat64 / float32value whose sign is inspected

Returns: true when the sign bit is set

PositiveInfinity64

pub func PositiveInfinity64() -> float64

Positive infinity.

Source

Returns: positive infinity at float64 precision

PositiveInfinity32

pub func PositiveInfinity32() -> float32

Positive infinity at the narrow width.

Source

Returns: positive infinity at float32 precision

QuietNan64

pub func QuietNan64() -> float64

A quiet NaN.

Source

Returns: A quiet NaN at float64 precision

QuietNan32

pub func QuietNan32() -> float32

A quiet NaN at the narrow width.

Source

Returns: A quiet NaN at float32 precision