1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunsdfti
8 // Returns: convert a to a unsigned long long, rounding toward zero.
9 // Negative values all become zero.
11 // Assumption: double is a IEEE 64 bit floating point type
12 // tu_int is a 64 bit integral type
13 // value in double is representable in tu_int or is negative
14 // (no range checking performed)
16 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
20 COMPILER_RT_ABI tu_int
__fixunsdfti(double a
);
22 int test__fixunsdfti(double a
, tu_int expected
)
24 tu_int x
= __fixunsdfti(a
);
30 expectedt
.all
= expected
;
31 printf("error in __fixunsdfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
32 a
, xt
.s
.high
, xt
.s
.low
, expectedt
.s
.high
, expectedt
.s
.low
);
37 char assumption_1
[sizeof(tu_int
) == 2*sizeof(du_int
)] = {0};
38 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
39 char assumption_3
[sizeof(double)*CHAR_BIT
== 64] = {0};
46 if (test__fixunsdfti(0.0, 0))
49 if (test__fixunsdfti(0.5, 0))
51 if (test__fixunsdfti(0.99, 0))
53 if (test__fixunsdfti(1.0, 1))
55 if (test__fixunsdfti(1.5, 1))
57 if (test__fixunsdfti(1.99, 1))
59 if (test__fixunsdfti(2.0, 2))
61 if (test__fixunsdfti(2.01, 2))
63 if (test__fixunsdfti(-0.5, 0))
65 if (test__fixunsdfti(-0.99, 0))
68 if (test__fixunsdfti(-1.0, 0)) // libgcc ignores "returns 0 for negative input" spec
70 if (test__fixunsdfti(-1.5, 0))
72 if (test__fixunsdfti(-1.99, 0))
74 if (test__fixunsdfti(-2.0, 0))
76 if (test__fixunsdfti(-2.01, 0))
80 if (test__fixunsdfti(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
82 if (test__fixunsdfti(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
86 if (test__fixunsdfti(-0x1.FFFFFEp
+62, 0))
88 if (test__fixunsdfti(-0x1.FFFFFCp
+62, 0))
92 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp
+63, 0xFFFFFFFFFFFFF800ULL
))
94 if (test__fixunsdfti(0x1.0000000000000p
+63, 0x8000000000000000ULL
))
96 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00ULL
))
98 if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800ULL
))
101 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp
+127, make_ti(0xFFFFFFFFFFFFF800ULL
, 0)))
103 if (test__fixunsdfti(0x1.0000000000000p
+127, make_ti(0x8000000000000000ULL
, 0)))
105 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp
+126, make_ti(0x7FFFFFFFFFFFFC00ULL
, 0)))
107 if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp
+126, make_ti(0x7FFFFFFFFFFFF800ULL
, 0)))
109 if (test__fixunsdfti(0x1.0000000000000p
+128, make_ti(0xFFFFFFFFFFFFFFFFULL
,
110 0xFFFFFFFFFFFFFFFFULL
)))
114 if (test__fixunsdfti(-0x1.FFFFFFFFFFFFFp
+62, 0))
116 if (test__fixunsdfti(-0x1.FFFFFFFFFFFFEp
+62, 0))