xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/floatditf_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- floatditf_test.c - Test __floatditf -------------------------------===//
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 __floatditf 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 <math.h>
16*7c3d14c8STreehugger Robot #include <complex.h>
17*7c3d14c8STreehugger Robot #include <stdio.h>
18*7c3d14c8STreehugger Robot 
19*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot #include "fp_test.h"
22*7c3d14c8STreehugger Robot 
23*7c3d14c8STreehugger Robot // Returns: long integer converted to long double
24*7c3d14c8STreehugger Robot 
25*7c3d14c8STreehugger Robot COMPILER_RT_ABI long double __floatditf(long long a);
26*7c3d14c8STreehugger Robot 
test__floatditf(long long a,uint64_t expectedHi,uint64_t expectedLo)27*7c3d14c8STreehugger Robot int test__floatditf(long long a, uint64_t expectedHi, uint64_t expectedLo)
28*7c3d14c8STreehugger Robot {
29*7c3d14c8STreehugger Robot     long double x = __floatditf(a);
30*7c3d14c8STreehugger Robot     int ret = compareResultLD(x, expectedHi, expectedLo);
31*7c3d14c8STreehugger Robot 
32*7c3d14c8STreehugger Robot     if (ret)
33*7c3d14c8STreehugger Robot         printf("error in __floatditf(%Ld) = %.20Lf, "
34*7c3d14c8STreehugger Robot                "expected %.20Lf\n", a, x, fromRep128(expectedHi, expectedLo));
35*7c3d14c8STreehugger Robot     return ret;
36*7c3d14c8STreehugger Robot }
37*7c3d14c8STreehugger Robot 
38*7c3d14c8STreehugger Robot char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
39*7c3d14c8STreehugger Robot 
40*7c3d14c8STreehugger Robot #endif
41*7c3d14c8STreehugger Robot 
main()42*7c3d14c8STreehugger Robot int main()
43*7c3d14c8STreehugger Robot {
44*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
45*7c3d14c8STreehugger Robot     if (test__floatditf(0x7fffffffffffffff, UINT64_C(0x403dffffffffffff), UINT64_C(0xfffc000000000000)))
46*7c3d14c8STreehugger Robot         return 1;
47*7c3d14c8STreehugger Robot     if (test__floatditf(0x123456789abcdef1, UINT64_C(0x403b23456789abcd), UINT64_C(0xef10000000000000)))
48*7c3d14c8STreehugger Robot         return 1;
49*7c3d14c8STreehugger Robot     if (test__floatditf(0x2, UINT64_C(0x4000000000000000), UINT64_C(0x0)))
50*7c3d14c8STreehugger Robot         return 1;
51*7c3d14c8STreehugger Robot     if (test__floatditf(0x1, UINT64_C(0x3fff000000000000), UINT64_C(0x0)))
52*7c3d14c8STreehugger Robot         return 1;
53*7c3d14c8STreehugger Robot     if (test__floatditf(0x0, UINT64_C(0x0), UINT64_C(0x0)))
54*7c3d14c8STreehugger Robot         return 1;
55*7c3d14c8STreehugger Robot     if (test__floatditf(0xffffffffffffffff, UINT64_C(0xbfff000000000000), UINT64_C(0x0)))
56*7c3d14c8STreehugger Robot         return 1;
57*7c3d14c8STreehugger Robot     if (test__floatditf(0xfffffffffffffffe, UINT64_C(0xc000000000000000), UINT64_C(0x0)))
58*7c3d14c8STreehugger Robot         return 1;
59*7c3d14c8STreehugger Robot     if (test__floatditf(-0x123456789abcdef1, UINT64_C(0xc03b23456789abcd), UINT64_C(0xef10000000000000)))
60*7c3d14c8STreehugger Robot         return 1;
61*7c3d14c8STreehugger Robot     if (test__floatditf(0x8000000000000000, UINT64_C(0xc03e000000000000), UINT64_C(0x0)))
62*7c3d14c8STreehugger Robot         return 1;
63*7c3d14c8STreehugger Robot 
64*7c3d14c8STreehugger Robot #else
65*7c3d14c8STreehugger Robot     printf("skipped\n");
66*7c3d14c8STreehugger Robot 
67*7c3d14c8STreehugger Robot #endif
68*7c3d14c8STreehugger Robot     return 0;
69*7c3d14c8STreehugger Robot }
70