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