Crates.io | cmp_floats |
lib.rs | cmp_floats |
version | 0.1.7 |
source | src |
created_at | 2021-02-08 20:05:10.402273 |
updated_at | 2021-02-21 14:21:40.546145 |
description | A function to compare floats |
homepage | |
repository | https://github.com/47617272696e/cmp_floats |
max_upload_size | |
id | 352471 |
size | 4,587 |
This is a function I made, because other float comparison libraries seemed unnecessarily complicated.
use std::cmp::Ordering::*;
use cmp_floats::cmp_floats;
assert_eq!(Less, cmp_floats(2.71828f32, 3.14159f64));
let a: f32 = 0.15 + 0.15 + 0.15;
let b: f32 = 0.1 + 0.1 + 0.25;
assert_eq!(Equal, cmp_floats(a, b));