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 //   tan(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(tan(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     test(std::complex<T>(10000, -10000), std::complex<T>(0, -1));
     34 }
     35 
     36 void test_edges()
     37 {
     38     typedef std::complex<double> C;
     39     const double pi = std::atan2(+0., -0.);
     40     const unsigned N = sizeof(x) / sizeof(x[0]);
     41     for (unsigned i = 0; i < N; ++i)
     42     {
     43         std::complex<double> r = tan(x[i]);
     44         std::complex<double> t1(-imag(x[i]), real(x[i]));
     45         std::complex<double> t2 = tanh(t1);
     46         std::complex<double> z(imag(t2), -real(t2));
     47         if (std::isnan(real(r)))
     48             assert(std::isnan(real(z)));
     49         else
     50         {
     51             assert(real(r) == real(z));
     52             assert(std::signbit(real(r)) == std::signbit(real(z)));
     53         }
     54         if (std::isnan(imag(r)))
     55             assert(std::isnan(imag(z)));
     56         else
     57         {
     58             assert(imag(r) == imag(z));
     59             assert(std::signbit(imag(r)) == std::signbit(imag(z)));
     60         }
     61     }
     62 }
     63 
     64 int main()
     65 {
     66     test<float>();
     67     test<double>();
     68     test<long double>();
     69     test_edges();
     70 }
     71