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