1*7c3d14c8STreehugger Robot //===-- floatdisf_test.c - Test __floatdisf -------------------------------===//
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 __floatdisf 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 <float.h>
16*7c3d14c8STreehugger Robot #include <stdio.h>
17*7c3d14c8STreehugger Robot
18*7c3d14c8STreehugger Robot // Returns: convert a to a float, rounding toward even.
19*7c3d14c8STreehugger Robot
20*7c3d14c8STreehugger Robot // Assumption: float is a IEEE 32 bit floating point type
21*7c3d14c8STreehugger Robot // di_int is a 64 bit integral type
22*7c3d14c8STreehugger Robot
23*7c3d14c8STreehugger Robot // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
24*7c3d14c8STreehugger Robot
25*7c3d14c8STreehugger Robot COMPILER_RT_ABI float __floatdisf(di_int a);
26*7c3d14c8STreehugger Robot
test__floatdisf(di_int a,float expected)27*7c3d14c8STreehugger Robot int test__floatdisf(di_int a, float expected)
28*7c3d14c8STreehugger Robot {
29*7c3d14c8STreehugger Robot float x = __floatdisf(a);
30*7c3d14c8STreehugger Robot if (x != expected)
31*7c3d14c8STreehugger Robot printf("error in __floatdisf(%llX) = %a, expected %a\n",
32*7c3d14c8STreehugger Robot a, x, expected);
33*7c3d14c8STreehugger Robot return x != expected;
34*7c3d14c8STreehugger Robot }
35*7c3d14c8STreehugger Robot
36*7c3d14c8STreehugger Robot char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
37*7c3d14c8STreehugger Robot char assumption_2[sizeof(di_int)*CHAR_BIT == 64] = {0};
38*7c3d14c8STreehugger Robot char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
39*7c3d14c8STreehugger Robot
main()40*7c3d14c8STreehugger Robot int main()
41*7c3d14c8STreehugger Robot {
42*7c3d14c8STreehugger Robot if (test__floatdisf(0, 0.0F))
43*7c3d14c8STreehugger Robot return 1;
44*7c3d14c8STreehugger Robot
45*7c3d14c8STreehugger Robot if (test__floatdisf(1, 1.0F))
46*7c3d14c8STreehugger Robot return 1;
47*7c3d14c8STreehugger Robot if (test__floatdisf(2, 2.0F))
48*7c3d14c8STreehugger Robot return 1;
49*7c3d14c8STreehugger Robot if (test__floatdisf(-1, -1.0F))
50*7c3d14c8STreehugger Robot return 1;
51*7c3d14c8STreehugger Robot if (test__floatdisf(-2, -2.0F))
52*7c3d14c8STreehugger Robot return 1;
53*7c3d14c8STreehugger Robot
54*7c3d14c8STreehugger Robot if (test__floatdisf(0x7FFFFF8000000000LL, 0x1.FFFFFEp+62F))
55*7c3d14c8STreehugger Robot return 1;
56*7c3d14c8STreehugger Robot if (test__floatdisf(0x7FFFFF0000000000LL, 0x1.FFFFFCp+62F))
57*7c3d14c8STreehugger Robot return 1;
58*7c3d14c8STreehugger Robot
59*7c3d14c8STreehugger Robot if (test__floatdisf(0x8000008000000000LL, -0x1.FFFFFEp+62F))
60*7c3d14c8STreehugger Robot return 1;
61*7c3d14c8STreehugger Robot if (test__floatdisf(0x8000010000000000LL, -0x1.FFFFFCp+62F))
62*7c3d14c8STreehugger Robot return 1;
63*7c3d14c8STreehugger Robot
64*7c3d14c8STreehugger Robot if (test__floatdisf(0x8000000000000000LL, -0x1.000000p+63F))
65*7c3d14c8STreehugger Robot return 1;
66*7c3d14c8STreehugger Robot if (test__floatdisf(0x8000000000000001LL, -0x1.000000p+63F))
67*7c3d14c8STreehugger Robot return 1;
68*7c3d14c8STreehugger Robot
69*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72E8000000LL, 0x1.FEDCBAp+50F))
70*7c3d14c8STreehugger Robot return 1;
71*7c3d14c8STreehugger Robot
72*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72EA000000LL, 0x1.FEDCBAp+50F))
73*7c3d14c8STreehugger Robot return 1;
74*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72EB000000LL, 0x1.FEDCBAp+50F))
75*7c3d14c8STreehugger Robot return 1;
76*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72EBFFFFFFLL, 0x1.FEDCBAp+50F))
77*7c3d14c8STreehugger Robot return 1;
78*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72EC000000LL, 0x1.FEDCBCp+50F))
79*7c3d14c8STreehugger Robot return 1;
80*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72E8000001LL, 0x1.FEDCBAp+50F))
81*7c3d14c8STreehugger Robot return 1;
82*7c3d14c8STreehugger Robot
83*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72E6000000LL, 0x1.FEDCBAp+50F))
84*7c3d14c8STreehugger Robot return 1;
85*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72E7000000LL, 0x1.FEDCBAp+50F))
86*7c3d14c8STreehugger Robot return 1;
87*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72E7FFFFFFLL, 0x1.FEDCBAp+50F))
88*7c3d14c8STreehugger Robot return 1;
89*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72E4000001LL, 0x1.FEDCBAp+50F))
90*7c3d14c8STreehugger Robot return 1;
91*7c3d14c8STreehugger Robot if (test__floatdisf(0x0007FB72E4000000LL, 0x1.FEDCB8p+50F))
92*7c3d14c8STreehugger Robot return 1;
93*7c3d14c8STreehugger Robot
94*7c3d14c8STreehugger Robot return 0;
95*7c3d14c8STreehugger Robot }
96