1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_floatundidf |
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 | // du_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 __floatundidf(du_int a); |
16 | |
17 | int test__floatundidf(di_int a, double expected) |
18 | { |
19 | double x = __floatundidf(a); |
20 | if (x != expected) |
21 | printf(format: "error in __floatundidf(%llX) = %a, expected %a\n" , |
22 | a, x, expected); |
23 | return x != expected; |
24 | } |
25 | |
26 | char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0}; |
27 | char assumption_2[sizeof(di_int)*CHAR_BIT == 64] = {0}; |
28 | char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0}; |
29 | |
30 | int main() |
31 | { |
32 | if (test__floatundidf(a: 0, expected: 0.0)) |
33 | return 1; |
34 | |
35 | if (test__floatundidf(a: 1, expected: 1.0)) |
36 | return 1; |
37 | if (test__floatundidf(a: 2, expected: 2.0)) |
38 | return 1; |
39 | if (test__floatundidf(a: 20, expected: 20.0)) |
40 | return 1; |
41 | |
42 | if (test__floatundidf(a: 0x7FFFFF8000000000LL, expected: 0x1.FFFFFEp+62)) |
43 | return 1; |
44 | if (test__floatundidf(a: 0x7FFFFFFFFFFFF800LL, expected: 0x1.FFFFFFFFFFFFEp+62)) |
45 | return 1; |
46 | if (test__floatundidf(a: 0x7FFFFF0000000000LL, expected: 0x1.FFFFFCp+62)) |
47 | return 1; |
48 | if (test__floatundidf(a: 0x7FFFFFFFFFFFF000LL, expected: 0x1.FFFFFFFFFFFFCp+62)) |
49 | return 1; |
50 | |
51 | if (test__floatundidf(a: 0x8000008000000000LL, expected: 0x1.000001p+63)) |
52 | return 1; |
53 | if (test__floatundidf(a: 0x8000000000000800LL, expected: 0x1.0000000000001p+63)) |
54 | return 1; |
55 | if (test__floatundidf(a: 0x8000010000000000LL, expected: 0x1.000002p+63)) |
56 | return 1; |
57 | if (test__floatundidf(a: 0x8000000000001000LL, expected: 0x1.0000000000002p+63)) |
58 | return 1; |
59 | |
60 | if (test__floatundidf(a: 0x8000000000000000LL, expected: 0x1p+63)) |
61 | return 1; |
62 | if (test__floatundidf(a: 0x8000000000000001LL, expected: 0x1p+63)) |
63 | return 1; |
64 | |
65 | if (test__floatundidf(a: 0x0007FB72E8000000LL, expected: 0x1.FEDCBAp+50)) |
66 | return 1; |
67 | |
68 | if (test__floatundidf(a: 0x0007FB72EA000000LL, expected: 0x1.FEDCBA8p+50)) |
69 | return 1; |
70 | if (test__floatundidf(a: 0x0007FB72EB000000LL, expected: 0x1.FEDCBACp+50)) |
71 | return 1; |
72 | if (test__floatundidf(a: 0x0007FB72EBFFFFFFLL, expected: 0x1.FEDCBAFFFFFFCp+50)) |
73 | return 1; |
74 | if (test__floatundidf(a: 0x0007FB72EC000000LL, expected: 0x1.FEDCBBp+50)) |
75 | return 1; |
76 | if (test__floatundidf(a: 0x0007FB72E8000001LL, expected: 0x1.FEDCBA0000004p+50)) |
77 | return 1; |
78 | |
79 | if (test__floatundidf(a: 0x0007FB72E6000000LL, expected: 0x1.FEDCB98p+50)) |
80 | return 1; |
81 | if (test__floatundidf(a: 0x0007FB72E7000000LL, expected: 0x1.FEDCB9Cp+50)) |
82 | return 1; |
83 | if (test__floatundidf(a: 0x0007FB72E7FFFFFFLL, expected: 0x1.FEDCB9FFFFFFCp+50)) |
84 | return 1; |
85 | if (test__floatundidf(a: 0x0007FB72E4000001LL, expected: 0x1.FEDCB90000004p+50)) |
86 | return 1; |
87 | if (test__floatundidf(a: 0x0007FB72E4000000LL, expected: 0x1.FEDCB9p+50)) |
88 | return 1; |
89 | |
90 | if (test__floatundidf(a: 0x023479FD0E092DC0LL, expected: 0x1.1A3CFE870496Ep+57)) |
91 | return 1; |
92 | if (test__floatundidf(a: 0x023479FD0E092DA1LL, expected: 0x1.1A3CFE870496Dp+57)) |
93 | return 1; |
94 | if (test__floatundidf(a: 0x023479FD0E092DB0LL, expected: 0x1.1A3CFE870496Ep+57)) |
95 | return 1; |
96 | if (test__floatundidf(a: 0x023479FD0E092DB8LL, expected: 0x1.1A3CFE870496Ep+57)) |
97 | return 1; |
98 | if (test__floatundidf(a: 0x023479FD0E092DB6LL, expected: 0x1.1A3CFE870496Ep+57)) |
99 | return 1; |
100 | if (test__floatundidf(a: 0x023479FD0E092DBFLL, expected: 0x1.1A3CFE870496Ep+57)) |
101 | return 1; |
102 | if (test__floatundidf(a: 0x023479FD0E092DC1LL, expected: 0x1.1A3CFE870496Ep+57)) |
103 | return 1; |
104 | if (test__floatundidf(a: 0x023479FD0E092DC7LL, expected: 0x1.1A3CFE870496Ep+57)) |
105 | return 1; |
106 | if (test__floatundidf(a: 0x023479FD0E092DC8LL, expected: 0x1.1A3CFE870496Ep+57)) |
107 | return 1; |
108 | if (test__floatundidf(a: 0x023479FD0E092DCFLL, expected: 0x1.1A3CFE870496Ep+57)) |
109 | return 1; |
110 | if (test__floatundidf(a: 0x023479FD0E092DD0LL, expected: 0x1.1A3CFE870496Ep+57)) |
111 | return 1; |
112 | if (test__floatundidf(a: 0x023479FD0E092DD1LL, expected: 0x1.1A3CFE870496Fp+57)) |
113 | return 1; |
114 | if (test__floatundidf(a: 0x023479FD0E092DD8LL, expected: 0x1.1A3CFE870496Fp+57)) |
115 | return 1; |
116 | if (test__floatundidf(a: 0x023479FD0E092DDFLL, expected: 0x1.1A3CFE870496Fp+57)) |
117 | return 1; |
118 | if (test__floatundidf(a: 0x023479FD0E092DE0LL, expected: 0x1.1A3CFE870496Fp+57)) |
119 | return 1; |
120 | |
121 | return 0; |
122 | } |
123 | |