#comparison #type #numeric #numbers #algorithm

no-std num-ord

Numerically ordered wrapper type for cross-type comparisons

1 unstable release

0.1.0 Sep 12, 2021

#1179 in Math

Download history 37/week @ 2024-11-18 37/week @ 2024-11-25 47/week @ 2024-12-02 57/week @ 2024-12-09 36/week @ 2024-12-16 23/week @ 2024-12-23 20/week @ 2024-12-30 30/week @ 2025-01-06 37/week @ 2025-01-13 31/week @ 2025-01-20 29/week @ 2025-01-27 42/week @ 2025-02-03 33/week @ 2025-02-10 42/week @ 2025-02-17 36/week @ 2025-02-24 33/week @ 2025-03-03

148 downloads per month

Zlib license

16KB
295 lines

num-ord

This crate provides a numerically ordered wrapper type, NumOrd. This type implements the PartialOrd and PartialEq traits for all the possible combinations of built-in integer types, in a mathematically correct manner without overflows. Please refer to the the documentation for more information.

To start using num-ord add the following to your Cargo.toml:

[dependencies]
num-ord = "0.1"

Example

use num_ord::NumOrd;

let x = 3_i64;
let y = 3.5_f64;
assert_eq!(x < (y as i64), false); // Incorrect.
assert_eq!(NumOrd(x) < NumOrd(y), true); // Correct.

let x = 9007199254740993_i64;
let y = 9007199254740992_f64;
assert_eq!(format!("{}", y), "9007199254740992"); // No rounded constant trickery!
assert_eq!((x as f64) <= y, true); // Incorrect.
assert_eq!(NumOrd(x) <= NumOrd(y), false); // Correct.

License

num-ord is released under the Zlib license, a permissive license. It is OSI and FSF approved and GPL compatible.

No runtime deps