diff --git a/lib/std/math/complex/abs.zig b/lib/std/math/complex/abs.zig index ab85f2c36c33a125b69b525730cc1c33288163fb..8b75db4a61a0f1cc0ecf4f5310fcf85518d3293f 100644 --- a/lib/std/math/complex/abs.zig +++ b/lib/std/math/complex/abs.zig @@ -9,10 +9,9 @@ pub fn abs(z: anytype) @TypeOf(z.re, z.im) { return math.hypot(z.re, z.im); } -const epsilon = 0.0001; - test abs { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = abs(a); - try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); + try testing.expectApproxEqAbs(5.8309517, c, epsilon); } diff --git a/lib/std/math/complex/acos.zig b/lib/std/math/complex/acos.zig index 9cbfaffe4b41c191919f44e96e808e40e2609d76..afaae740d94fc4e938d2f9d3c027aa132d55a579 100644 --- a/lib/std/math/complex/acos.zig +++ b/lib/std/math/complex/acos.zig @@ -11,12 +11,11 @@ pub fn acos(z: anytype) Complex(@TypeOf(z.re, z.im)) { return Complex(T).init(@as(T, math.pi) / 2 - q.re, -q.im); } -const epsilon = 0.0001; - test acos { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = acos(a); - try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon)); + try testing.expectApproxEqAbs(0.5469737, c.re, epsilon); + try testing.expectApproxEqAbs(-2.4529128, c.im, epsilon); } diff --git a/lib/std/math/complex/acosh.zig b/lib/std/math/complex/acosh.zig index dba8b03794bd185b80d5e05c4b2b5033388f9ff4..dbb7104343c7a60559fd866bf6803a2c33d05da5 100644 --- a/lib/std/math/complex/acosh.zig +++ b/lib/std/math/complex/acosh.zig @@ -8,15 +8,18 @@ const Complex = cmath.Complex; pub fn acosh(z: anytype) Complex(@TypeOf(z.re, z.im)) { const T = @TypeOf(z.re, z.im); const q = cmath.acos(z); - return Complex(T).init(-q.im, q.re); -} -const epsilon = 0.0001; + return if (math.signbit(z.im)) + Complex(T).init(q.im, -q.re) + else + Complex(T).init(-q.im, q.re); +} test acosh { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = acosh(a); - try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon)); + try testing.expectApproxEqAbs(2.4529128, c.re, epsilon); + try testing.expectApproxEqAbs(0.5469737, c.im, epsilon); } diff --git a/lib/std/math/complex/arg.zig b/lib/std/math/complex/arg.zig index ac69276d96b03e887fa29f9da2ac35af5da6258a..12986c7c8d52cf81f3e84aee5fc35d6bdaae3eed 100644 --- a/lib/std/math/complex/arg.zig +++ b/lib/std/math/complex/arg.zig @@ -9,10 +9,9 @@ pub fn arg(z: anytype) @TypeOf(z.re, z.im) { return math.atan2(z.im, z.re); } -const epsilon = 0.0001; - test arg { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = arg(a); - try testing.expect(math.approxEqAbs(f32, c, 0.540420, epsilon)); + try testing.expectApproxEqAbs(0.5404195, c, epsilon); } diff --git a/lib/std/math/complex/asin.zig b/lib/std/math/complex/asin.zig index deacfa26eada16d800eeb4bf5a928166baf9df21..bf3e9a00da996a5c69639030833ee46a0d9ae83c 100644 --- a/lib/std/math/complex/asin.zig +++ b/lib/std/math/complex/asin.zig @@ -17,12 +17,11 @@ pub fn asin(z: anytype) Complex(@TypeOf(z.re, z.im)) { return Complex(T).init(r.im, -r.re); } -const epsilon = 0.0001; - test asin { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = asin(a); - try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon)); + try testing.expectApproxEqAbs(1.0238227, c.re, epsilon); + try testing.expectApproxEqAbs(2.4529128, c.im, epsilon); } diff --git a/lib/std/math/complex/asinh.zig b/lib/std/math/complex/asinh.zig index 2dcfc9c2acb4a5ff5cf3473878c6219b944bd42c..4923caff507de72c653bb737e094247b9f31a596 100644 --- a/lib/std/math/complex/asinh.zig +++ b/lib/std/math/complex/asinh.zig @@ -12,12 +12,11 @@ pub fn asinh(z: anytype) Complex(@TypeOf(z.re, z.im)) { return Complex(T).init(r.im, -r.re); } -const epsilon = 0.0001; - test asinh { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = asinh(a); - try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon)); + try testing.expectApproxEqAbs(2.4598298, c.re, epsilon); + try testing.expectApproxEqAbs(0.5339993, c.im, epsilon); } diff --git a/lib/std/math/complex/atan.zig b/lib/std/math/complex/atan.zig index 33109178f8db39999d6d69c12f23dea2497e46e9..9e9e94622c1ccf82a7f269fbd39aad0faa7017ee 100644 --- a/lib/std/math/complex/atan.zig +++ b/lib/std/math/complex/atan.zig @@ -32,37 +32,22 @@ fn redupif32(x: f32) f32 { t -= 0.5; } - const u = @as(f32, @floatFromInt(@as(i32, @intFromFloat(t)))); - return ((x - u * DP1) - u * DP2) - t * DP3; + const u: f32 = @trunc(t); + return ((x - u * DP1) - u * DP2) - u * DP3; } fn atan32(z: Complex(f32)) Complex(f32) { - const maxnum = 1.0e38; - const x = z.re; const y = z.im; - if ((x == 0.0) and (y > 1.0)) { - // overflow - return Complex(f32).init(maxnum, maxnum); - } - const x2 = x * x; var a = 1.0 - x2 - (y * y); - if (a == 0.0) { - // overflow - return Complex(f32).init(maxnum, maxnum); - } var t = 0.5 * math.atan2(2.0 * x, a); const w = redupif32(t); t = y - 1.0; a = x2 + t * t; - if (a == 0.0) { - // overflow - return Complex(f32).init(maxnum, maxnum); - } t = y + 1.0; a = (x2 + (t * t)) / a; @@ -81,57 +66,42 @@ fn redupif64(x: f64) f64 { t -= 0.5; } - const u = @as(f64, @floatFromInt(@as(i64, @intFromFloat(t)))); - return ((x - u * DP1) - u * DP2) - t * DP3; + const u: f64 = @trunc(t); + return ((x - u * DP1) - u * DP2) - u * DP3; } fn atan64(z: Complex(f64)) Complex(f64) { - const maxnum = 1.0e308; - const x = z.re; const y = z.im; - if ((x == 0.0) and (y > 1.0)) { - // overflow - return Complex(f64).init(maxnum, maxnum); - } - const x2 = x * x; var a = 1.0 - x2 - (y * y); - if (a == 0.0) { - // overflow - return Complex(f64).init(maxnum, maxnum); - } var t = 0.5 * math.atan2(2.0 * x, a); const w = redupif64(t); t = y - 1.0; a = x2 + t * t; - if (a == 0.0) { - // overflow - return Complex(f64).init(maxnum, maxnum); - } t = y + 1.0; a = (x2 + (t * t)) / a; return Complex(f64).init(w, 0.25 * @log(a)); } -const epsilon = 0.0001; - test atan32 { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = atan(a); - try testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon)); + try testing.expectApproxEqAbs(1.423679, c.re, epsilon); + try testing.expectApproxEqAbs(0.086569, c.im, epsilon); } test atan64 { + const epsilon = math.floatEps(f64); const a = Complex(f64).init(5, 3); const c = atan(a); - try testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon)); - try testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon)); + try testing.expectApproxEqAbs(1.4236790442393028, c.re, epsilon); + try testing.expectApproxEqAbs(0.08656905917945844, c.im, epsilon); } diff --git a/lib/std/math/complex/atanh.zig b/lib/std/math/complex/atanh.zig index 54d21fc433537ca5848997f50674cf0e1d07a864..86d5b3df23655cacc26c0f9efb6abd2e915940f2 100644 --- a/lib/std/math/complex/atanh.zig +++ b/lib/std/math/complex/atanh.zig @@ -12,12 +12,11 @@ pub fn atanh(z: anytype) Complex(@TypeOf(z.re, z.im)) { return Complex(T).init(r.im, -r.re); } -const epsilon = 0.0001; - test atanh { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = atanh(a); - try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon)); + try testing.expectApproxEqAbs(0.14694665, c.re, epsilon); + try testing.expectApproxEqAbs(1.4808695, c.im, epsilon); } diff --git a/lib/std/math/complex/conj.zig b/lib/std/math/complex/conj.zig index b5a4d063d3170956900ec7cedc5bb2b068f22b6e..4a271c9801d9e37207443e8a714c1cb073982403 100644 --- a/lib/std/math/complex/conj.zig +++ b/lib/std/math/complex/conj.zig @@ -14,5 +14,6 @@ test conj { const a = Complex(f32).init(5, 3); const c = a.conjugate(); - try testing.expect(c.re == 5 and c.im == -3); + try testing.expectEqual(5, c.re); + try testing.expectEqual(-3, c.im); } diff --git a/lib/std/math/complex/cos.zig b/lib/std/math/complex/cos.zig index 389dd013e3a060a512cccfcf92a5c5e48e8eddbf..fee1a8c37a2745bae71a0e5b44230e3dfb3b6438 100644 --- a/lib/std/math/complex/cos.zig +++ b/lib/std/math/complex/cos.zig @@ -11,12 +11,11 @@ pub fn cos(z: anytype) Complex(@TypeOf(z.re, z.im)) { return cmath.cosh(p); } -const epsilon = 0.0001; - test cos { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = cos(a); - try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon)); + try testing.expectApproxEqAbs(2.8558152, c.re, epsilon); + try testing.expectApproxEqAbs(9.606383, c.im, epsilon); } diff --git a/lib/std/math/complex/cosh.zig b/lib/std/math/complex/cosh.zig index 42f5b432ec0c4a96780ed83415861b2e994efee9..d41b3fb06a0b460391186f81875ee36905953d41 100644 --- a/lib/std/math/complex/cosh.zig +++ b/lib/std/math/complex/cosh.zig @@ -34,7 +34,7 @@ fn cosh32(z: Complex(f32)) Complex(f32) { if (ix < 0x7f800000 and iy < 0x7f800000) { if (iy == 0) { - return Complex(f32).init(math.cosh(x), y); + return Complex(f32).init(math.cosh(x), x * y); } // small x: normal case if (ix < 0x41100000) { @@ -45,7 +45,7 @@ fn cosh32(z: Complex(f32)) Complex(f32) { if (ix < 0x42b17218) { // x < 88.7: exp(|x|) won't overflow const h = @exp(@abs(x)) * 0.5; - return Complex(f32).init(math.copysign(h, x) * @cos(y), h * @sin(y)); + return Complex(f32).init(h * @cos(y), math.copysign(h, x) * @sin(y)); } // x < 192.7: scale to avoid overflow else if (ix < 0x4340b1e7) { @@ -68,7 +68,7 @@ fn cosh32(z: Complex(f32)) Complex(f32) { if (hx & 0x7fffff == 0) { return Complex(f32).init(x * x, math.copysign(@as(f32, 0.0), x) * y); } - return Complex(f32).init(x, math.copysign(@as(f32, 0.0), (x + x) * y)); + return Complex(f32).init(x * x, math.copysign(@as(f32, 0.0), (x + x) * y)); } if (ix < 0x7f800000 and iy >= 0x7f800000) { @@ -123,7 +123,7 @@ fn cosh64(z: Complex(f64)) Complex(f64) { } // x >= 1455: result always overflows else { - const h = 0x1p1023; + const h = 0x1p1023 * x; return Complex(f64).init(h * h * @cos(y), h * @sin(y)); } } @@ -153,20 +153,29 @@ fn cosh64(z: Complex(f64)) Complex(f64) { return Complex(f64).init((x * x) * (y - y), (x + x) * (y - y)); } -const epsilon = 0.0001; - test cosh32 { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = cosh(a); - try testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon)); + try testing.expectApproxEqAbs(-73.467300, c.re, epsilon); + try testing.expectApproxEqAbs(10.471557, c.im, epsilon); } test cosh64 { + const epsilon = math.floatEps(f64); const a = Complex(f64).init(5, 3); const c = cosh(a); - try testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon)); - try testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon)); + try testing.expectApproxEqAbs(-73.46729221264526, c.re, epsilon); + try testing.expectApproxEqAbs(10.471557674805572, c.im, epsilon); +} + +test "cosh64 musl" { + const epsilon = math.floatEps(f64); + const a = Complex(f64).init(7.44648873421389e17, 1.6008058402057622e19); + const c = cosh(a); + + try testing.expectApproxEqAbs(std.math.inf(f64), c.re, epsilon); + try testing.expectApproxEqAbs(std.math.inf(f64), c.im, epsilon); } diff --git a/lib/std/math/complex/log.zig b/lib/std/math/complex/log.zig index 65859c2dce93c2d461f80b2b9048776657947ae8..39174431f1c1ae8ddf5a991a97b7c63b2fe8b8f9 100644 --- a/lib/std/math/complex/log.zig +++ b/lib/std/math/complex/log.zig @@ -13,12 +13,11 @@ pub fn log(z: anytype) Complex(@TypeOf(z.re, z.im)) { return Complex(T).init(@log(r), phi); } -const epsilon = 0.0001; - test log { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = log(a); - try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon)); + try testing.expectApproxEqAbs(1.7631803, c.re, epsilon); + try testing.expectApproxEqAbs(0.5404195, c.im, epsilon); } diff --git a/lib/std/math/complex/pow.zig b/lib/std/math/complex/pow.zig index 874e4037dcb7a76cda90d9cb5bf8a23a6d008ec3..6fcca6b864615375efe8814a26fb0cfc568f95fc 100644 --- a/lib/std/math/complex/pow.zig +++ b/lib/std/math/complex/pow.zig @@ -9,13 +9,12 @@ pub fn pow(z: anytype, s: anytype) Complex(@TypeOf(z.re, z.im, s.re, s.im)) { return cmath.exp(cmath.log(z).mul(s)); } -const epsilon = 0.0001; - test pow { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const b = Complex(f32).init(2.3, -1.3); const c = pow(a, b); - try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon)); + try testing.expectApproxEqAbs(58.049110, c.re, epsilon); + try testing.expectApproxEqAbs(-101.003433, c.im, epsilon); } diff --git a/lib/std/math/complex/proj.zig b/lib/std/math/complex/proj.zig index b7d3d58b12cb9cf0d54ba8c0b858c9f22c802a3d..243e5133c300b92cf33fc4fe2c2637daf1229cf1 100644 --- a/lib/std/math/complex/proj.zig +++ b/lib/std/math/complex/proj.zig @@ -19,5 +19,6 @@ test proj { const a = Complex(f32).init(5, 3); const c = proj(a); - try testing.expect(c.re == 5 and c.im == 3); + try testing.expectEqual(5, c.re); + try testing.expectEqual(3, c.im); } diff --git a/lib/std/math/complex/sin.zig b/lib/std/math/complex/sin.zig index 3ca2419e430d552f0d916d447d7d0f082c3bbfd1..5ce5b335f85e7c80809c1d59845722925f938e9e 100644 --- a/lib/std/math/complex/sin.zig +++ b/lib/std/math/complex/sin.zig @@ -12,12 +12,11 @@ pub fn sin(z: anytype) Complex(@TypeOf(z.re, z.im)) { return Complex(T).init(q.im, -q.re); } -const epsilon = 0.0001; - test sin { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = sin(a); - try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon)); + try testing.expectApproxEqAbs(-9.654126, c.re, epsilon); + try testing.expectApproxEqAbs(2.8416924, c.im, epsilon); } diff --git a/lib/std/math/complex/sinh.zig b/lib/std/math/complex/sinh.zig index 911587a9c5320970e5b4c259aec639c5885b2d51..ae8fadb9abba67c744cd8e10cc127e4bcf6dab95 100644 --- a/lib/std/math/complex/sinh.zig +++ b/lib/std/math/complex/sinh.zig @@ -152,20 +152,20 @@ fn sinh64(z: Complex(f64)) Complex(f64) { return Complex(f64).init((x * x) * (y - y), (x + x) * (y - y)); } -const epsilon = 0.0001; - test sinh32 { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = sinh(a); - try testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon)); + try testing.expectApproxEqAbs(-73.460617, c.re, epsilon); + try testing.expectApproxEqAbs(10.472508, c.im, epsilon); } test sinh64 { + const epsilon = math.floatEps(f64); const a = Complex(f64).init(5, 3); const c = sinh(a); - try testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon)); - try testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon)); + try testing.expectApproxEqAbs(-73.46062169567367, c.re, epsilon); + try testing.expectApproxEqAbs(10.472508533940392, c.im, epsilon); } diff --git a/lib/std/math/complex/sqrt.zig b/lib/std/math/complex/sqrt.zig index 0edf18fb2378540820b5a77745bb816268be19fe..f8f7798ae9fce1762b7281cc5143a98d30ac3967 100644 --- a/lib/std/math/complex/sqrt.zig +++ b/lib/std/math/complex/sqrt.zig @@ -43,7 +43,7 @@ fn sqrt32(z: Complex(f32)) Complex(f32) { // sqrt(-inf + i nan) = nan +- inf i // sqrt(-inf + iy) = 0 + inf i if (math.signbit(x)) { - return Complex(f32).init(@abs(x - y), math.copysign(x, y)); + return Complex(f32).init(@abs(y - y), math.copysign(x, y)); } else { return Complex(f32).init(x, math.copysign(y - y, y)); } @@ -94,7 +94,7 @@ fn sqrt64(z: Complex(f64)) Complex(f64) { // sqrt(-inf + i nan) = nan +- inf i // sqrt(-inf + iy) = 0 + inf i if (math.signbit(x)) { - return Complex(f64).init(@abs(x - y), math.copysign(x, y)); + return Complex(f64).init(@abs(y - y), math.copysign(x, y)); } else { return Complex(f64).init(x, math.copysign(y - y, y)); } @@ -127,20 +127,20 @@ fn sqrt64(z: Complex(f64)) Complex(f64) { return result; } -const epsilon = 0.0001; - test sqrt32 { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = sqrt(a); - try testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon)); + try testing.expectApproxEqAbs(2.3271174, c.re, epsilon); + try testing.expectApproxEqAbs(0.6445742, c.im, epsilon); } test sqrt64 { + const epsilon = math.floatEps(f64); const a = Complex(f64).init(5, 3); const c = sqrt(a); - try testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon)); - try testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon)); + try testing.expectApproxEqAbs(2.3271175190399496, c.re, epsilon); + try testing.expectApproxEqAbs(0.6445742373246469, c.im, epsilon); } diff --git a/lib/std/math/complex/tan.zig b/lib/std/math/complex/tan.zig index ad5b1b47b6488ce5efec992e13e310ef16d821e2..4c3629046a6bf69a8cc367b0c9f90ae8c635ba49 100644 --- a/lib/std/math/complex/tan.zig +++ b/lib/std/math/complex/tan.zig @@ -12,12 +12,11 @@ pub fn tan(z: anytype) Complex(@TypeOf(z.re, z.im)) { return Complex(T).init(r.im, -r.re); } -const epsilon = 0.0001; - test tan { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = tan(a); - try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon)); + try testing.expectApproxEqAbs(-0.002708233, c.re, epsilon); + try testing.expectApproxEqAbs(1.0041647, c.im, epsilon); } diff --git a/lib/std/math/complex/tanh.zig b/lib/std/math/complex/tanh.zig index 8a1d46eca7537af1d1f4cac947063a0f7ea1a00d..af2ed4f061c86280cd5454e611babebe5382889e 100644 --- a/lib/std/math/complex/tanh.zig +++ b/lib/std/math/complex/tanh.zig @@ -70,7 +70,7 @@ fn tanh64(z: Complex(f64)) Complex(f64) { const ix = hx & 0x7fffffff; if (ix >= 0x7ff00000) { - if ((ix & 0x7fffff) | lx != 0) { + if ((ix & 0xfffff) | lx != 0) { const r = if (y == 0) y else x * y; return Complex(f64).init(x, r); } @@ -101,20 +101,29 @@ fn tanh64(z: Complex(f64)) Complex(f64) { return Complex(f64).init((beta * rho * s) / den, t / den); } -const epsilon = 0.0001; - test tanh32 { + const epsilon = math.floatEps(f32); const a = Complex(f32).init(5, 3); const c = tanh(a); - try testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon)); - try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon)); + try testing.expectApproxEqAbs(0.99991274, c.re, epsilon); + try testing.expectApproxEqAbs(-0.00002536878, c.im, epsilon); } test tanh64 { + const epsilon = math.floatEps(f64); const a = Complex(f64).init(5, 3); const c = tanh(a); - try testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon)); - try testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon)); + try testing.expectApproxEqAbs(0.9999128201513536, c.re, epsilon); + try testing.expectApproxEqAbs(-0.00002536867620767604, c.im, epsilon); +} + +test "tanh64 musl" { + const epsilon = math.floatEps(f64); + const a = Complex(f64).init(std.math.inf(f64), std.math.inf(f64)); + const c = tanh(a); + + try testing.expectApproxEqAbs(1, c.re, epsilon); + try testing.expectApproxEqAbs(0, c.im, epsilon); }