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