#numeric #comparison #order

numcmp

Comparison between differently typed numbers

1 unstable release

Uses old Rust 2015

0.1.0 Feb 17, 2021

#2086 in Algorithms

Download history 29/week @ 2024-07-14 1/week @ 2024-07-21 23/week @ 2024-07-28 22/week @ 2024-08-04 15/week @ 2024-08-11 9/week @ 2024-08-18 4/week @ 2024-08-25 4/week @ 2024-09-01 16/week @ 2024-09-08 37/week @ 2024-09-15 25/week @ 2024-09-22 13/week @ 2024-09-29 53/week @ 2024-10-06 27/week @ 2024-10-13 32/week @ 2024-10-20 10/week @ 2024-10-27

122 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