1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_floatdidf |
3 | |
4 | #include "int_lib.h" |
5 | #include <float.h> |
6 | #include <stdio.h> |
7 | |
8 | // Returns: convert a to a double, rounding toward even. |
9 | |
10 | // Assumption: double is a IEEE 64 bit floating point type |
11 | // di_int is a 64 bit integral type |
12 | |
13 | // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm |
14 | |
15 | COMPILER_RT_ABI double __floatdidf(di_int a); |
16 | |
17 | int test__floatdidf(di_int a, double expected) |
18 | { |
19 | double x = __floatdidf(a); |
20 | if (x != expected) |
21 | printf(format: "error in __floatdidf(%llX) = %a, expected %a\n" , a, x, expected); |
22 | return x != expected; |
23 | } |
24 | |
25 | char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0}; |
26 | char assumption_2[sizeof(di_int)*CHAR_BIT == 64] = {0}; |
27 | char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0}; |
28 | |
29 | int main() |
30 | { |
31 | if (test__floatdidf(a: 0, expected: 0.0)) |
32 | return 1; |
33 | |
34 | if (test__floatdidf(a: 1, expected: 1.0)) |
35 | return 1; |
36 | if (test__floatdidf(a: 2, expected: 2.0)) |
37 | return 1; |
38 | if (test__floatdidf(a: 20, expected: 20.0)) |
39 | return 1; |
40 | if (test__floatdidf(a: -1, expected: -1.0)) |
41 | return 1; |
42 | if (test__floatdidf(a: -2, expected: -2.0)) |
43 | return 1; |
44 | if (test__floatdidf(a: -20, expected: -20.0)) |
45 | return 1; |
46 | |
47 | if (test__floatdidf(a: 0x7FFFFF8000000000LL, expected: 0x1.FFFFFEp+62)) |
48 | return 1; |
49 | if (test__floatdidf(a: 0x7FFFFFFFFFFFF800LL, expected: 0x1.FFFFFFFFFFFFEp+62)) |
50 | return 1; |
51 | if (test__floatdidf(a: 0x7FFFFF0000000000LL, expected: 0x1.FFFFFCp+62)) |
52 | return 1; |
53 | if (test__floatdidf(a: 0x7FFFFFFFFFFFF000LL, expected: 0x1.FFFFFFFFFFFFCp+62)) |
54 | return 1; |
55 | |
56 | if (test__floatdidf(a: 0x8000008000000000LL, expected: -0x1.FFFFFEp+62)) |
57 | return 1; |
58 | if (test__floatdidf(a: 0x8000000000000800LL, expected: -0x1.FFFFFFFFFFFFEp+62)) |
59 | return 1; |
60 | if (test__floatdidf(a: 0x8000010000000000LL, expected: -0x1.FFFFFCp+62)) |
61 | return 1; |
62 | if (test__floatdidf(a: 0x8000000000001000LL, expected: -0x1.FFFFFFFFFFFFCp+62)) |
63 | return 1; |
64 | |
65 | if (test__floatdidf(a: 0x8000000000000000LL, expected: -0x1.000000p+63)) |
66 | return 1; |
67 | if (test__floatdidf(a: 0x8000000000000001LL, expected: -0x1.000000p+63)) |
68 | return 1; |
69 | |
70 | if (test__floatdidf(a: 0x0007FB72E8000000LL, expected: 0x1.FEDCBAp+50)) |
71 | return 1; |
72 | |
73 | if (test__floatdidf(a: 0x0007FB72EA000000LL, expected: 0x1.FEDCBA8p+50)) |
74 | return 1; |
75 | if (test__floatdidf(a: 0x0007FB72EB000000LL, expected: 0x1.FEDCBACp+50)) |
76 | return 1; |
77 | if (test__floatdidf(a: 0x0007FB72EBFFFFFFLL, expected: 0x1.FEDCBAFFFFFFCp+50)) |
78 | return 1; |
79 | if (test__floatdidf(a: 0x0007FB72EC000000LL, expected: 0x1.FEDCBBp+50)) |
80 | return 1; |
81 | if (test__floatdidf(a: 0x0007FB72E8000001LL, expected: 0x1.FEDCBA0000004p+50)) |
82 | return 1; |
83 | |
84 | if (test__floatdidf(a: 0x0007FB72E6000000LL, expected: 0x1.FEDCB98p+50)) |
85 | return 1; |
86 | if (test__floatdidf(a: 0x0007FB72E7000000LL, expected: 0x1.FEDCB9Cp+50)) |
87 | return 1; |
88 | if (test__floatdidf(a: 0x0007FB72E7FFFFFFLL, expected: 0x1.FEDCB9FFFFFFCp+50)) |
89 | return 1; |
90 | if (test__floatdidf(a: 0x0007FB72E4000001LL, expected: 0x1.FEDCB90000004p+50)) |
91 | return 1; |
92 | if (test__floatdidf(a: 0x0007FB72E4000000LL, expected: 0x1.FEDCB9p+50)) |
93 | return 1; |
94 | |
95 | if (test__floatdidf(a: 0x023479FD0E092DC0LL, expected: 0x1.1A3CFE870496Ep+57)) |
96 | return 1; |
97 | if (test__floatdidf(a: 0x023479FD0E092DA1LL, expected: 0x1.1A3CFE870496Dp+57)) |
98 | return 1; |
99 | if (test__floatdidf(a: 0x023479FD0E092DB0LL, expected: 0x1.1A3CFE870496Ep+57)) |
100 | return 1; |
101 | if (test__floatdidf(a: 0x023479FD0E092DB8LL, expected: 0x1.1A3CFE870496Ep+57)) |
102 | return 1; |
103 | if (test__floatdidf(a: 0x023479FD0E092DB6LL, expected: 0x1.1A3CFE870496Ep+57)) |
104 | return 1; |
105 | if (test__floatdidf(a: 0x023479FD0E092DBFLL, expected: 0x1.1A3CFE870496Ep+57)) |
106 | return 1; |
107 | if (test__floatdidf(a: 0x023479FD0E092DC1LL, expected: 0x1.1A3CFE870496Ep+57)) |
108 | return 1; |
109 | if (test__floatdidf(a: 0x023479FD0E092DC7LL, expected: 0x1.1A3CFE870496Ep+57)) |
110 | return 1; |
111 | if (test__floatdidf(a: 0x023479FD0E092DC8LL, expected: 0x1.1A3CFE870496Ep+57)) |
112 | return 1; |
113 | if (test__floatdidf(a: 0x023479FD0E092DCFLL, expected: 0x1.1A3CFE870496Ep+57)) |
114 | return 1; |
115 | if (test__floatdidf(a: 0x023479FD0E092DD0LL, expected: 0x1.1A3CFE870496Ep+57)) |
116 | return 1; |
117 | if (test__floatdidf(a: 0x023479FD0E092DD1LL, expected: 0x1.1A3CFE870496Fp+57)) |
118 | return 1; |
119 | if (test__floatdidf(a: 0x023479FD0E092DD8LL, expected: 0x1.1A3CFE870496Fp+57)) |
120 | return 1; |
121 | if (test__floatdidf(a: 0x023479FD0E092DDFLL, expected: 0x1.1A3CFE870496Fp+57)) |
122 | return 1; |
123 | if (test__floatdidf(a: 0x023479FD0E092DE0LL, expected: 0x1.1A3CFE870496Fp+57)) |
124 | return 1; |
125 | |
126 | return 0; |
127 | } |
128 | |