1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunsdfdi
7 // Returns: convert a to a unsigned long long, rounding toward zero.
8 // Negative values all become zero.
10 // Assumption: double is a IEEE 64 bit floating point type
11 // du_int is a 64 bit integral type
12 // value in double is representable in du_int or is negative
13 // (no range checking performed)
15 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
17 COMPILER_RT_ABI du_int
__fixunsdfdi(double a
);
19 int test__fixunsdfdi(double a
, du_int expected
)
21 du_int x
= __fixunsdfdi(a
);
23 printf("error in __fixunsdfdi(%A) = %llX, expected %llX\n", a
, x
, expected
);
27 char assumption_1
[sizeof(du_int
) == 2*sizeof(su_int
)] = {0};
28 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
29 char assumption_3
[sizeof(double)*CHAR_BIT
== 64] = {0};
33 if (test__fixunsdfdi(0.0, 0))
36 if (test__fixunsdfdi(0.5, 0))
38 if (test__fixunsdfdi(0.99, 0))
40 if (test__fixunsdfdi(1.0, 1))
42 if (test__fixunsdfdi(1.5, 1))
44 if (test__fixunsdfdi(1.99, 1))
46 if (test__fixunsdfdi(2.0, 2))
48 if (test__fixunsdfdi(2.01, 2))
50 if (test__fixunsdfdi(-0.5, 0))
52 if (test__fixunsdfdi(-0.99, 0))
55 if (test__fixunsdfdi(-1.0, 0)) // libgcc ignores "returns 0 for negative input" spec
57 if (test__fixunsdfdi(-1.5, 0))
59 if (test__fixunsdfdi(-1.99, 0))
61 if (test__fixunsdfdi(-2.0, 0))
63 if (test__fixunsdfdi(-2.01, 0))
67 if (test__fixunsdfdi(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
69 if (test__fixunsdfdi(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
73 if (test__fixunsdfdi(-0x1.FFFFFEp
+62, 0))
75 if (test__fixunsdfdi(-0x1.FFFFFCp
+62, 0))
79 if (test__fixunsdfdi(0x1.FFFFFFFFFFFFFp
+63, 0xFFFFFFFFFFFFF800LL
))
81 if (test__fixunsdfdi(0x1.0000000000000p
+63, 0x8000000000000000LL
))
83 if (test__fixunsdfdi(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
85 if (test__fixunsdfdi(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
89 if (test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp
+62, 0))
91 if (test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp
+62, 0))