1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixtfdi
3 //===--------------- fixtfdi_test.c - Test __fixtfdi ----------------------===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file tests __fixtfdi for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
18 #if __LDBL_MANT_DIG__ == 113
22 di_int
__fixtfdi(long double a
);
24 int test__fixtfdi(long double a
, di_int expected
)
26 di_int x
= __fixtfdi(a
);
27 int ret
= (x
!= expected
);
31 printf("error in test__fixtfdi(%.20Lf) = %llX, "
32 "expected %llX\n", a
, x
, expected
);
37 char assumption_1
[sizeof(long double) * CHAR_BIT
== 128] = {0};
43 #if __LDBL_MANT_DIG__ == 113
44 if (test__fixtfdi(makeInf128(), 0x7fffffffffffffffLL
))
46 if (test__fixtfdi(0, 0x0))
48 if (test__fixtfdi(0x1.23456789abcdefp
+5L, 0x24LL
))
50 if (test__fixtfdi(0x1.23456789abcdefp
-3L, 0x0LL
))
52 if (test__fixtfdi(0x1.23456789abcdef12345678p
+20L, 0x123456LL
))
54 if (test__fixtfdi(0x1.23456789abcdef12345678p
+40L, 0x123456789abLL
))
56 if (test__fixtfdi(0x1.23456789abcdef12345678p
+60L, 0x123456789abcdef1LL
))
58 if (test__fixtfdi(0x1.23456789abcdefp
+256L, 0x7fffffffffffffffLL
))
60 if (test__fixtfdi(-0x1.23456789abcdefp
+20L, 0xffffffffffedcbaaLL
))
62 if (test__fixtfdi(-0x1.23456789abcdefp
+40L, 0xfffffedcba987655LL
))
64 if (test__fixtfdi(-0x1.23456789abcdefp
+256L, 0x8000000000000000LL
))