| 1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
| 2 | // REQUIRES: librt_has_extendhfxf2 |
| 3 | |
| 4 | #include <limits.h> |
| 5 | #include <math.h> // for isnan, isinf |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include "fp_test.h" |
| 9 | |
| 10 | #if HAS_80_BIT_LONG_DOUBLE |
| 11 | |
| 12 | xf_float __extendhfxf2(TYPE_FP16 f); |
| 13 | |
| 14 | int test_extendhfxf2(TYPE_FP16 a, uint16_t expectedHi, uint64_t expectedLo) { |
| 15 | xf_float x = __extendhfxf2(f: a); |
| 16 | int ret = compareResultF80(result: x, expectedHi, expectedLo); |
| 17 | if (ret) { |
| 18 | printf(format: "error in test__extendhfxf2(%#.4x) = %.20Lf, " |
| 19 | "expected %.20Lf\n" , |
| 20 | toRep16(x: a), x, F80FromRep80(hi: expectedHi, lo: expectedLo)); |
| 21 | } |
| 22 | return ret; |
| 23 | } |
| 24 | |
| 25 | int main() { |
| 26 | // Small positive value |
| 27 | if (test_extendhfxf2(a: fromRep16(x: 0x2e66), UINT16_C(0x3ffb), |
| 28 | UINT64_C(0xccc0000000000000))) |
| 29 | return 1; |
| 30 | |
| 31 | // Small negative value |
| 32 | if (test_extendhfxf2(a: fromRep16(x: 0xae66), UINT16_C(0xbffb), |
| 33 | UINT64_C(0xccc0000000000000))) |
| 34 | return 1; |
| 35 | |
| 36 | // Zero |
| 37 | if (test_extendhfxf2(a: fromRep16(x: 0), UINT16_C(0x0), UINT64_C(0x0))) |
| 38 | return 1; |
| 39 | |
| 40 | // Smallest positive non-zero value |
| 41 | if (test_extendhfxf2(a: fromRep16(x: 0x0100), UINT16_C(0x3fef), |
| 42 | UINT64_C(0x8000000000000000))) |
| 43 | return 1; |
| 44 | |
| 45 | // Smallest negative non-zero value |
| 46 | if (test_extendhfxf2(a: fromRep16(x: 0x8100), UINT16_C(0xbfef), |
| 47 | UINT64_C(0x8000000000000000))) |
| 48 | return 1; |
| 49 | |
| 50 | // Positive infinity |
| 51 | if (test_extendhfxf2(a: makeInf16(), UINT16_C(0x7fff), |
| 52 | UINT64_C(0x8000000000000000))) |
| 53 | return 1; |
| 54 | |
| 55 | // Negative infinity |
| 56 | if (test_extendhfxf2(a: makeNegativeInf16(), UINT16_C(0xffff), |
| 57 | UINT64_C(0x8000000000000000))) |
| 58 | return 1; |
| 59 | |
| 60 | // NaN |
| 61 | if (test_extendhfxf2(a: makeQNaN16(), UINT16_C(0x7fff), |
| 62 | UINT64_C(0xc000000000000000))) |
| 63 | return 1; |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | #else |
| 69 | |
| 70 | int main() { |
| 71 | printf("skipped\n" ); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | #endif |
| 76 | |