| Crates.io | ballpark |
| lib.rs | ballpark |
| version | 1.0.0 |
| created_at | 2025-05-07 23:38:20.190756+00 |
| updated_at | 2025-07-15 21:05:23.653526+00 |
| description | Approximate comparisons for floating-point numbers |
| homepage | |
| repository | https://github.com/SludgePhD/Ballpark |
| max_upload_size | |
| id | 1664690 |
| size | 64,421 |
This crate provides approximate equality comparisons and assertions for floating-point values.
use ballpark::assert_approx_eq;
// Infamously, 0.1 + 0.2 == 0.30000000000000004 when using double precision.
assert_ne!(0.1 + 0.2, 0.3);
// But they are *approximately* equal.
assert_approx_eq!(0.1 + 0.2, 0.3);
// In fact, the result is within one unit in the last place (ULP) of the correct one:
assert_approx_eq!(0.1 + 0.2, 0.3).ulps(1);
Refer to the API Documentation for more examples like these.
#![no_std] support, no alloc needed (just disable the default features).This crate does not aim to provide the following features:
ballpark themselves and provide their own implementations (potentially behind a Cargo feature).This library targets the latest Rust version.
Older Rust versions are supported by equally older versions of this crate. For example, to use a version of Rust that was succeeded 6 months ago, you'd also use an at least 6 month old version of this library.
Compatibility with older Rust versions may be provided on a best-effort basis.