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 //   cosh(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(cosh(c) == x);
     26 }
     27 
     28 template <class T>
     29 void
     30 test()
     31 {
     32     test(std::complex<T>(0, 0), std::complex<T>(1, 0));
     33 }
     34 
     35 void test_edges()
     36 {
     37     typedef std::complex<double> C;
     38     const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
     39     for (unsigned i = 0; i < N; ++i)
     40     {
     41         std::complex<double> r = cosh(testcases[i]);
     42         if (testcases[i].real() == 0 && testcases[i].imag() == 0)
     43         {
     44             assert(r.real() == 1);
     45             assert(r.imag() == 0);
     46             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
     47         }
     48         else if (testcases[i].real() == 0 && std::isinf(testcases[i].imag()))
     49         {
     50             assert(std::isnan(r.real()));
     51             assert(r.imag() == 0);
     52         }
     53         else if (testcases[i].real() == 0 && std::isnan(testcases[i].imag()))
     54         {
     55             assert(std::isnan(r.real()));
     56             assert(r.imag() == 0);
     57         }
     58         else if (std::isfinite(testcases[i].real()) && std::isinf(testcases[i].imag()))
     59         {
     60             assert(std::isnan(r.real()));
     61             assert(std::isnan(r.imag()));
     62         }
     63         else if (std::isfinite(testcases[i].real()) && std::isnan(testcases[i].imag()))
     64         {
     65             assert(std::isnan(r.real()));
     66             assert(std::isnan(r.imag()));
     67         }
     68         else if (std::isinf(testcases[i].real()) && testcases[i].imag() == 0)
     69         {
     70             assert(std::isinf(r.real()));
     71             assert(!std::signbit(r.real()));
     72             assert(r.imag() == 0);
     73             assert(std::signbit(r.imag()) == std::signbit(testcases[i].imag()));
     74         }
     75         else if (std::isinf(testcases[i].real()) && std::isfinite(testcases[i].imag()))
     76         {
     77             assert(std::isinf(r.real()));
     78             assert(std::signbit(r.real()) == std::signbit(cos(testcases[i].imag())));
     79             assert(std::isinf(r.imag()));
     80             assert(std::signbit(r.imag()) == std::signbit(testcases[i].real() * sin(testcases[i].imag())));
     81         }
     82         else if (std::isinf(testcases[i].real()) && std::isinf(testcases[i].imag()))
     83         {
     84             assert(std::isinf(r.real()));
     85             assert(std::isnan(r.imag()));
     86         }
     87         else if (std::isinf(testcases[i].real()) && std::isnan(testcases[i].imag()))
     88         {
     89             assert(std::isinf(r.real()));
     90             assert(r.real() > 0);
     91             assert(std::isnan(r.imag()));
     92         }
     93         else if (std::isnan(testcases[i].real()) && testcases[i].imag() == 0)
     94         {
     95             assert(std::isnan(r.real()));
     96             assert(r.imag() == 0);
     97         }
     98         else if (std::isnan(testcases[i].real()) && std::isfinite(testcases[i].imag()))
     99         {
    100             assert(std::isnan(r.real()));
    101             assert(std::isnan(r.imag()));
    102         }
    103         else if (std::isnan(testcases[i].real()) && std::isnan(testcases[i].imag()))
    104         {
    105             assert(std::isnan(r.real()));
    106             assert(std::isnan(r.imag()));
    107         }
    108     }
    109 }
    110 
    111 int main()
    112 {
    113     test<float>();
    114     test<double>();
    115     test<long double>();
    116     test_edges();
    117 }
    118