[libcxx-commits] [PATCH] D112277: Fix numeric of exp(complex) at inf

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf21c2473006f: [libc++] Fix numeric of exp(complex) at inf (authored by zasdfgbnm, committed by ldionne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112277

Files:
  libcxx/include/complex
  libcxx/test/std/numerics/complex.number/cases.h
  libcxx/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp


Index: libcxx/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp
===================================================================
--- libcxx/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp
+++ libcxx/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp
@@ -102,6 +102,10 @@
             assert(!std::signbit(r.real()));
             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
         }
+        else if (std::isinf(r.real()) && testcases[i].imag() == 0) {
+            assert(r.imag() == 0);
+            assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
+        }
     }
 }
 
@@ -112,5 +116,5 @@
     test<long double>();
     test_edges();
 
-  return 0;
+    return 0;
 }
Index: libcxx/test/std/numerics/complex.number/cases.h
===================================================================
--- libcxx/test/std/numerics/complex.number/cases.h
+++ libcxx/test/std/numerics/complex.number/cases.h
@@ -38,6 +38,24 @@
     std::complex<double>(-1.e+6, -1.e+6),
     std::complex<double>( 1.e+6, -1.e+6),
 
+    std::complex<double>(-0, -1.e-6),
+    std::complex<double>(-0,  1.e-6),
+    std::complex<double>(-0,  1.e+6),
+    std::complex<double>(-0, -1.e+6),
+    std::complex<double>( 0, -1.e-6),
+    std::complex<double>( 0,  1.e-6),
+    std::complex<double>( 0,  1.e+6),
+    std::complex<double>( 0, -1.e+6),
+
+    std::complex<double>(-1.e-6, -0),
+    std::complex<double>( 1.e-6, -0),
+    std::complex<double>( 1.e+6, -0),
+    std::complex<double>(-1.e+6, -0),
+    std::complex<double>(-1.e-6,  0),
+    std::complex<double>( 1.e-6,  0),
+    std::complex<double>( 1.e+6,  0),
+    std::complex<double>(-1.e+6,  0),
+
     std::complex<double>(NAN, NAN),
     std::complex<double>(-INFINITY, NAN),
     std::complex<double>(-2, NAN),
Index: libcxx/include/complex
===================================================================
--- libcxx/include/complex
+++ libcxx/include/complex
@@ -1056,6 +1056,9 @@
 exp(const complex<_Tp>& __x)
 {
     _Tp __i = __x.imag();
+    if (__i == 0) {
+        return complex<_Tp>(exp(__x.real()), copysign(_Tp(0), __x.imag()));
+    }
     if (__libcpp_isinf_or_builtin(__x.real()))
     {
         if (__x.real() < _Tp(0))
@@ -1070,8 +1073,6 @@
             return complex<_Tp>(__x.real(), __i);
         }
     }
-    else if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0)
-        return __x;
     _Tp __e = exp(__x.real());
     return complex<_Tp>(__e * cos(__i), __e * sin(__i));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112277.383136.patch
Type: text/x-patch
Size: 2566 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211028/3b92dcf3/attachment.bin>


More information about the libcxx-commits mailing list