1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixxfdi
8 #if HAS_80_BIT_LONG_DOUBLE
9 // Returns: convert a to a signed long long, rounding toward zero.
11 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
12 // su_int is a 32 bit integral type
13 // value in long double is representable in di_int (no range checking performed)
15 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
16 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
18 COMPILER_RT_ABI di_int
__fixxfdi(long double a
);
20 int test__fixxfdi(long double a
, di_int expected
)
22 di_int x
= __fixxfdi(a
);
24 printf("error in __fixxfdi(%LA) = %llX, expected %llX\n",
29 char assumption_1
[sizeof(di_int
) == 2*sizeof(si_int
)] = {0};
30 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
31 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
36 #if HAS_80_BIT_LONG_DOUBLE
37 if (test__fixxfdi(0.0, 0))
40 if (test__fixxfdi(0.5, 0))
42 if (test__fixxfdi(0.99, 0))
44 if (test__fixxfdi(1.0, 1))
46 if (test__fixxfdi(1.5, 1))
48 if (test__fixxfdi(1.99, 1))
50 if (test__fixxfdi(2.0, 2))
52 if (test__fixxfdi(2.01, 2))
54 if (test__fixxfdi(-0.5, 0))
56 if (test__fixxfdi(-0.99, 0))
58 if (test__fixxfdi(-1.0, -1))
60 if (test__fixxfdi(-1.5, -1))
62 if (test__fixxfdi(-1.99, -1))
64 if (test__fixxfdi(-2.0, -2))
66 if (test__fixxfdi(-2.01, -2))
69 if (test__fixxfdi(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
71 if (test__fixxfdi(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
74 if (test__fixxfdi(-0x1.FFFFFEp
+62, 0x8000008000000000LL
))
76 if (test__fixxfdi(-0x1.FFFFFCp
+62, 0x8000010000000000LL
))
79 if (test__fixxfdi(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
81 if (test__fixxfdi(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
84 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFp
+62, 0x8000000000000400LL
))
86 if (test__fixxfdi(-0x1.FFFFFFFFFFFFEp
+62, 0x8000000000000800LL
))
89 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFFCp
+62L, 0x7FFFFFFFFFFFFFFFLL
))
91 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFF8p
+62L, 0x7FFFFFFFFFFFFFFELL
))
94 if (test__fixxfdi(-0x1.0000000000000000p
+63L, 0x8000000000000000LL
))
96 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFFCp
+62L, 0x8000000000000001LL
))
98 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFF8p
+62L, 0x8000000000000002LL
))