]> git.kaiwu.me - njs.git/commitdiff
Tests: tolerate rounding differences in Math.tanh() master
authorJakub Jirutka <jakub@jirutka.cz>
Tue, 1 Dec 2026 15:44:28 +0000 (16:44 +0100)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 2 Dec 2026 00:56:24 +0000 (16:56 -0800)
On Alpine Linux/i686, Math.tanh(0.5) differs from the reference
expression (Math.E - 1)/(Math.E + 1) by one ULP (about 5.55e-17).
The exact comparison fails with both SSE and x87 builds.

Allow an absolute difference of Number.EPSILON, as in the tests
for Math.atanh() and Math.acosh().

src/test/njs_unit_test.c

index 7f3721fefc837601c10cd121097df4493976e83e..464adedb86ce2b990bb19e7abf9abd85654b5169 100644 (file)
@@ -19173,8 +19173,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("Math.tanh(-Infinity)"),
       njs_str("-1") },
 
     { njs_str("Math.tanh(-Infinity)"),
       njs_str("-1") },
 
-    { njs_str("Math.tanh(0.5) - (Math.E - 1)/(Math.E + 1)"),
-      njs_str("0") },
+    { njs_str("Math.abs(Math.tanh(0.5) - (Math.E - 1)/(Math.E + 1))"
+              " <= Number.EPSILON"),
+      njs_str("true") },
 
     { njs_str("Math.trunc(3.9)"),
       njs_str("3") },
 
     { njs_str("Math.trunc(3.9)"),
       njs_str("3") },