1 //===-- fixunsdfti_test.c - Test __fixunsdfti -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __fixunsdfti for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
17 // Returns: convert a to a unsigned long long, rounding toward zero.
18 // Negative values all become zero.
20 // Assumption: double is a IEEE 64 bit floating point type
21 // tu_int is a 64 bit integral type
22 // value in double is representable in tu_int or is negative
23 // (no range checking performed)
25 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
29 tu_int
__fixunsdfti(double a
);
31 int test__fixunsdfti(double a
, tu_int expected
)
33 tu_int x
= __fixunsdfti(a
);
39 expectedt
.all
= expected
;
40 printf("error in __fixunsdfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
41 a
, xt
.s
.high
, xt
.s
.low
, expectedt
.s
.high
, expectedt
.s
.low
);
46 char assumption_1
[sizeof(tu_int
) == 2*sizeof(du_int
)] = {0};
47 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
48 char assumption_3
[sizeof(double)*CHAR_BIT
== 64] = {0};
55 if (test__fixunsdfti(0.0, 0))
58 if (test__fixunsdfti(0.5, 0))
60 if (test__fixunsdfti(0.99, 0))
62 if (test__fixunsdfti(1.0, 1))
64 if (test__fixunsdfti(1.5, 1))
66 if (test__fixunsdfti(1.99, 1))
68 if (test__fixunsdfti(2.0, 2))
70 if (test__fixunsdfti(2.01, 2))
72 if (test__fixunsdfti(-0.5, 0))
74 if (test__fixunsdfti(-0.99, 0))
77 if (test__fixunsdfti(-1.0, 0)) // libgcc ignores "returns 0 for negative input" spec
79 if (test__fixunsdfti(-1.5, 0))
81 if (test__fixunsdfti(-1.99, 0))
83 if (test__fixunsdfti(-2.0, 0))
85 if (test__fixunsdfti(-2.01, 0))
89 if (test__fixunsdfti(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
91 if (test__fixunsdfti(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
95 if (test__fixunsdfti(-0x1.FFFFFEp
+62, 0))
97 if (test__fixunsdfti(-0x1.FFFFFCp
+62, 0))
101 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp
+63, 0xFFFFFFFFFFFFF800LL
))
103 if (test__fixunsdfti(0x1.0000000000000p
+63, 0x8000000000000000LL
))
105 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
107 if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
110 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp
+127, make_ti(0xFFFFFFFFFFFFF800LL
, 0)))
112 if (test__fixunsdfti(0x1.0000000000000p
+127, make_ti(0x8000000000000000LL
, 0)))
114 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp
+126, make_ti(0x7FFFFFFFFFFFFC00LL
, 0)))
116 if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp
+126, make_ti(0x7FFFFFFFFFFFF800LL
, 0)))
120 if (test__fixunsdfti(-0x1.FFFFFFFFFFFFFp
+62, 0))
122 if (test__fixunsdfti(-0x1.FFFFFFFFFFFFEp
+62, 0))