1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_floatditf
3
4#include "int_lib.h"
5#include <complex.h>
6#include <math.h>
7#include <stdio.h>
8
9// The testcase currently assumes IEEE TF format, once that has been
10// fixed the defined(CRT_HAS_IEEE_TF) guard can be removed to enable it for
11// IBM 128 floats as well.
12#if defined(CRT_HAS_IEEE_TF)
13
14# include "fp_test.h"
15
16// Returns: long integer converted to tf_float
17
18COMPILER_RT_ABI tf_float __floatditf(di_int a);
19
20int test__floatditf(di_int a, uint64_t expectedHi, uint64_t expectedLo) {
21 tf_float x = __floatditf(a);
22 int ret = compareResultF128(result: x, expectedHi, expectedLo);
23
24 if (ret)
25 printf(format: "error in __floatditf(%Ld) = %.20Lf, "
26 "expected %.20Lf\n",
27 a, x, fromRep128(hi: expectedHi, lo: expectedLo));
28 return ret;
29}
30
31char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
32
33#endif
34
35int main() {
36#if defined(CRT_HAS_IEEE_TF)
37 if (test__floatditf(a: 0x7fffffffffffffff, UINT64_C(0x403dffffffffffff),
38 UINT64_C(0xfffc000000000000)))
39 return 1;
40 if (test__floatditf(a: 0x123456789abcdef1, UINT64_C(0x403b23456789abcd),
41 UINT64_C(0xef10000000000000)))
42 return 1;
43 if (test__floatditf(a: 0x2, UINT64_C(0x4000000000000000), UINT64_C(0x0)))
44 return 1;
45 if (test__floatditf(a: 0x1, UINT64_C(0x3fff000000000000), UINT64_C(0x0)))
46 return 1;
47 if (test__floatditf(a: 0x0, UINT64_C(0x0), UINT64_C(0x0)))
48 return 1;
49 if (test__floatditf(a: 0xffffffffffffffff, UINT64_C(0xbfff000000000000),
50 UINT64_C(0x0)))
51 return 1;
52 if (test__floatditf(a: 0xfffffffffffffffe, UINT64_C(0xc000000000000000),
53 UINT64_C(0x0)))
54 return 1;
55 if (test__floatditf(a: -0x123456789abcdef1, UINT64_C(0xc03b23456789abcd),
56 UINT64_C(0xef10000000000000)))
57 return 1;
58 if (test__floatditf(a: 0x8000000000000000, UINT64_C(0xc03e000000000000),
59 UINT64_C(0x0)))
60 return 1;
61
62#else
63 printf("skipped\n");
64
65#endif
66 return 0;
67}
68

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