#nan #panic #float #compare #floating-point #order

real_float

Floating point types that check for correctness and implement total ordering

4 releases (2 breaking)

0.3.0 May 21, 2022
0.2.0 Apr 24, 2022
0.1.1 Mar 31, 2022
0.1.0 Mar 28, 2022

#1343 in Math

Download history 23/week @ 2024-03-11 24/week @ 2024-03-18 33/week @ 2024-03-25 49/week @ 2024-04-01 14/week @ 2024-04-08 22/week @ 2024-04-15 26/week @ 2024-04-22 106/week @ 2024-04-29 29/week @ 2024-05-06 41/week @ 2024-05-13 49/week @ 2024-05-20 53/week @ 2024-05-27 20/week @ 2024-06-03 61/week @ 2024-06-10 45/week @ 2024-06-17 34/week @ 2024-06-24

169 downloads per month
Used in 4 crates (via radians)

MIT/Apache

74KB
2K SLoC

real_float

Intro

This crate is for dealing checked floating point numbers. It exports three types: Real, Finite, and NonNeg. Real is checked at runtime to ensure that it is never NaN, while Finite adds the additional constraint that it can never be infinite, and NonNeg requires that it be positive.

For the sake of brevity, we will only discuss Real, but understand that everything applies to Finite and NonNeg as well.

Checking behavior

A NaN-check is inserted in every single operation and method. If a NaN ever surfaces, it will result in a runtime panic.

Note that these checks will normally only be present in debug builds. This is consistent with Rust's philosphy for integer overflowing: panic in debug mode, and allow fast-but-likely-incorrect bevhavior in release mode. If you want these checks to be present no matter what, enable the strict feature.

Fallible API

The types in this crate also support fallible APIs for any operation that would otherwise panic. These are the try_* methods defined on Real and Finite, and they will perform NaN checks whether or not debug mode is enabled.

Comparison with similar crates

TODO

License: MIT OR Apache-2.0

Dependencies

~38KB