1 //===-- fixxfdi_test.c - Test __fixxfdi -----------------------------------===//
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 __fixxfdi for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
18 #if HAS_80_BIT_LONG_DOUBLE
19 // Returns: convert a to a signed long long, rounding toward zero.
21 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
22 // su_int is a 32 bit integral type
23 // value in long double is representable in di_int (no range checking performed)
25 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
26 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
28 di_int
__fixxfdi(long double a
);
30 int test__fixxfdi(long double a
, di_int expected
)
32 di_int x
= __fixxfdi(a
);
34 printf("error in __fixxfdi(%LA) = %llX, expected %llX\n",
39 char assumption_1
[sizeof(di_int
) == 2*sizeof(si_int
)] = {0};
40 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
41 char assumption_3
[sizeof(long double)*CHAR_BIT
== 128] = {0};
46 #if HAS_80_BIT_LONG_DOUBLE
47 if (test__fixxfdi(0.0, 0))
50 if (test__fixxfdi(0.5, 0))
52 if (test__fixxfdi(0.99, 0))
54 if (test__fixxfdi(1.0, 1))
56 if (test__fixxfdi(1.5, 1))
58 if (test__fixxfdi(1.99, 1))
60 if (test__fixxfdi(2.0, 2))
62 if (test__fixxfdi(2.01, 2))
64 if (test__fixxfdi(-0.5, 0))
66 if (test__fixxfdi(-0.99, 0))
68 if (test__fixxfdi(-1.0, -1))
70 if (test__fixxfdi(-1.5, -1))
72 if (test__fixxfdi(-1.99, -1))
74 if (test__fixxfdi(-2.0, -2))
76 if (test__fixxfdi(-2.01, -2))
79 if (test__fixxfdi(0x1.FFFFFEp
+62, 0x7FFFFF8000000000LL
))
81 if (test__fixxfdi(0x1.FFFFFCp
+62, 0x7FFFFF0000000000LL
))
84 if (test__fixxfdi(-0x1.FFFFFEp
+62, 0x8000008000000000LL
))
86 if (test__fixxfdi(-0x1.FFFFFCp
+62, 0x8000010000000000LL
))
89 if (test__fixxfdi(0x1.FFFFFFFFFFFFFp
+62, 0x7FFFFFFFFFFFFC00LL
))
91 if (test__fixxfdi(0x1.FFFFFFFFFFFFEp
+62, 0x7FFFFFFFFFFFF800LL
))
94 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFp
+62, 0x8000000000000400LL
))
96 if (test__fixxfdi(-0x1.FFFFFFFFFFFFEp
+62, 0x8000000000000800LL
))
99 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFFCp
+62L, 0x7FFFFFFFFFFFFFFFLL
))
101 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFF8p
+62L, 0x7FFFFFFFFFFFFFFELL
))
104 if (test__fixxfdi(-0x1.0000000000000000p
+63L, 0x8000000000000000LL
))
106 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFFCp
+62L, 0x8000000000000001LL
))
108 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFF8p
+62L, 0x8000000000000002LL
))