Crate decorum

source ·
Expand description

Making floating-point values behave: traits, ordering, equality, hashing, and constraints for floating-point types.

Decorum provides proxy (wrapper) types and functions that canonicalize floating-point values and provide a total ordering. This allows floating-point values to be hashed and compared. Proxy types also provide contraints on the values that may be represented and will panic if those constraints are violated. See the README.

Ordering

NaN and zero are canonicalized to a single representation (called CNaN and C0 respectively) to provide the following total ordering for all proxy types and ordering functions: [ -INF | ... | C0 | ... | +INF | CNaN ]

Note that NaN is canonicalized to CNaN, which has a single representation and supports the relations CNaN = CNaN and CNaN > x | x ≠ CNaN. +0 and -0 are also canonicalized to C0, which is equivalent to +0.

Constraints

The NotNan and Finite types wrap raw floating-point values and disallow certain values like NaN, INF, and -INF. They will panic if an operation or conversion invalidates these constraints. The Ordered type allows any valid IEEE-754 value (there are no constraints). For most use cases, either Ordered or NotNan are appropriate.

Structs

Floating-point proxy that provides ordering, hashing, and value constraints.

Traits

Floating-point encoding.
A floating-point value that can be infinite (-INF or INF).
A floating-point value that can be NaN.
A primitive floating-point value.
A value that can represent a real number.

Functions

Compares primitive floating-point values.
Compares primitive floating-point arrays.
Compares primitive floating-point slices.
Determines if primitive floating-point values are equal.
Determines if primitive floating-point arrays are equal.
Determines if primitive floating-point slices are equal.
Hashes a primitive floating-point value.
Hashes an array of primitive floating-point values.
Hashes a slice of primitive floating-point values.

Type Definitions

An ordered and canonicalized floating-point value that must represent a real number.
An alias for a floating-point value that cannot be NaN.
An alias for a floating-point value that cannot be NaN.
An ordered and canonicalized floating-point value that cannot be NaN.
An ordered and canonicalized floating-point value.
An alias for a floating-point value that represents a real number.
An alias for a floating-point value that represents a real number.