#比较 #数值 #排序

num-cmp

不同类型数值之间的比较

1个不稳定版本

使用旧的Rust 2015

0.1.0 2017年3月2日

#比较中排名第51

Download history 90700/week @ 2024-03-14 91467/week @ 2024-03-21 95351/week @ 2024-03-28 165912/week @ 2024-04-04 128148/week @ 2024-04-11 161191/week @ 2024-04-18 129513/week @ 2024-04-25 117722/week @ 2024-05-02 122824/week @ 2024-05-09 130490/week @ 2024-05-16 125611/week @ 2024-05-23 197585/week @ 2024-05-30 148666/week @ 2024-06-06 258828/week @ 2024-06-13 137878/week @ 2024-06-20 118501/week @ 2024-06-27

每月下载量695,958
143个crate中使用了(通过jsonschema

MIT/Apache

43KB
892

num-cmp

NumCmp是一个用于不同类型数值之间比较的trait。

use std::f32;
use std::cmp::Ordering;
use num_cmp::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);

可以在nightly模式下启用i128 Cargo功能以获得对i128u128类型的支持,这正在Rust问题#35118中实现。


lib.rs:

NumCmp是一个用于不同类型数值之间比较的trait。

use std::f32;
use std::cmp::Ordering;
use num_cmp::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);

可以在nightly模式下启用i128 Cargo功能以获得对i128u128类型的支持,这正在Rust问题#35118中实现。

没有运行时依赖

功能