1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | |
3 | #define QUAD_PRECISION |
4 | #include <fenv.h> |
5 | #include <float.h> |
6 | #include <limits.h> |
7 | #include <math.h> |
8 | #include <stdio.h> |
9 | #include "fp_lib.h" |
10 | |
11 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) |
12 | |
13 | int test__compiler_rt_scalbnl(const char *mode, fp_t x, int y) { |
14 | fp_t crt_value = __compiler_rt_scalbnl(x, y); |
15 | fp_t libm_value = scalbnl(x, y); |
16 | // Consider +/-0 unequal, but disregard the sign/payload of NaN. |
17 | if (toRep(crt_value) != toRep(libm_value) && |
18 | !(crt_isnan(crt_value) && crt_isnan(libm_value))) { |
19 | // Split expected values into two for printf |
20 | twords x_t, crt_value_t, libm_value_t; |
21 | x_t.all = toRep(x); |
22 | crt_value_t.all = toRep(crt_value); |
23 | libm_value_t.all = toRep(libm_value); |
24 | printf( |
25 | "error: [%s] in __compiler_rt_scalbnl([%llX %llX], %d) = " |
26 | "[%llX %llX] != [%llX %llX]\n" , |
27 | mode, (unsigned long long)x_t.s.high, (unsigned long long)x_t.s.low, y, |
28 | (unsigned long long)crt_value_t.s.high, |
29 | (unsigned long long)crt_value_t.s.low, |
30 | (unsigned long long)libm_value_t.s.high, |
31 | (unsigned long long)libm_value_t.s.low); |
32 | return 1; |
33 | } |
34 | return 0; |
35 | } |
36 | |
37 | fp_t cases[] = { |
38 | -NAN, NAN, -INFINITY, INFINITY, -0.0, 0.0, -1, 1, -2, 2, |
39 | LDBL_TRUE_MIN, LDBL_MIN, LDBL_MAX, |
40 | -1.001, 1.001, -1.002, 1.002, 1.e-6, -1.e-6, |
41 | 0x1.0p-16381L, |
42 | 0x1.0p-16382L, |
43 | 0x1.0p-16383L, // subnormal |
44 | 0x1.0p-16384L, // subnormal |
45 | }; |
46 | |
47 | int iterate_cases(const char *mode) { |
48 | const unsigned N = sizeof(cases) / sizeof(cases[0]); |
49 | unsigned i; |
50 | for (i = 0; i < N; ++i) { |
51 | int j; |
52 | for (j = -5; j <= 5; ++j) { |
53 | if (test__compiler_rt_scalbnl(mode, cases[i], j)) return 1; |
54 | } |
55 | if (test__compiler_rt_scalbnl(mode, cases[i], -100000)) return 1; |
56 | if (test__compiler_rt_scalbnl(mode, cases[i], 100000)) return 1; |
57 | if (test__compiler_rt_scalbnl(mode, cases[i], INT_MIN)) return 1; |
58 | if (test__compiler_rt_scalbnl(mode, cases[i], INT_MAX)) return 1; |
59 | } |
60 | return 0; |
61 | } |
62 | |
63 | #endif |
64 | |
65 | int main() { |
66 | #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) |
67 | if (iterate_cases("default" )) return 1; |
68 | |
69 | // Skip rounding mode tests (fesetround) because compiler-rt's quad-precision |
70 | // multiply also ignores the current rounding mode. |
71 | |
72 | #else |
73 | printf("skipped\n" ); |
74 | #endif |
75 | |
76 | return 0; |
77 | } |
78 | |