approx

Approximate floating point equality comparisons and assertions for Rust

Library
Cargo
v0.6.0-rc2
188stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
58/100Fair
Development Activity56
Maintenance24
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality84
Innovation65
Learning Curve88

approx is a small, foundational Rust crate for comparing floating point numbers for approximate equality. Because binary floats rarely compare exactly equal, it provides relative, absolute, and ULP (units in the last place) based comparison strategies so numeric code and tests can express meaningful tolerances.

The crate ships ergonomic assertion macros such as assert_relative_eq!, assert_abs_diff_eq!, and assert_ulps_eq!, along with the AbsDiffEq, RelativeEq, and UlpsEq traits that downstream types can implement. It is an extremely widely used dependency across the Rust scientific and graphics ecosystem, distributed under the Apache-2.0 license.

What You Get

  • Assertion macros: assert_relative_eq!, assert_abs_diff_eq!, assert_ulps_eq!
  • The AbsDiffEq, RelativeEq, and UlpsEq comparison traits
  • Configurable epsilon, max relative, and max ULP tolerances
  • A no_std-friendly, dependency-light implementation

Common Use Cases

  • Writing unit tests that compare computed floats within a tolerance
  • Validating results of numerical and geometric algorithms
  • Implementing approximate equality for custom math types
  • Comparing vectors and matrices in graphics or physics code

Under The Hood

Architecture - approx is built around three core traits — AbsDiffEq, RelativeEq, and UlpsEq — each parameterized by an epsilon type and default tolerances. Assertion macros expand into calls against these traits, and blanket/derived implementations cover primitive floats and slices while letting user types opt in.

Tech Stack - Pure Rust with optional num-complex and num-traits integration, no_std support, and a minimum rustc of 1.36; distributed as the approx crate on crates.io.

Code Quality - A compact, thoroughly documented codebase with docs.rs coverage, CI test workflows, and 30 contributors; its long track record and ~132M downloads reflect strong reliability.

API Design - The macro plus trait design is highly ergonomic: comparisons read naturally, tolerances are set fluently via builder-style macro arguments, and extending support to new types is a matter of implementing a small trait.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search