|
5 | 5 | #include <math.h> // for isnan, isinf
|
6 | 6 | #include <stdio.h>
|
7 | 7 |
|
8 |
| -#include "int_lib.h" |
| 8 | +#include "fp_test.h" |
9 | 9 |
|
10 | 10 | #if HAS_80_BIT_LONG_DOUBLE && defined(COMPILER_RT_HAS_FLOAT16)
|
11 | 11 |
|
12 |
| -long double __extendhfxf2(_Float16 f); |
| 12 | +xf_float __extendhfxf2(TYPE_FP16 f); |
13 | 13 |
|
14 |
| -int test_extendhfxf2(_Float16 a, long double expected) { |
15 |
| - long double x = __extendhfxf2(a); |
16 |
| - __uint16_t *b = (void *)&a; |
17 |
| - int ret = !((isnan(x) && isnan(expected)) || x == expected); |
| 14 | +int test_extendhfxf2(TYPE_FP16 a, xf_float expected) { |
| 15 | + xf_float x = __extendhfxf2(a); |
| 16 | + uint16_t a_rep = toRep16(a); |
| 17 | + int ret = compareResultF80(x, expected); |
18 | 18 | if (ret) {
|
19 | 19 | printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
|
20 | 20 | "expected %.20Lf\n",
|
21 |
| - *b, x, expected); |
| 21 | + a_rep, x, expected); |
22 | 22 | }
|
23 | 23 | return ret;
|
24 | 24 | }
|
25 | 25 |
|
26 |
| -char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0}; |
27 |
| - |
28 | 26 | int main() {
|
29 | 27 | // Small positive value
|
30 |
| - if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000L)) |
| 28 | + if (test_extendhfxf2(fromRep16(0x2e66), 0.09997558593750000000L)) |
31 | 29 | return 1;
|
32 | 30 |
|
33 | 31 | // Small negative value
|
34 |
| - if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000L)) |
| 32 | + if (test_extendhfxf2(fromRep16(0xae66), -0.09997558593750000000L)) |
35 | 33 | return 1;
|
36 | 34 |
|
37 | 35 | // Zero
|
38 |
| - if (test_extendhfxf2(0.0f, 0.0L)) |
| 36 | + if (test_extendhfxf2(fromRep16(0), 0.0L)) |
39 | 37 | return 1;
|
40 | 38 |
|
41 | 39 | // Smallest positive non-zero value
|
42 |
| - if (test_extendhfxf2(0x1p-16f, 0x1p-16L)) |
| 40 | + if (test_extendhfxf2(fromRep16(0x0100), 0x1p-16L)) |
43 | 41 | return 1;
|
44 | 42 |
|
45 | 43 | // Smallest negative non-zero value
|
46 |
| - if (test_extendhfxf2(-0x1p-16f, -0x1p-16L)) |
| 44 | + if (test_extendhfxf2(fromRep16(0x8100), -0x1p-16L)) |
47 | 45 | return 1;
|
48 | 46 |
|
49 | 47 | // Positive infinity
|
50 |
| - if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x())) |
| 48 | + if (test_extendhfxf2(makeInf16(), makeInf80())) |
51 | 49 | return 1;
|
52 | 50 |
|
53 | 51 | // Negative infinity
|
54 |
| - if (test_extendhfxf2(-__builtin_huge_valf16(), |
55 |
| - (long double)-__builtin_huge_valf64x())) |
| 52 | + if (test_extendhfxf2(makeNegativeInf16(), makeNegativeInf80())) |
56 | 53 | return 1;
|
57 | 54 |
|
58 | 55 | // NaN
|
59 |
| - if (test_extendhfxf2(__builtin_nanf16(""), |
60 |
| - (long double)__builtin_nanf64x(""))) |
| 56 | + if (test_extendhfxf2(makeQNaN16(), makeQNaN80())) |
61 | 57 | return 1;
|
62 | 58 |
|
63 | 59 | return 0;
|
|
0 commit comments