From ff14451b4a328ca6862637a88912000d11aa2bf3 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 2 Nov 2020 13:25:50 +0100 Subject: std: Implement more useful approxEq semantics Comparisons with absolute epsilons are usually useful when comparing numbers to zero, for non-zero numbers it's advised to switch to relative epsilons instead to obtain meaningful results (check [1] for more details). The new API introduces approxEqAbs and approxEqRel, where the former aliases and deprecated the old `approxEq`, allowing the user to pick the right tool for the job. The documentation is meant to guide the user in the choice of the correct alternative. [1] https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ --- lib/std/math/complex/abs.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/std/math/complex/abs.zig') diff --git a/lib/std/math/complex/abs.zig b/lib/std/math/complex/abs.zig index db9c43e89d..228b56c286 100644 --- a/lib/std/math/complex/abs.zig +++ b/lib/std/math/complex/abs.zig @@ -20,5 +20,5 @@ const epsilon = 0.0001; test "complex.cabs" { const a = Complex(f32).new(5, 3); const c = abs(a); - testing.expect(math.approxEq(f32, c, 5.83095, epsilon)); + testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); } -- cgit v1.2.3