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/exp.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/std/math/complex/exp.zig') diff --git a/lib/std/math/complex/exp.zig b/lib/std/math/complex/exp.zig index 3ad51fe06f..156a947a32 100644 --- a/lib/std/math/complex/exp.zig +++ b/lib/std/math/complex/exp.zig @@ -131,14 +131,14 @@ test "complex.cexp32" { const a = Complex(f32).new(5, 3); const c = exp(a); - testing.expect(math.approxEq(f32, c.re, -146.927917, epsilon)); - testing.expect(math.approxEq(f32, c.im, 20.944065, epsilon)); + testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon)); + testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon)); } test "complex.cexp64" { const a = Complex(f64).new(5, 3); const c = exp(a); - testing.expect(math.approxEq(f64, c.re, -146.927917, epsilon)); - testing.expect(math.approxEq(f64, c.im, 20.944065, epsilon)); + testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon)); + testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon)); } -- cgit v1.2.3