Skip to content

Commit fb2e1e0

Browse files
committed
Add testcase for extendhfxf2
1 parent 545d921 commit fb2e1e0

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %clang_builtins %s %librt -o %t && %run %t
2+
// REQUIRES: librt_has_extendhfxf2
3+
4+
#include <stdio.h>
5+
#include <math.h> // for isnan, isinf
6+
#include <limits.h>
7+
8+
long double __extendhfxf2(_Float16 f);
9+
10+
int test_extendhfxf2(_Float16 a, long double expected)
11+
{
12+
long double x = __extendhfxf2(a);
13+
int ret = !(x == expected || (isnan(x) && isnan(expected)) || (isinf(x) && isinf(expected) && x == expected));
14+
if (ret){
15+
printf("error in test__extendhfsf2(%f) = %.20Lf, "
16+
"expected %.20Lf\n", a, x, expected);
17+
}
18+
return ret;
19+
}
20+
21+
char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0};
22+
23+
int main() {
24+
// Small positive value
25+
if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000f))
26+
return 1;
27+
28+
// Small negative value
29+
if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000f))
30+
return 1;
31+
32+
// Zero
33+
if (test_extendhfxf2(0.0f, 0.0L))
34+
return 1;
35+
36+
// Smallest positive non-zero value
37+
if (test_extendhfxf2(0x1p-16f, 0x1p-16f))
38+
return 1;
39+
40+
// Smallest negative non-zero value
41+
if (test_extendhfxf2(-0x1p-16f, -0x1p-16f))
42+
return 1;
43+
44+
// Positive infinity
45+
if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x()))
46+
return 1;
47+
48+
// Negative infinity
49+
if (test_extendhfxf2(-__builtin_huge_valf16(), (long double)-__builtin_huge_valf64x()))
50+
return 1;
51+
52+
// NaN
53+
if (test_extendhfxf2(__builtin_nanf16(""), (long double)__builtin_nanf64x("")))
54+
return 1;
55+
56+
return 0;
57+
}

0 commit comments

Comments
 (0)