|
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, uint64_t expectedHi, uint64_t expectedLo) { |
| 15 | + xf_float x = __extendhfxf2(a); |
| 16 | + int ret = compareResultF80(x, expectedHi, expectedLo); |
18 | 17 | if (ret) { |
19 | 18 | printf("error in test__extendhfxf2(%#.4x) = %.20Lf, " |
20 | 19 | "expected %.20Lf\n", |
21 | | - *b, x, expected); |
| 20 | + toRep16(a), x, F80FromRep128(expectedHi, expectedLo)); |
22 | 21 | } |
23 | 22 | return ret; |
24 | 23 | } |
25 | 24 |
|
26 | | -char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0}; |
27 | | - |
28 | 25 | int main() { |
29 | 26 | // Small positive value |
30 | | - if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000L)) |
| 27 | + if (test_extendhfxf2(fromRep16(0x2e66), UINT64_C(0x3ffb), |
| 28 | + UINT64_C(0xccc0000000000000))) |
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), UINT64_C(0xbffb), |
| 33 | + UINT64_C(0xccc0000000000000))) |
35 | 34 | return 1; |
36 | 35 |
|
37 | 36 | // Zero |
38 | | - if (test_extendhfxf2(0.0f, 0.0L)) |
| 37 | + if (test_extendhfxf2(fromRep16(0), UINT64_C(0x0), UINT64_C(0x0))) |
39 | 38 | return 1; |
40 | 39 |
|
41 | 40 | // Smallest positive non-zero value |
42 | | - if (test_extendhfxf2(0x1p-16f, 0x1p-16L)) |
| 41 | + if (test_extendhfxf2(fromRep16(0x0100), UINT64_C(0x3fef), |
| 42 | + UINT64_C(0x8000000000000000))) |
43 | 43 | return 1; |
44 | 44 |
|
45 | 45 | // Smallest negative non-zero value |
46 | | - if (test_extendhfxf2(-0x1p-16f, -0x1p-16L)) |
| 46 | + if (test_extendhfxf2(fromRep16(0x8100), UINT64_C(0xbfef), |
| 47 | + UINT64_C(0x8000000000000000))) |
47 | 48 | return 1; |
48 | 49 |
|
49 | 50 | // Positive infinity |
50 | | - if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x())) |
| 51 | + if (test_extendhfxf2(makeInf16(), UINT64_C(0x7fff), |
| 52 | + UINT64_C(0x8000000000000000))) |
51 | 53 | return 1; |
52 | 54 |
|
53 | 55 | // Negative infinity |
54 | | - if (test_extendhfxf2(-__builtin_huge_valf16(), |
55 | | - (long double)-__builtin_huge_valf64x())) |
| 56 | + if (test_extendhfxf2(makeNegativeInf16(), UINT64_C(0xffff), |
| 57 | + UINT64_C(0x8000000000000000))) |
56 | 58 | return 1; |
57 | 59 |
|
58 | 60 | // NaN |
59 | | - if (test_extendhfxf2(__builtin_nanf16(""), |
60 | | - (long double)__builtin_nanf64x(""))) |
| 61 | + if (test_extendhfxf2(makeQNaN16(), UINT64_C(0x7fff), |
| 62 | + UINT64_C(0xc000000000000000))) |
61 | 63 | return 1; |
62 | 64 |
|
63 | 65 | return 0; |
|
0 commit comments