|
| 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 | +long double __extendhfxf2(_Float16 f); |
| 9 | + |
| 10 | +int test_extendhfxf2(_Float16 a, long double expected) { |
| 11 | + long double x = __extendhfxf2(a); |
| 12 | + __uint16_t *b = (void *)&a; |
| 13 | + int ret = !(x == expected || (isnan(x) && isnan(expected)) || |
| 14 | + (isinf(x) && isinf(expected) && x == expected)); |
| 15 | + if (ret) { |
| 16 | + printf("error in test__extendhfsf2(%#.4x) = %.20Lf, " |
| 17 | + "expected %.20Lf\n", |
| 18 | + *b, x, expected); |
| 19 | + } |
| 20 | + return ret; |
| 21 | +} |
| 22 | + |
| 23 | +char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0}; |
| 24 | + |
| 25 | +int main() { |
| 26 | + // Small positive value |
| 27 | + if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000L)) |
| 28 | + return 1; |
| 29 | + |
| 30 | + // Small negative value |
| 31 | + if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000L)) |
| 32 | + return 1; |
| 33 | + |
| 34 | + // Zero |
| 35 | + if (test_extendhfxf2(0.0f, 0.0L)) |
| 36 | + return 1; |
| 37 | + |
| 38 | + // Smallest positive non-zero value |
| 39 | + if (test_extendhfxf2(0x1p-16f, 0x1p-16L)) |
| 40 | + return 1; |
| 41 | + |
| 42 | + // Smallest negative non-zero value |
| 43 | + if (test_extendhfxf2(-0x1p-16f, -0x1p-16L)) |
| 44 | + return 1; |
| 45 | + |
| 46 | + // Positive infinity |
| 47 | + if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x())) |
| 48 | + return 1; |
| 49 | + |
| 50 | + // Negative infinity |
| 51 | + if (test_extendhfxf2(-__builtin_huge_valf16(), |
| 52 | + (long double)-__builtin_huge_valf64x())) |
| 53 | + return 1; |
| 54 | + |
| 55 | + // NaN |
| 56 | + if (test_extendhfxf2(__builtin_nanf16(""), |
| 57 | + (long double)__builtin_nanf64x(""))) |
| 58 | + return 1; |
| 59 | + |
| 60 | + return 0; |
| 61 | +} |
0 commit comments