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 //   acosh(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(acosh(c) == x);
     26 }
     27 
     28 template <class T>
     29 void
     30 test()
     31 {
     32     test(std::complex<T>(INFINITY, 1), std::complex<T>(INFINITY, 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 = acosh(testcases[i]);
     43         if (testcases[i].real() == 0 && testcases[i].imag() == 0)
     44         {
     45             assert(!std::signbit(r.real()));
     46             if (std::signbit(testcases[i].imag()))
     47                 is_about(r.imag(), -pi/2);
     48             else
     49                 is_about(r.imag(),  pi/2);
     50         }
     51         else if (testcases[i].real() == 1 && testcases[i].imag() == 0)
     52         {
     53             assert(r.real() == 0);
     54             assert(!std::signbit(r.real()));
     55             assert(r.imag() == 0);
     56             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
     57         }
     58         else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
     59         {
     60             assert(std::isinf(r.real()));
     61             assert(r.real() > 0);
     62             if (std::signbit(testcases[i].imag()))
     63                 is_about(r.imag(), -pi/2);
     64             else
     65                 is_about(r.imag(),  pi/2);
     66         }
     67         else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag()))
     68         {
     69             assert(std::isnan(r.real()));
     70             assert(std::isnan(r.imag()));
     71         }
     72         else if (std::isinf(testcases[i].real()) && testcases[i].real() < 0 && std::isfinite(testcases[i].imag()))
     73         {
     74             assert(std::isinf(r.real()));
     75             assert(r.real() > 0);
     76             if (std::signbit(testcases[i].imag()))
     77                 is_about(r.imag(), -pi);
     78             else
     79                 is_about(r.imag(),  pi);
     80         }
     81         else if (std::isinf(testcases[i].real()) && testcases[i].real() > 0 && std::isfinite(testcases[i].imag()))
     82         {
     83             assert(std::isinf(r.real()));
     84             assert(r.real() > 0);
     85             assert(r.imag() == 0);
     86             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
     87         }
     88         else if (std::isinf(testcases[i].real()) && testcases[i].real() < 0 && std::isinf(testcases[i].imag()))
     89         {
     90             assert(std::isinf(r.real()));
     91             assert(r.real() > 0);
     92             if (std::signbit(testcases[i].imag()))
     93                 is_about(r.imag(), -0.75 * pi);
     94             else
     95                 is_about(r.imag(),  0.75 * pi);
     96         }
     97         else if (std::isinf(testcases[i].real()) && testcases[i].real() > 0 && std::isinf(testcases[i].imag()))
     98         {
     99             assert(std::isinf(r.real()));
    100             assert(r.real() > 0);
    101             if (std::signbit(testcases[i].imag()))
    102                 is_about(r.imag(), -0.25 * pi);
    103             else
    104                 is_about(r.imag(),  0.25 * pi);
    105         }
    106         else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
    107         {
    108             assert(std::isinf(r.real()));
    109             assert(r.real() > 0);
    110             assert(std::isnan(r.imag()));
    111         }
    112         else if (std::isnan(testcases[i].real()) && std::isfinite(testcases[i].imag()))
    113         {
    114             assert(std::isnan(r.real()));
    115             assert(std::isnan(r.imag()));
    116         }
    117         else if (std::isnan(testcases[i].real()) && std::isinf(testcases[i].imag()))
    118         {
    119             assert(std::isinf(r.real()));
    120             assert(r.real() > 0);
    121             assert(std::isnan(r.imag()));
    122         }
    123         else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag()))
    124         {
    125             assert(std::isnan(r.real()));
    126             assert(std::isnan(r.imag()));
    127         }
    128         else
    129         {
    130             assert(!std::signbit(r.real()));
    131             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
    132         }
    133     }
    134 }
    135 
    136 int main()
    137 {
    138     test<float>();
    139     test<double>();
    140     test<long double>();
    141     test_edges();
    142 }
    143