1*4684ddb6SLionel Sambuc //===-- powitf2_test.cpp - Test __powitf2 ---------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __powitf2 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc
14*4684ddb6SLionel Sambuc #if _ARCH_PPC
15*4684ddb6SLionel Sambuc
16*4684ddb6SLionel Sambuc #include "int_lib.h"
17*4684ddb6SLionel Sambuc #include <stdio.h>
18*4684ddb6SLionel Sambuc #include <math.h>
19*4684ddb6SLionel Sambuc
20*4684ddb6SLionel Sambuc // Returns: a ^ b
21*4684ddb6SLionel Sambuc
22*4684ddb6SLionel Sambuc long double __powitf2(long double a, si_int b);
23*4684ddb6SLionel Sambuc
test__powitf2(long double a,si_int b,long double expected)24*4684ddb6SLionel Sambuc int test__powitf2(long double a, si_int b, long double expected)
25*4684ddb6SLionel Sambuc {
26*4684ddb6SLionel Sambuc long double x = __powitf2(a, b);
27*4684ddb6SLionel Sambuc int correct = (x == expected) && (signbit(x) == signbit(expected));
28*4684ddb6SLionel Sambuc if (!correct)
29*4684ddb6SLionel Sambuc printf("error in __powitf2(%Lf, %d) = %Lf, expected %Lf\n",
30*4684ddb6SLionel Sambuc a, b, x, expected);
31*4684ddb6SLionel Sambuc return !correct;
32*4684ddb6SLionel Sambuc }
33*4684ddb6SLionel Sambuc
34*4684ddb6SLionel Sambuc #endif
35*4684ddb6SLionel Sambuc
main()36*4684ddb6SLionel Sambuc int main()
37*4684ddb6SLionel Sambuc {
38*4684ddb6SLionel Sambuc #if _ARCH_PPC
39*4684ddb6SLionel Sambuc if (test__powitf2(0, 0, 1))
40*4684ddb6SLionel Sambuc return 1;
41*4684ddb6SLionel Sambuc if (test__powitf2(1, 0, 1))
42*4684ddb6SLionel Sambuc return 1;
43*4684ddb6SLionel Sambuc if (test__powitf2(1.5, 0, 1))
44*4684ddb6SLionel Sambuc return 1;
45*4684ddb6SLionel Sambuc if (test__powitf2(2, 0, 1))
46*4684ddb6SLionel Sambuc return 1;
47*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 0, 1))
48*4684ddb6SLionel Sambuc return 1;
49*4684ddb6SLionel Sambuc
50*4684ddb6SLionel Sambuc if (test__powitf2(-0., 0, 1))
51*4684ddb6SLionel Sambuc return 1;
52*4684ddb6SLionel Sambuc if (test__powitf2(-1, 0, 1))
53*4684ddb6SLionel Sambuc return 1;
54*4684ddb6SLionel Sambuc if (test__powitf2(-1.5, 0, 1))
55*4684ddb6SLionel Sambuc return 1;
56*4684ddb6SLionel Sambuc if (test__powitf2(-2, 0, 1))
57*4684ddb6SLionel Sambuc return 1;
58*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 0, 1))
59*4684ddb6SLionel Sambuc return 1;
60*4684ddb6SLionel Sambuc
61*4684ddb6SLionel Sambuc if (test__powitf2(0, 1, 0))
62*4684ddb6SLionel Sambuc return 1;
63*4684ddb6SLionel Sambuc if (test__powitf2(0, 2, 0))
64*4684ddb6SLionel Sambuc return 1;
65*4684ddb6SLionel Sambuc if (test__powitf2(0, 3, 0))
66*4684ddb6SLionel Sambuc return 1;
67*4684ddb6SLionel Sambuc if (test__powitf2(0, 4, 0))
68*4684ddb6SLionel Sambuc return 1;
69*4684ddb6SLionel Sambuc if (test__powitf2(0, 0x7FFFFFFE, 0))
70*4684ddb6SLionel Sambuc return 1;
71*4684ddb6SLionel Sambuc if (test__powitf2(0, 0x7FFFFFFF, 0))
72*4684ddb6SLionel Sambuc return 1;
73*4684ddb6SLionel Sambuc
74*4684ddb6SLionel Sambuc if (test__powitf2(-0., 1, -0.))
75*4684ddb6SLionel Sambuc return 1;
76*4684ddb6SLionel Sambuc if (test__powitf2(-0., 2, 0))
77*4684ddb6SLionel Sambuc return 1;
78*4684ddb6SLionel Sambuc if (test__powitf2(-0., 3, -0.))
79*4684ddb6SLionel Sambuc return 1;
80*4684ddb6SLionel Sambuc if (test__powitf2(-0., 4, 0))
81*4684ddb6SLionel Sambuc return 1;
82*4684ddb6SLionel Sambuc if (test__powitf2(-0., 0x7FFFFFFE, 0))
83*4684ddb6SLionel Sambuc return 1;
84*4684ddb6SLionel Sambuc if (test__powitf2(-0., 0x7FFFFFFF, -0.))
85*4684ddb6SLionel Sambuc return 1;
86*4684ddb6SLionel Sambuc
87*4684ddb6SLionel Sambuc if (test__powitf2(1, 1, 1))
88*4684ddb6SLionel Sambuc return 1;
89*4684ddb6SLionel Sambuc if (test__powitf2(1, 2, 1))
90*4684ddb6SLionel Sambuc return 1;
91*4684ddb6SLionel Sambuc if (test__powitf2(1, 3, 1))
92*4684ddb6SLionel Sambuc return 1;
93*4684ddb6SLionel Sambuc if (test__powitf2(1, 4, 1))
94*4684ddb6SLionel Sambuc return 1;
95*4684ddb6SLionel Sambuc if (test__powitf2(1, 0x7FFFFFFE, 1))
96*4684ddb6SLionel Sambuc return 1;
97*4684ddb6SLionel Sambuc if (test__powitf2(1, 0x7FFFFFFF, 1))
98*4684ddb6SLionel Sambuc return 1;
99*4684ddb6SLionel Sambuc
100*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 1, INFINITY))
101*4684ddb6SLionel Sambuc return 1;
102*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 2, INFINITY))
103*4684ddb6SLionel Sambuc return 1;
104*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 3, INFINITY))
105*4684ddb6SLionel Sambuc return 1;
106*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 4, INFINITY))
107*4684ddb6SLionel Sambuc return 1;
108*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 0x7FFFFFFE, INFINITY))
109*4684ddb6SLionel Sambuc return 1;
110*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 0x7FFFFFFF, INFINITY))
111*4684ddb6SLionel Sambuc return 1;
112*4684ddb6SLionel Sambuc
113*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 1, -INFINITY))
114*4684ddb6SLionel Sambuc return 1;
115*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 2, INFINITY))
116*4684ddb6SLionel Sambuc return 1;
117*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 3, -INFINITY))
118*4684ddb6SLionel Sambuc return 1;
119*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 4, INFINITY))
120*4684ddb6SLionel Sambuc return 1;
121*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 0x7FFFFFFE, INFINITY))
122*4684ddb6SLionel Sambuc return 1;
123*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 0x7FFFFFFF, -INFINITY))
124*4684ddb6SLionel Sambuc return 1;
125*4684ddb6SLionel Sambuc
126*4684ddb6SLionel Sambuc if (test__powitf2(0, -1, INFINITY))
127*4684ddb6SLionel Sambuc return 1;
128*4684ddb6SLionel Sambuc if (test__powitf2(0, -2, INFINITY))
129*4684ddb6SLionel Sambuc return 1;
130*4684ddb6SLionel Sambuc if (test__powitf2(0, -3, INFINITY))
131*4684ddb6SLionel Sambuc return 1;
132*4684ddb6SLionel Sambuc if (test__powitf2(0, -4, INFINITY))
133*4684ddb6SLionel Sambuc return 1;
134*4684ddb6SLionel Sambuc if (test__powitf2(0, 0x80000002, INFINITY))
135*4684ddb6SLionel Sambuc return 1;
136*4684ddb6SLionel Sambuc if (test__powitf2(0, 0x80000001, INFINITY))
137*4684ddb6SLionel Sambuc return 1;
138*4684ddb6SLionel Sambuc if (test__powitf2(0, 0x80000000, INFINITY))
139*4684ddb6SLionel Sambuc return 1;
140*4684ddb6SLionel Sambuc
141*4684ddb6SLionel Sambuc if (test__powitf2(-0., -1, -INFINITY))
142*4684ddb6SLionel Sambuc return 1;
143*4684ddb6SLionel Sambuc if (test__powitf2(-0., -2, INFINITY))
144*4684ddb6SLionel Sambuc return 1;
145*4684ddb6SLionel Sambuc if (test__powitf2(-0., -3, -INFINITY))
146*4684ddb6SLionel Sambuc return 1;
147*4684ddb6SLionel Sambuc if (test__powitf2(-0., -4, INFINITY))
148*4684ddb6SLionel Sambuc return 1;
149*4684ddb6SLionel Sambuc if (test__powitf2(-0., 0x80000002, INFINITY))
150*4684ddb6SLionel Sambuc return 1;
151*4684ddb6SLionel Sambuc if (test__powitf2(-0., 0x80000001, -INFINITY))
152*4684ddb6SLionel Sambuc return 1;
153*4684ddb6SLionel Sambuc if (test__powitf2(-0., 0x80000000, INFINITY))
154*4684ddb6SLionel Sambuc return 1;
155*4684ddb6SLionel Sambuc
156*4684ddb6SLionel Sambuc if (test__powitf2(1, -1, 1))
157*4684ddb6SLionel Sambuc return 1;
158*4684ddb6SLionel Sambuc if (test__powitf2(1, -2, 1))
159*4684ddb6SLionel Sambuc return 1;
160*4684ddb6SLionel Sambuc if (test__powitf2(1, -3, 1))
161*4684ddb6SLionel Sambuc return 1;
162*4684ddb6SLionel Sambuc if (test__powitf2(1, -4, 1))
163*4684ddb6SLionel Sambuc return 1;
164*4684ddb6SLionel Sambuc if (test__powitf2(1, 0x80000002, 1))
165*4684ddb6SLionel Sambuc return 1;
166*4684ddb6SLionel Sambuc if (test__powitf2(1, 0x80000001, 1))
167*4684ddb6SLionel Sambuc return 1;
168*4684ddb6SLionel Sambuc if (test__powitf2(1, 0x80000000, 1))
169*4684ddb6SLionel Sambuc return 1;
170*4684ddb6SLionel Sambuc
171*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, -1, 0))
172*4684ddb6SLionel Sambuc return 1;
173*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, -2, 0))
174*4684ddb6SLionel Sambuc return 1;
175*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, -3, 0))
176*4684ddb6SLionel Sambuc return 1;
177*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, -4, 0))
178*4684ddb6SLionel Sambuc return 1;
179*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 0x80000002, 0))
180*4684ddb6SLionel Sambuc return 1;
181*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 0x80000001, 0))
182*4684ddb6SLionel Sambuc return 1;
183*4684ddb6SLionel Sambuc if (test__powitf2(INFINITY, 0x80000000, 0))
184*4684ddb6SLionel Sambuc return 1;
185*4684ddb6SLionel Sambuc
186*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, -1, -0.))
187*4684ddb6SLionel Sambuc return 1;
188*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, -2, 0))
189*4684ddb6SLionel Sambuc return 1;
190*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, -3, -0.))
191*4684ddb6SLionel Sambuc return 1;
192*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, -4, 0))
193*4684ddb6SLionel Sambuc return 1;
194*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 0x80000002, 0))
195*4684ddb6SLionel Sambuc return 1;
196*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 0x80000001, -0.))
197*4684ddb6SLionel Sambuc return 1;
198*4684ddb6SLionel Sambuc if (test__powitf2(-INFINITY, 0x80000000, 0))
199*4684ddb6SLionel Sambuc return 1;
200*4684ddb6SLionel Sambuc
201*4684ddb6SLionel Sambuc if (test__powitf2(2, 10, 1024.))
202*4684ddb6SLionel Sambuc return 1;
203*4684ddb6SLionel Sambuc if (test__powitf2(-2, 10, 1024.))
204*4684ddb6SLionel Sambuc return 1;
205*4684ddb6SLionel Sambuc if (test__powitf2(2, -10, 1/1024.))
206*4684ddb6SLionel Sambuc return 1;
207*4684ddb6SLionel Sambuc if (test__powitf2(-2, -10, 1/1024.))
208*4684ddb6SLionel Sambuc return 1;
209*4684ddb6SLionel Sambuc
210*4684ddb6SLionel Sambuc if (test__powitf2(2, 19, 524288.))
211*4684ddb6SLionel Sambuc return 1;
212*4684ddb6SLionel Sambuc if (test__powitf2(-2, 19, -524288.))
213*4684ddb6SLionel Sambuc return 1;
214*4684ddb6SLionel Sambuc if (test__powitf2(2, -19, 1/524288.))
215*4684ddb6SLionel Sambuc return 1;
216*4684ddb6SLionel Sambuc if (test__powitf2(-2, -19, -1/524288.))
217*4684ddb6SLionel Sambuc return 1;
218*4684ddb6SLionel Sambuc
219*4684ddb6SLionel Sambuc if (test__powitf2(2, 31, 2147483648.))
220*4684ddb6SLionel Sambuc return 1;
221*4684ddb6SLionel Sambuc if (test__powitf2(-2, 31, -2147483648.))
222*4684ddb6SLionel Sambuc return 1;
223*4684ddb6SLionel Sambuc if (test__powitf2(2, -31, 1/2147483648.))
224*4684ddb6SLionel Sambuc return 1;
225*4684ddb6SLionel Sambuc if (test__powitf2(-2, -31, -1/2147483648.))
226*4684ddb6SLionel Sambuc return 1;
227*4684ddb6SLionel Sambuc
228*4684ddb6SLionel Sambuc #else
229*4684ddb6SLionel Sambuc printf("skipped\n");
230*4684ddb6SLionel Sambuc #endif
231*4684ddb6SLionel Sambuc return 0;
232*4684ddb6SLionel Sambuc }
233