Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lifthrasiir/num-cmp
Comparison between differently typed numbers in Rust
https://github.com/lifthrasiir/num-cmp
rust
Last synced: 2 months ago
JSON representation
Comparison between differently typed numbers in Rust
- Host: GitHub
- URL: https://github.com/lifthrasiir/num-cmp
- Owner: lifthrasiir
- License: other
- Created: 2017-03-02T12:26:26.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-03T19:03:17.000Z (almost 5 years ago)
- Last Synced: 2024-04-24T18:40:43.015Z (8 months ago)
- Topics: rust
- Language: Rust
- Homepage: https://docs.rs/num-cmp/
- Size: 16.6 KB
- Stars: 13
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# num-cmp
The **[`NumCmp`](https://docs.rs/num-cmp/*/num_cmp/trait.NumCmp.html)** trait for comparison between differently typed numbers.
```rust
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);
```The `i128` Cargo feature can be enabled in nightly
to get support for `i128` and `u128` types as well,
which is being implemented in [Rust issue #35118][issue-35118].[issue-35118]: https://github.com/rust-lang/rust/issues/35118