[libcxx-commits] [PATCH] D112252: Fix buggy numerics of tanh(complex) at inf #361

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 28 13:11:22 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGde493a26b970: [libc++] Fix buggy numerics of tanh(complex) at inf (authored by zasdfgbnm, committed by ldionne).

Changed prior to commit:
  https://reviews.llvm.org/D112252?vs=381330&id=383137#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112252/new/

https://reviews.llvm.org/D112252

Files:
  libcxx/include/complex
  libcxx/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp


Index: libcxx/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp
===================================================================
--- libcxx/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp
+++ libcxx/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp
@@ -57,18 +57,18 @@
         }
         else if (std::isinf(testcases[i].real()) && std::isfinite(testcases[i].imag()))
         {
-            assert(r.real() == 1);
+            assert(r.real() == (testcases[i].real() > 0 ? 1 : -1));
             assert(r.imag() == 0);
-            assert(std::signbit(r.imag()) == std::signbit(sin(2*testcases[i].imag())));
+            assert(std::signbit(r.imag()) == std::signbit(sin(2 * testcases[i].imag())));
         }
         else if (std::isinf(testcases[i].real()) && std::isinf(testcases[i].imag()))
         {
-            assert(r.real() == 1);
+            assert(r.real() == (testcases[i].real() > 0 ? 1 : -1));
             assert(r.imag() == 0);
         }
         else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
         {
-            assert(r.real() == 1);
+            assert(r.real() == (testcases[i].real() > 0 ? 1 : -1));
             assert(r.imag() == 0);
         }
         else if (std::isnan(testcases[i].real()) && testcases[i].imag() == 0)
Index: libcxx/include/complex
===================================================================
--- libcxx/include/complex
+++ libcxx/include/complex
@@ -1270,8 +1270,8 @@
     if (__libcpp_isinf_or_builtin(__x.real()))
     {
         if (!__libcpp_isfinite_or_builtin(__x.imag()))
-            return complex<_Tp>(_Tp(1), _Tp(0));
-        return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
+            return complex<_Tp>(copysign(_Tp(1), __x.real()), _Tp(0));
+        return complex<_Tp>(copysign(_Tp(1), __x.real()), copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
     }
     if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0)
         return __x;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112252.383137.patch
Type: text/x-patch
Size: 2045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211028/d5b66195/attachment-0001.bin>


More information about the libcxx-commits mailing list