• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <complex>
10 
11 // template<class T>
12 //   complex<T>
13 //   cos(const complex<T>& x);
14 
15 #include <complex>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "../cases.h"
20 
21 template <class T>
22 void
test(const std::complex<T> & c,std::complex<T> x)23 test(const std::complex<T>& c, std::complex<T> x)
24 {
25     assert(cos(c) == x);
26 }
27 
28 template <class T>
29 void
test()30 test()
31 {
32     test(std::complex<T>(0, 0), std::complex<T>(1, 0));
33 }
34 
test_edges()35 void test_edges()
36 {
37     const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
38     for (unsigned i = 0; i < N; ++i)
39     {
40         std::complex<double> r = cos(testcases[i]);
41         std::complex<double> t1(-imag(testcases[i]), real(testcases[i]));
42         std::complex<double> z = cosh(t1);
43         if (std::isnan(real(r)))
44             assert(std::isnan(real(z)));
45         else
46         {
47             assert(real(r) == real(z));
48             assert(std::signbit(real(r)) == std::signbit(real(z)));
49         }
50         if (std::isnan(imag(r)))
51             assert(std::isnan(imag(z)));
52         else
53         {
54             assert(imag(r) == imag(z));
55             assert(std::signbit(imag(r)) == std::signbit(imag(z)));
56         }
57     }
58 }
59 
main(int,char **)60 int main(int, char**)
61 {
62     test<float>();
63     test<double>();
64     test<long double>();
65     test_edges();
66 
67   return 0;
68 }
69