Home | History | Annotate | Download | only in complex.transcendentals
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <complex>
     11 
     12 // template<class T>
     13 //   complex<T>
     14 //   asinh(const complex<T>& x);
     15 
     16 #include <complex>
     17 #include <cassert>
     18 
     19 #include "../cases.h"
     20 
     21 template <class T>
     22 void
     23 test(const std::complex<T>& c, std::complex<T> x)
     24 {
     25     assert(asinh(c) == x);
     26 }
     27 
     28 template <class T>
     29 void
     30 test()
     31 {
     32     test(std::complex<T>(0, 0), std::complex<T>(0, 0));
     33 }
     34 
     35 void test_edges()
     36 {
     37     typedef std::complex<double> C;
     38     const double pi = std::atan2(+0., -0.);
     39     const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
     40     for (unsigned i = 0; i < N; ++i)
     41     {
     42         std::complex<double> r = asinh(testcases[i]);
     43         if (testcases[i].real() == 0 && testcases[i].imag() == 0)
     44         {
     45             assert(std::signbit(r.real()) == std::signbit(testcases[i].real()));
     46             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
     47         }
     48         else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
     49         {
     50             assert(std::isinf(r.real()));
     51             assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
     52             if (std::signbit(testcases[i].imag()))
     53                 is_about(r.imag(), -pi/2);
     54             else
     55                 is_about(r.imag(),  pi/2);
     56         }
     57         else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag()))
     58         {
     59             assert(std::isnan(r.real()));
     60             assert(std::isnan(r.imag()));
     61         }
     62         else if (std::isinf(testcases[i].real()) && std::isfinite(testcases[i].imag()))
     63         {
     64             assert(std::isinf(r.real()));
     65             assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
     66             assert(r.imag() == 0);
     67             assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
     68         }
     69         else if (std::isinf(testcases[i].real()) && std::isinf(testcases[i].imag()))
     70         {
     71             assert(std::isinf(r.real()));
     72             assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
     73             if (std::signbit(testcases[i].imag()))
     74                 is_about(r.imag(), -pi/4);
     75             else
     76                 is_about(r.imag(),  pi/4);
     77         }
     78         else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
     79         {
     80             assert(std::isinf(r.real()));
     81             assert(std::signbit(testcases[i].real()) == std::signbit(r.real()));
     82             assert(std::isnan(r.imag()));
     83         }
     84         else if (std::isnan(testcases[i].real()) && testcases[i].imag() == 0)
     85         {
     86             assert(std::isnan(r.real()));
     87             assert(r.imag() == 0);
     88             assert(std::signbit(testcases[i].imag()) == std::signbit(r.imag()));
     89         }
     90         else if (std::isnan(testcases[i].real()) && std::isfinite(testcases[i].imag()))
     91         {
     92             assert(std::isnan(r.real()));
     93             assert(std::isnan(r.imag()));
     94         }
     95         else if (std::isnan(testcases[i].real()) && std::isinf(testcases[i].imag()))
     96         {
     97             assert(std::isinf(r.real()));
     98             assert(std::isnan(r.imag()));
     99         }
    100         else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag()))
    101         {
    102             assert(std::isnan(r.real()));
    103             assert(std::isnan(r.imag()));
    104         }
    105         else
    106         {
    107             assert(std::signbit(r.real()) == std::signbit(testcases[i].real()));
    108             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
    109         }
    110     }
    111 }
    112 
    113 int main()
    114 {
    115     test<float>();
    116     test<double>();
    117     test<long double>();
    118     test_edges();
    119 }
    120