1*7c3d14c8STreehugger Robot //===--------------- truncdfhf2_test.c - Test __truncdfhf2 ----------------===//
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 __truncdfhf2 for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot
14*7c3d14c8STreehugger Robot #include <stdio.h>
15*7c3d14c8STreehugger Robot
16*7c3d14c8STreehugger Robot #include "fp_test.h"
17*7c3d14c8STreehugger Robot
18*7c3d14c8STreehugger Robot uint16_t __truncdfhf2(double a);
19*7c3d14c8STreehugger Robot
test__truncdfhf2(double a,uint16_t expected)20*7c3d14c8STreehugger Robot int test__truncdfhf2(double a, uint16_t expected)
21*7c3d14c8STreehugger Robot {
22*7c3d14c8STreehugger Robot uint16_t x = __truncdfhf2(a);
23*7c3d14c8STreehugger Robot int ret = compareResultH(x, expected);
24*7c3d14c8STreehugger Robot
25*7c3d14c8STreehugger Robot if (ret){
26*7c3d14c8STreehugger Robot printf("error in test__truncdfhf2(%f) = %#.4x, "
27*7c3d14c8STreehugger Robot "expected %#.4x\n", a, x, fromRep16(expected));
28*7c3d14c8STreehugger Robot }
29*7c3d14c8STreehugger Robot return ret;
30*7c3d14c8STreehugger Robot }
31*7c3d14c8STreehugger Robot
32*7c3d14c8STreehugger Robot char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0};
33*7c3d14c8STreehugger Robot
main()34*7c3d14c8STreehugger Robot int main()
35*7c3d14c8STreehugger Robot {
36*7c3d14c8STreehugger Robot // qNaN
37*7c3d14c8STreehugger Robot if (test__truncdfhf2(makeQNaN64(),
38*7c3d14c8STreehugger Robot UINT16_C(0x7e00)))
39*7c3d14c8STreehugger Robot return 1;
40*7c3d14c8STreehugger Robot // NaN
41*7c3d14c8STreehugger Robot if (test__truncdfhf2(makeNaN64(UINT64_C(0x8000)),
42*7c3d14c8STreehugger Robot UINT16_C(0x7e00)))
43*7c3d14c8STreehugger Robot return 1;
44*7c3d14c8STreehugger Robot // inf
45*7c3d14c8STreehugger Robot if (test__truncdfhf2(makeInf64(),
46*7c3d14c8STreehugger Robot UINT16_C(0x7c00)))
47*7c3d14c8STreehugger Robot return 1;
48*7c3d14c8STreehugger Robot if (test__truncdfhf2(-makeInf64(),
49*7c3d14c8STreehugger Robot UINT16_C(0xfc00)))
50*7c3d14c8STreehugger Robot return 1;
51*7c3d14c8STreehugger Robot // zero
52*7c3d14c8STreehugger Robot if (test__truncdfhf2(0.0, UINT16_C(0x0)))
53*7c3d14c8STreehugger Robot return 1;
54*7c3d14c8STreehugger Robot if (test__truncdfhf2(-0.0, UINT16_C(0x8000)))
55*7c3d14c8STreehugger Robot return 1;
56*7c3d14c8STreehugger Robot
57*7c3d14c8STreehugger Robot if (test__truncdfhf2(3.1415926535,
58*7c3d14c8STreehugger Robot UINT16_C(0x4248)))
59*7c3d14c8STreehugger Robot return 1;
60*7c3d14c8STreehugger Robot if (test__truncdfhf2(-3.1415926535,
61*7c3d14c8STreehugger Robot UINT16_C(0xc248)))
62*7c3d14c8STreehugger Robot return 1;
63*7c3d14c8STreehugger Robot if (test__truncdfhf2(0x1.987124876876324p+1000,
64*7c3d14c8STreehugger Robot UINT16_C(0x7c00)))
65*7c3d14c8STreehugger Robot return 1;
66*7c3d14c8STreehugger Robot if (test__truncdfhf2(0x1.987124876876324p+12,
67*7c3d14c8STreehugger Robot UINT16_C(0x6e62)))
68*7c3d14c8STreehugger Robot return 1;
69*7c3d14c8STreehugger Robot if (test__truncdfhf2(0x1.0p+0,
70*7c3d14c8STreehugger Robot UINT16_C(0x3c00)))
71*7c3d14c8STreehugger Robot return 1;
72*7c3d14c8STreehugger Robot if (test__truncdfhf2(0x1.0p-14,
73*7c3d14c8STreehugger Robot UINT16_C(0x0400)))
74*7c3d14c8STreehugger Robot return 1;
75*7c3d14c8STreehugger Robot // denormal
76*7c3d14c8STreehugger Robot if (test__truncdfhf2(0x1.0p-20,
77*7c3d14c8STreehugger Robot UINT16_C(0x0010)))
78*7c3d14c8STreehugger Robot return 1;
79*7c3d14c8STreehugger Robot if (test__truncdfhf2(0x1.0p-24,
80*7c3d14c8STreehugger Robot UINT16_C(0x0001)))
81*7c3d14c8STreehugger Robot return 1;
82*7c3d14c8STreehugger Robot if (test__truncdfhf2(-0x1.0p-24,
83*7c3d14c8STreehugger Robot UINT16_C(0x8001)))
84*7c3d14c8STreehugger Robot return 1;
85*7c3d14c8STreehugger Robot if (test__truncdfhf2(0x1.5p-25,
86*7c3d14c8STreehugger Robot UINT16_C(0x0001)))
87*7c3d14c8STreehugger Robot return 1;
88*7c3d14c8STreehugger Robot // and back to zero
89*7c3d14c8STreehugger Robot if (test__truncdfhf2(0x1.0p-25,
90*7c3d14c8STreehugger Robot UINT16_C(0x0000)))
91*7c3d14c8STreehugger Robot return 1;
92*7c3d14c8STreehugger Robot if (test__truncdfhf2(-0x1.0p-25,
93*7c3d14c8STreehugger Robot UINT16_C(0x8000)))
94*7c3d14c8STreehugger Robot return 1;
95*7c3d14c8STreehugger Robot // max (precise)
96*7c3d14c8STreehugger Robot if (test__truncdfhf2(65504.0,
97*7c3d14c8STreehugger Robot UINT16_C(0x7bff)))
98*7c3d14c8STreehugger Robot return 1;
99*7c3d14c8STreehugger Robot // max (rounded)
100*7c3d14c8STreehugger Robot if (test__truncdfhf2(65519.0,
101*7c3d14c8STreehugger Robot UINT16_C(0x7bff)))
102*7c3d14c8STreehugger Robot return 1;
103*7c3d14c8STreehugger Robot // max (to +inf)
104*7c3d14c8STreehugger Robot if (test__truncdfhf2(65520.0,
105*7c3d14c8STreehugger Robot UINT16_C(0x7c00)))
106*7c3d14c8STreehugger Robot return 1;
107*7c3d14c8STreehugger Robot if (test__truncdfhf2(-65520.0,
108*7c3d14c8STreehugger Robot UINT16_C(0xfc00)))
109*7c3d14c8STreehugger Robot return 1;
110*7c3d14c8STreehugger Robot if (test__truncdfhf2(65536.0,
111*7c3d14c8STreehugger Robot UINT16_C(0x7c00)))
112*7c3d14c8STreehugger Robot return 1;
113*7c3d14c8STreehugger Robot return 0;
114*7c3d14c8STreehugger Robot }
115