xref: /minix3/external/bsd/libc++/dist/libcxx/test/std/numerics/complex.number/cases.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*0a6a1f1dSLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc //
8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
9*0a6a1f1dSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc // <complex>
11*0a6a1f1dSLionel Sambuc 
12*0a6a1f1dSLionel Sambuc // test cases
13*0a6a1f1dSLionel Sambuc 
14*0a6a1f1dSLionel Sambuc #ifndef CASES_H
15*0a6a1f1dSLionel Sambuc #define CASES_H
16*0a6a1f1dSLionel Sambuc 
17*0a6a1f1dSLionel Sambuc #include <complex>
18*0a6a1f1dSLionel Sambuc #include <cassert>
19*0a6a1f1dSLionel Sambuc 
20*0a6a1f1dSLionel Sambuc std::complex<double> x[] =
21*0a6a1f1dSLionel Sambuc {
22*0a6a1f1dSLionel Sambuc     std::complex<double>( 1.e-6,  1.e-6),
23*0a6a1f1dSLionel Sambuc     std::complex<double>(-1.e-6,  1.e-6),
24*0a6a1f1dSLionel Sambuc     std::complex<double>(-1.e-6, -1.e-6),
25*0a6a1f1dSLionel Sambuc     std::complex<double>( 1.e-6, -1.e-6),
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc     std::complex<double>( 1.e+6,  1.e-6),
28*0a6a1f1dSLionel Sambuc     std::complex<double>(-1.e+6,  1.e-6),
29*0a6a1f1dSLionel Sambuc     std::complex<double>(-1.e+6, -1.e-6),
30*0a6a1f1dSLionel Sambuc     std::complex<double>( 1.e+6, -1.e-6),
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc     std::complex<double>( 1.e-6,  1.e+6),
33*0a6a1f1dSLionel Sambuc     std::complex<double>(-1.e-6,  1.e+6),
34*0a6a1f1dSLionel Sambuc     std::complex<double>(-1.e-6, -1.e+6),
35*0a6a1f1dSLionel Sambuc     std::complex<double>( 1.e-6, -1.e+6),
36*0a6a1f1dSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc     std::complex<double>( 1.e+6,  1.e+6),
38*0a6a1f1dSLionel Sambuc     std::complex<double>(-1.e+6,  1.e+6),
39*0a6a1f1dSLionel Sambuc     std::complex<double>(-1.e+6, -1.e+6),
40*0a6a1f1dSLionel Sambuc     std::complex<double>( 1.e+6, -1.e+6),
41*0a6a1f1dSLionel Sambuc 
42*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, NAN),
43*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, NAN),
44*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, NAN),
45*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, NAN),
46*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, NAN),
47*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., NAN),
48*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., NAN),
49*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, NAN),
50*0a6a1f1dSLionel Sambuc     std::complex<double>(1, NAN),
51*0a6a1f1dSLionel Sambuc     std::complex<double>(2, NAN),
52*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, NAN),
53*0a6a1f1dSLionel Sambuc 
54*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, -INFINITY),
55*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, -INFINITY),
56*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, -INFINITY),
57*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, -INFINITY),
58*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, -INFINITY),
59*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., -INFINITY),
60*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., -INFINITY),
61*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, -INFINITY),
62*0a6a1f1dSLionel Sambuc     std::complex<double>(1, -INFINITY),
63*0a6a1f1dSLionel Sambuc     std::complex<double>(2, -INFINITY),
64*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, -INFINITY),
65*0a6a1f1dSLionel Sambuc 
66*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, -2),
67*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, -2),
68*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, -2),
69*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, -2),
70*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, -2),
71*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., -2),
72*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., -2),
73*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, -2),
74*0a6a1f1dSLionel Sambuc     std::complex<double>(1, -2),
75*0a6a1f1dSLionel Sambuc     std::complex<double>(2, -2),
76*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, -2),
77*0a6a1f1dSLionel Sambuc 
78*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, -1),
79*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, -1),
80*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, -1),
81*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, -1),
82*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, -1),
83*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., -1),
84*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., -1),
85*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, -1),
86*0a6a1f1dSLionel Sambuc     std::complex<double>(1, -1),
87*0a6a1f1dSLionel Sambuc     std::complex<double>(2, -1),
88*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, -1),
89*0a6a1f1dSLionel Sambuc 
90*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, -0.5),
91*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, -0.5),
92*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, -0.5),
93*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, -0.5),
94*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, -0.5),
95*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., -0.5),
96*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., -0.5),
97*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, -0.5),
98*0a6a1f1dSLionel Sambuc     std::complex<double>(1, -0.5),
99*0a6a1f1dSLionel Sambuc     std::complex<double>(2, -0.5),
100*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, -0.5),
101*0a6a1f1dSLionel Sambuc 
102*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, -0.),
103*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, -0.),
104*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, -0.),
105*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, -0.),
106*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, -0.),
107*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., -0.),
108*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., -0.),
109*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, -0.),
110*0a6a1f1dSLionel Sambuc     std::complex<double>(1, -0.),
111*0a6a1f1dSLionel Sambuc     std::complex<double>(2, -0.),
112*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, -0.),
113*0a6a1f1dSLionel Sambuc 
114*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, +0.),
115*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, +0.),
116*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, +0.),
117*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, +0.),
118*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, +0.),
119*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., +0.),
120*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., +0.),
121*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, +0.),
122*0a6a1f1dSLionel Sambuc     std::complex<double>(1, +0.),
123*0a6a1f1dSLionel Sambuc     std::complex<double>(2, +0.),
124*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, +0.),
125*0a6a1f1dSLionel Sambuc 
126*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, 0.5),
127*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, 0.5),
128*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, 0.5),
129*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, 0.5),
130*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, 0.5),
131*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., 0.5),
132*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., 0.5),
133*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, 0.5),
134*0a6a1f1dSLionel Sambuc     std::complex<double>(1, 0.5),
135*0a6a1f1dSLionel Sambuc     std::complex<double>(2, 0.5),
136*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, 0.5),
137*0a6a1f1dSLionel Sambuc 
138*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, 1),
139*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, 1),
140*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, 1),
141*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, 1),
142*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, 1),
143*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., 1),
144*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., 1),
145*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, 1),
146*0a6a1f1dSLionel Sambuc     std::complex<double>(1, 1),
147*0a6a1f1dSLionel Sambuc     std::complex<double>(2, 1),
148*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, 1),
149*0a6a1f1dSLionel Sambuc 
150*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, 2),
151*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, 2),
152*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, 2),
153*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, 2),
154*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, 2),
155*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., 2),
156*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., 2),
157*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, 2),
158*0a6a1f1dSLionel Sambuc     std::complex<double>(1, 2),
159*0a6a1f1dSLionel Sambuc     std::complex<double>(2, 2),
160*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, 2),
161*0a6a1f1dSLionel Sambuc 
162*0a6a1f1dSLionel Sambuc     std::complex<double>(NAN, INFINITY),
163*0a6a1f1dSLionel Sambuc     std::complex<double>(-INFINITY, INFINITY),
164*0a6a1f1dSLionel Sambuc     std::complex<double>(-2, INFINITY),
165*0a6a1f1dSLionel Sambuc     std::complex<double>(-1, INFINITY),
166*0a6a1f1dSLionel Sambuc     std::complex<double>(-0.5, INFINITY),
167*0a6a1f1dSLionel Sambuc     std::complex<double>(-0., INFINITY),
168*0a6a1f1dSLionel Sambuc     std::complex<double>(+0., INFINITY),
169*0a6a1f1dSLionel Sambuc     std::complex<double>(0.5, INFINITY),
170*0a6a1f1dSLionel Sambuc     std::complex<double>(1, INFINITY),
171*0a6a1f1dSLionel Sambuc     std::complex<double>(2, INFINITY),
172*0a6a1f1dSLionel Sambuc     std::complex<double>(INFINITY, INFINITY)
173*0a6a1f1dSLionel Sambuc };
174*0a6a1f1dSLionel Sambuc 
175*0a6a1f1dSLionel Sambuc enum {zero, non_zero, inf, NaN, non_zero_nan};
176*0a6a1f1dSLionel Sambuc 
177*0a6a1f1dSLionel Sambuc template <class T>
178*0a6a1f1dSLionel Sambuc int
classify(const std::complex<T> & x)179*0a6a1f1dSLionel Sambuc classify(const std::complex<T>& x)
180*0a6a1f1dSLionel Sambuc {
181*0a6a1f1dSLionel Sambuc     if (x == std::complex<T>())
182*0a6a1f1dSLionel Sambuc         return zero;
183*0a6a1f1dSLionel Sambuc     if (std::isinf(x.real()) || std::isinf(x.imag()))
184*0a6a1f1dSLionel Sambuc         return inf;
185*0a6a1f1dSLionel Sambuc     if (std::isnan(x.real()) && std::isnan(x.imag()))
186*0a6a1f1dSLionel Sambuc         return NaN;
187*0a6a1f1dSLionel Sambuc     if (std::isnan(x.real()))
188*0a6a1f1dSLionel Sambuc     {
189*0a6a1f1dSLionel Sambuc         if (x.imag() == T(0))
190*0a6a1f1dSLionel Sambuc             return NaN;
191*0a6a1f1dSLionel Sambuc         return non_zero_nan;
192*0a6a1f1dSLionel Sambuc     }
193*0a6a1f1dSLionel Sambuc     if (std::isnan(x.imag()))
194*0a6a1f1dSLionel Sambuc     {
195*0a6a1f1dSLionel Sambuc         if (x.real() == T(0))
196*0a6a1f1dSLionel Sambuc             return NaN;
197*0a6a1f1dSLionel Sambuc         return non_zero_nan;
198*0a6a1f1dSLionel Sambuc     }
199*0a6a1f1dSLionel Sambuc     return non_zero;
200*0a6a1f1dSLionel Sambuc }
201*0a6a1f1dSLionel Sambuc 
202*0a6a1f1dSLionel Sambuc inline
203*0a6a1f1dSLionel Sambuc int
classify(double x)204*0a6a1f1dSLionel Sambuc classify(double x)
205*0a6a1f1dSLionel Sambuc {
206*0a6a1f1dSLionel Sambuc     if (x == 0)
207*0a6a1f1dSLionel Sambuc         return zero;
208*0a6a1f1dSLionel Sambuc     if (std::isinf(x))
209*0a6a1f1dSLionel Sambuc         return inf;
210*0a6a1f1dSLionel Sambuc     if (std::isnan(x))
211*0a6a1f1dSLionel Sambuc         return NaN;
212*0a6a1f1dSLionel Sambuc     return non_zero;
213*0a6a1f1dSLionel Sambuc }
214*0a6a1f1dSLionel Sambuc 
is_about(float x,float y)215*0a6a1f1dSLionel Sambuc void is_about(float x, float y)
216*0a6a1f1dSLionel Sambuc {
217*0a6a1f1dSLionel Sambuc     assert(std::abs((x-y)/(x+y)) < 1.e-6);
218*0a6a1f1dSLionel Sambuc }
219*0a6a1f1dSLionel Sambuc 
is_about(double x,double y)220*0a6a1f1dSLionel Sambuc void is_about(double x, double y)
221*0a6a1f1dSLionel Sambuc {
222*0a6a1f1dSLionel Sambuc     assert(std::abs((x-y)/(x+y)) < 1.e-14);
223*0a6a1f1dSLionel Sambuc }
224*0a6a1f1dSLionel Sambuc 
is_about(long double x,long double y)225*0a6a1f1dSLionel Sambuc void is_about(long double x, long double y)
226*0a6a1f1dSLionel Sambuc {
227*0a6a1f1dSLionel Sambuc     assert(std::abs((x-y)/(x+y)) < 1.e-14);
228*0a6a1f1dSLionel Sambuc }
229*0a6a1f1dSLionel Sambuc 
230*0a6a1f1dSLionel Sambuc #endif  // CASES_H
231