A no-std
compatible crate which provides wrappers for imposing arbitrary invariants on floating point types.
The [FloatChecker
] trait can be implemented on a type to create an invariant checker that can then
be used in the [CheckedFloat
] type to create a wrapper that enforces the invariant for all operations.
Example
The following is an example of how to use checked-float
to create a floating point wrapper that forbids NaN.
# use *;
;
;
type NoNan64 = ; // our checked float wrapper
let y = new.unwrap; // not nan, so we can unwrap
let x = new.unwrap; // not nan, so we can unwrap
assert_eq!; // not nan, so we can unwrap
assert!; // 0/0 is nan, so we get Err
no-std
support
checked-float
supports building in no-std
environments out of the box.
However, for future-proofing, you may like to explicitly opt out of default features in case
a dependency on std
is ever added.
[]
= { = "...", = false }
Features
name | default | description |
---|---|---|
serde |
off | Enables serialization of [CheckedFloat ] |