xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/trunctfsf2_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===--------------- trunctfsf2_test.c - Test __trunctfsf2 ----------------===//
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 __trunctfsf2 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 float __trunctfsf2(long double a);
22*7c3d14c8STreehugger Robot 
test__trunctfsf2(long double a,uint32_t expected)23*7c3d14c8STreehugger Robot int test__trunctfsf2(long double a, uint32_t expected)
24*7c3d14c8STreehugger Robot {
25*7c3d14c8STreehugger Robot     float x = __trunctfsf2(a);
26*7c3d14c8STreehugger Robot     int ret = compareResultF(x, expected);
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot     if (ret){
29*7c3d14c8STreehugger Robot         printf("error in test__trunctfsf2(%.20Lf) = %f, "
30*7c3d14c8STreehugger Robot                "expected %f\n", a, x, fromRep32(expected));
31*7c3d14c8STreehugger Robot     }
32*7c3d14c8STreehugger Robot     return ret;
33*7c3d14c8STreehugger Robot }
34*7c3d14c8STreehugger Robot 
35*7c3d14c8STreehugger Robot char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
36*7c3d14c8STreehugger Robot 
37*7c3d14c8STreehugger Robot #endif
38*7c3d14c8STreehugger Robot 
main()39*7c3d14c8STreehugger Robot int main()
40*7c3d14c8STreehugger Robot {
41*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
42*7c3d14c8STreehugger Robot     // qNaN
43*7c3d14c8STreehugger Robot     if (test__trunctfsf2(makeQNaN128(),
44*7c3d14c8STreehugger Robot                          UINT32_C(0x7fc00000)))
45*7c3d14c8STreehugger Robot         return 1;
46*7c3d14c8STreehugger Robot     // NaN
47*7c3d14c8STreehugger Robot     if (test__trunctfsf2(makeNaN128(UINT64_C(0x810000000000)),
48*7c3d14c8STreehugger Robot                          UINT32_C(0x7fc08000)))
49*7c3d14c8STreehugger Robot         return 1;
50*7c3d14c8STreehugger Robot     // inf
51*7c3d14c8STreehugger Robot     if (test__trunctfsf2(makeInf128(),
52*7c3d14c8STreehugger Robot                          UINT32_C(0x7f800000)))
53*7c3d14c8STreehugger Robot         return 1;
54*7c3d14c8STreehugger Robot     // zero
55*7c3d14c8STreehugger Robot     if (test__trunctfsf2(0.0L, UINT32_C(0x0)))
56*7c3d14c8STreehugger Robot         return 1;
57*7c3d14c8STreehugger Robot 
58*7c3d14c8STreehugger Robot     if (test__trunctfsf2(0x1.23a2abb4a2ddee355f36789abcdep+5L,
59*7c3d14c8STreehugger Robot                          UINT32_C(0x4211d156)))
60*7c3d14c8STreehugger Robot         return 1;
61*7c3d14c8STreehugger Robot     if (test__trunctfsf2(0x1.e3d3c45bd3abfd98b76a54cc321fp-9L,
62*7c3d14c8STreehugger Robot                          UINT32_C(0x3b71e9e2)))
63*7c3d14c8STreehugger Robot         return 1;
64*7c3d14c8STreehugger Robot     if (test__trunctfsf2(0x1.234eebb5faa678f4488693abcdefp+4534L,
65*7c3d14c8STreehugger Robot                          UINT32_C(0x7f800000)))
66*7c3d14c8STreehugger Robot         return 1;
67*7c3d14c8STreehugger Robot     if (test__trunctfsf2(0x1.edcba9bb8c76a5a43dd21f334634p-435L,
68*7c3d14c8STreehugger Robot                          UINT32_C(0x0)))
69*7c3d14c8STreehugger Robot         return 1;
70*7c3d14c8STreehugger Robot 
71*7c3d14c8STreehugger Robot #else
72*7c3d14c8STreehugger Robot     printf("skipped\n");
73*7c3d14c8STreehugger Robot 
74*7c3d14c8STreehugger Robot #endif
75*7c3d14c8STreehugger Robot     return 0;
76*7c3d14c8STreehugger Robot }
77