Skip to content

Commit

Permalink
Compare with small epsilon
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcur committed Oct 6, 2024
1 parent 7fe8b55 commit 193f665
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ellipse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,11 @@ mod tests {
let circle_p = circle.perimeter(0.);
let ellipse_p = ellipse.perimeter(0.1);

assert_eq!(
circle_p,
ellipse_p,
// We expect the results to be identical, modulo potential roundoff errors. Compare
// with a very small relative epsilon.
let epsilon = f64::EPSILON * 8. * circle_p.max(ellipse_p);
assert!(
(circle_p - ellipse_p).abs() <= epsilon,
"Expected circular ellipse radius {ellipse_p} to be equal to circle radius {circle_p} for radius {radius}"
);
}
Expand Down

0 comments on commit 193f665

Please sign in to comment.