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