1 //===--------------- extendhfsf2_test.c - Test __extendhfsf2 --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __extendhfsf2 for the compiler_rt library.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include <stdio.h>
15
16 #include "fp_test.h"
17
18 float __extendhfsf2(uint16_t a);
19
test__extendhfsf2(uint16_t a,float expected)20 int test__extendhfsf2(uint16_t a, float expected)
21 {
22 float x = __extendhfsf2(a);
23 int ret = compareResultH(x, expected);
24
25 if (ret){
26 printf("error in test__extendhfsf2(%#.4x) = %f, "
27 "expected %f\n", a, x, expected);
28 }
29 return ret;
30 }
31
32 char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0};
33
main()34 int main()
35 {
36 // qNaN
37 if (test__extendhfsf2(UINT16_C(0x7e00),
38 makeQNaN32()))
39 return 1;
40 // NaN
41 if (test__extendhfsf2(UINT16_C(0x7e00),
42 makeNaN32(UINT32_C(0x8000))))
43 return 1;
44 // inf
45 if (test__extendhfsf2(UINT16_C(0x7c00),
46 makeInf32()))
47 return 1;
48 if (test__extendhfsf2(UINT16_C(0xfc00),
49 -makeInf32()))
50 return 1;
51 // zero
52 if (test__extendhfsf2(UINT16_C(0x0),
53 0.0f))
54 return 1;
55 if (test__extendhfsf2(UINT16_C(0x8000),
56 -0.0f))
57 return 1;
58
59 if (test__extendhfsf2(UINT16_C(0x4248),
60 3.1415926535f))
61 return 1;
62 if (test__extendhfsf2(UINT16_C(0xc248),
63 -3.1415926535f))
64 return 1;
65 if (test__extendhfsf2(UINT16_C(0x7c00),
66 0x1.987124876876324p+100f))
67 return 1;
68 if (test__extendhfsf2(UINT16_C(0x6e62),
69 0x1.988p+12f))
70 return 1;
71 if (test__extendhfsf2(UINT16_C(0x3c00),
72 0x1.0p+0f))
73 return 1;
74 if (test__extendhfsf2(UINT16_C(0x0400),
75 0x1.0p-14f))
76 return 1;
77 // denormal
78 if (test__extendhfsf2(UINT16_C(0x0010),
79 0x1.0p-20f))
80 return 1;
81 if (test__extendhfsf2(UINT16_C(0x0001),
82 0x1.0p-24f))
83 return 1;
84 if (test__extendhfsf2(UINT16_C(0x8001),
85 -0x1.0p-24f))
86 return 1;
87 if (test__extendhfsf2(UINT16_C(0x0001),
88 0x1.5p-25f))
89 return 1;
90 // and back to zero
91 if (test__extendhfsf2(UINT16_C(0x0000),
92 0x1.0p-25f))
93 return 1;
94 if (test__extendhfsf2(UINT16_C(0x8000),
95 -0x1.0p-25f))
96 return 1;
97 // max (precise)
98 if (test__extendhfsf2(UINT16_C(0x7bff),
99 65504.0f))
100 return 1;
101 // max (rounded)
102 if (test__extendhfsf2(UINT16_C(0x7bff),
103 65504.0f))
104 return 1;
105 // max (to +inf)
106 if (test__extendhfsf2(UINT16_C(0x7c00),
107 makeInf32()))
108 return 1;
109 if (test__extendhfsf2(UINT16_C(0xfc00),
110 -makeInf32()))
111 return 1;
112 return 0;
113 }
114