[][src]Crate decorum

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

ConstrainedFloat

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

Traits

Encoding

Floating-point encoding.

Infinite

A floating-point value that can be infinite (-INF or INF).

Nan

A floating-point value that can be NaN.

Primitive

A primitive floating-point value.

Real

A value that can represent a real number.

Functions

cmp_float

Compares primitive floating-point values.

cmp_float_array

Compares primitive floating-point arrays.

cmp_float_slice

Compares primitive floating-point slices.

eq_float

Determines if primitive floating-point values are equal.

eq_float_array

Determines if primitive floating-point arrays are equal.

eq_float_slice

Determines if primitive floating-point slices are equal.

hash_float

Hashes a primitive floating-point value.

hash_float_array

Hashes an array of primitive floating-point values.

hash_float_slice

Hashes a slice of primitive floating-point values.

Type Definitions

Finite

An ordered and canonicalized floating-point value that must represent a real number.

N32

An alias for a floating-point value that cannot be NaN.

N64

An alias for a floating-point value that cannot be NaN.

NotNan

An ordered and canonicalized floating-point value that cannot be NaN.

Ordered

An ordered and canonicalized floating-point value.

R32

An alias for a floating-point value that represents a real number.

R64

An alias for a floating-point value that represents a real number.