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