1*7c3d14c8STreehugger Robot //===-------------- trunctfdf2_test.c - Test __trunctfdf2 -----------------===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot // The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot // Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file tests __trunctfdf2 for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot
14*7c3d14c8STreehugger Robot #include "int_lib.h"
15*7c3d14c8STreehugger Robot #include <stdio.h>
16*7c3d14c8STreehugger Robot
17*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
18*7c3d14c8STreehugger Robot
19*7c3d14c8STreehugger Robot #include "fp_test.h"
20*7c3d14c8STreehugger Robot
21*7c3d14c8STreehugger Robot COMPILER_RT_ABI double __trunctfdf2(long double a);
22*7c3d14c8STreehugger Robot
test__trunctfdf2(long double a,uint64_t expected)23*7c3d14c8STreehugger Robot int test__trunctfdf2(long double a, uint64_t expected)
24*7c3d14c8STreehugger Robot {
25*7c3d14c8STreehugger Robot double x = __trunctfdf2(a);
26*7c3d14c8STreehugger Robot int ret = compareResultD(x, expected);
27*7c3d14c8STreehugger Robot
28*7c3d14c8STreehugger Robot if (ret)
29*7c3d14c8STreehugger Robot {
30*7c3d14c8STreehugger Robot printf("error in test__trunctfdf2(%.20Lf) = %lf, "
31*7c3d14c8STreehugger Robot "expected %lf\n", a, x, fromRep64(expected));
32*7c3d14c8STreehugger Robot }
33*7c3d14c8STreehugger Robot return ret;
34*7c3d14c8STreehugger Robot }
35*7c3d14c8STreehugger Robot
36*7c3d14c8STreehugger Robot char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
37*7c3d14c8STreehugger Robot
38*7c3d14c8STreehugger Robot #endif
39*7c3d14c8STreehugger Robot
main()40*7c3d14c8STreehugger Robot int main()
41*7c3d14c8STreehugger Robot {
42*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
43*7c3d14c8STreehugger Robot // qNaN
44*7c3d14c8STreehugger Robot if (test__trunctfdf2(makeQNaN128(),
45*7c3d14c8STreehugger Robot UINT64_C(0x7ff8000000000000)))
46*7c3d14c8STreehugger Robot return 1;
47*7c3d14c8STreehugger Robot // NaN
48*7c3d14c8STreehugger Robot if (test__trunctfdf2(makeNaN128(UINT64_C(0x810000000000)),
49*7c3d14c8STreehugger Robot UINT64_C(0x7ff8100000000000)))
50*7c3d14c8STreehugger Robot return 1;
51*7c3d14c8STreehugger Robot // inf
52*7c3d14c8STreehugger Robot if (test__trunctfdf2(makeInf128(),
53*7c3d14c8STreehugger Robot UINT64_C(0x7ff0000000000000)))
54*7c3d14c8STreehugger Robot return 1;
55*7c3d14c8STreehugger Robot // zero
56*7c3d14c8STreehugger Robot if (test__trunctfdf2(0.0L, UINT64_C(0x0)))
57*7c3d14c8STreehugger Robot return 1;
58*7c3d14c8STreehugger Robot
59*7c3d14c8STreehugger Robot if (test__trunctfdf2(0x1.af23456789bbaaab347645365cdep+5L,
60*7c3d14c8STreehugger Robot UINT64_C(0x404af23456789bbb)))
61*7c3d14c8STreehugger Robot return 1;
62*7c3d14c8STreehugger Robot if (test__trunctfdf2(0x1.dedafcff354b6ae9758763545432p-9L,
63*7c3d14c8STreehugger Robot UINT64_C(0x3f6dedafcff354b7)))
64*7c3d14c8STreehugger Robot return 1;
65*7c3d14c8STreehugger Robot if (test__trunctfdf2(0x1.2f34dd5f437e849b4baab754cdefp+4534L,
66*7c3d14c8STreehugger Robot UINT64_C(0x7ff0000000000000)))
67*7c3d14c8STreehugger Robot return 1;
68*7c3d14c8STreehugger Robot if (test__trunctfdf2(0x1.edcbff8ad76ab5bf46463233214fp-435L,
69*7c3d14c8STreehugger Robot UINT64_C(0x24cedcbff8ad76ab)))
70*7c3d14c8STreehugger Robot return 1;
71*7c3d14c8STreehugger Robot
72*7c3d14c8STreehugger Robot #else
73*7c3d14c8STreehugger Robot printf("skipped\n");
74*7c3d14c8STreehugger Robot
75*7c3d14c8STreehugger Robot #endif
76*7c3d14c8STreehugger Robot return 0;
77*7c3d14c8STreehugger Robot }
78