1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_fixtfdi
3
4#include "int_lib.h"
5#include <stdio.h>
6
7#if __LDBL_MANT_DIG__ == 113
8
9#include "fp_test.h"
10
11di_int __fixtfdi(long double a);
12
13int test__fixtfdi(long double a, di_int expected)
14{
15 di_int x = __fixtfdi(a);
16 int ret = (x != expected);
17
18 if (ret)
19 {
20 printf("error in test__fixtfdi(%.20Lf) = %llX, "
21 "expected %llX\n", a, x, expected);
22 }
23 return ret;
24}
25
26char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
27
28#endif
29
30int main()
31{
32#if __LDBL_MANT_DIG__ == 113
33 if (test__fixtfdi(makeInf128(), 0x7fffffffffffffffLL))
34 return 1;
35 if (test__fixtfdi(0, 0x0))
36 return 1;
37 if (test__fixtfdi(0x1.23456789abcdefp+5L, 0x24LL))
38 return 1;
39 if (test__fixtfdi(0x1.23456789abcdefp-3L, 0x0LL))
40 return 1;
41 if (test__fixtfdi(0x1.23456789abcdef12345678p+20L, 0x123456LL))
42 return 1;
43 if (test__fixtfdi(0x1.23456789abcdef12345678p+40L, 0x123456789abLL))
44 return 1;
45 if (test__fixtfdi(0x1.23456789abcdef12345678p+60L, 0x123456789abcdef1LL))
46 return 1;
47 if (test__fixtfdi(0x1.23456789abcdefp+256L, 0x7fffffffffffffffLL))
48 return 1;
49 if (test__fixtfdi(-0x1.23456789abcdefp+20L, 0xffffffffffedcbaaLL))
50 return 1;
51 if (test__fixtfdi(-0x1.23456789abcdefp+40L, 0xfffffedcba987655LL))
52 return 1;
53 if (test__fixtfdi(-0x1.23456789abcdefp+256L, 0x8000000000000000LL))
54 return 1;
55
56#else
57 printf(format: "skipped\n");
58
59#endif
60 return 0;
61}
62

source code of compiler-rt/test/builtins/Unit/fixtfdi_test.c