#comparison #numeric

numcmp

Comparison between differently typed numbers

1 unstable release

Uses old Rust 2015

0.1.0 Feb 17, 2021

#1477 in Algorithms

Download history 6/week @ 2024-03-13 4/week @ 2024-03-20 9/week @ 2024-03-27 17/week @ 2024-04-03 2/week @ 2024-05-08 3/week @ 2024-05-15 6/week @ 2024-05-22 11/week @ 2024-05-29 29/week @ 2024-06-05 9/week @ 2024-06-12 45/week @ 2024-06-19 37/week @ 2024-06-26

123 downloads per month
Used in dbgen

MIT/Apache

43KB
873 lines

numcmp

This crate is a fork of num-cmp but with stable i128 support.

The NumCmp trait for comparison between differently typed numbers.

use std::f32;
use std::cmp::Ordering;
use numcmp::NumCmp;

assert!(NumCmp::num_eq(3u64, 3.0f32));
assert!(NumCmp::num_lt(-4.7f64, -4i8));
assert!(!NumCmp::num_ge(-3i8, 1u16));

// 40_000_000 can be exactly represented in f32, 40_000_001 cannot
assert_eq!(NumCmp::num_cmp(40_000_000.0f32, 40_000_000u32), Some(Ordering::Equal));
assert_ne!(NumCmp::num_cmp(40_000_001.0f32, 40_000_001u32), Some(Ordering::Equal));
assert_eq!(NumCmp::num_cmp(f32::NAN,        40_000_002u32), None);

lib.rs:

The NumCmp trait for comparison between differently typed numbers.

use std::f32;
use std::cmp::Ordering;
use numcmp::NumCmp;

assert!(NumCmp::num_eq(3u64, 3.0f32));
assert!(NumCmp::num_lt(-4.7f64, -4i8));
assert!(!NumCmp::num_ge(-3i8, 1u16));

// 40_000_000 can be exactly represented in f32, 40_000_001 cannot
assert_eq!(NumCmp::num_cmp(40_000_000.0f32, 40_000_000u32), Some(Ordering::Equal));
assert_ne!(NumCmp::num_cmp(40_000_001.0f32, 40_000_001u32), Some(Ordering::Equal));
assert_eq!(NumCmp::num_cmp(f32::NAN,        40_000_002u32), None);

No runtime deps