liveBook · Manning

Eps

As explained in Rust in Action: Systems programming concepts and techniques

Floating-point epsilon is a small tolerance used to assess whether a computed value is sufficiently close to an expected mathematical result.

Floating-point epsilon is a small tolerance for deciding whether a computed value is close enough to its expected mathematical result. Exact equality can fail because floating-point values are represented with limited precision. section 2.3.3

Compare with a tolerance

Instead of asserting that 0.1 + 0.1 exactly equals 0.2, calculate the absolute difference and compare it with f32::EPSILON: let result: f32 = 0.1 + 0.1; let desired: f32 = 0.2; let absolute_difference = (desired - result).abs(); assert!(absolute_difference <= f32::EPSILON); Rust provides f32::EPSILON and f64::EPSILON for the two floating-point types. section 2.3.3

The suitable tolerance depends on the floating-point type and calculation. Inspecting bit patterns shows that equivalent-looking f32 and f64 operations can produce different results; epsilon comparisons address this precision problem rather than making values mathematically exact. section 2.3.3

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Demonstrates absolute-difference comparison and type-specific constants, but does not develop broader tolerance strategies.
Examples
Uses 0.1 + 0.2, f32 and f64 bit patterns, and an absolute-difference assertion.
What it assumes
Assumes basic Rust numeric values, comparisons, assertions, and method calls.
What you can do after
Diagnose floating-point equality failures and apply f32::EPSILON or f64::EPSILON in assertions.
How it connects
Connects epsilon with floating-point types, numeric equality, CPU operations, and NaN handling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.