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