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