Skip to content

Commit 7750d70

Browse files
committed
Add test case for extendhfxf2
1 parent 81cb9d5 commit 7750d70

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

compiler-rt/lib/builtins/extendhfxf2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//===-- lib/extendhfxf2.c - half -> long double conversion -------------*- C -*-===//
1+
//===-- lib/extendhfxf2.c - half -> long double conversion -------------*- C
2+
//-*-===//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
int ret = !(x == expected || (isnan(x) && isnan(expected)) ||
13+
(isinf(x) && isinf(expected) && x == expected));
14+
if (ret) {
15+
printf("error in test__extendhfsf2(%f) = %.20Lf, "
16+
"expected %.20Lf\n",
17+
a, x, expected);
18+
}
19+
return ret;
20+
}
21+
22+
char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0};
23+
24+
int main() {
25+
// Small positive value
26+
if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000f))
27+
return 1;
28+
29+
// Small negative value
30+
if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000f))
31+
return 1;
32+
33+
// Zero
34+
if (test_extendhfxf2(0.0f, 0.0L))
35+
return 1;
36+
37+
// Smallest positive non-zero value
38+
if (test_extendhfxf2(0x1p-16f, 0x1p-16f))
39+
return 1;
40+
41+
// Smallest negative non-zero value
42+
if (test_extendhfxf2(-0x1p-16f, -0x1p-16f))
43+
return 1;
44+
45+
// Positive infinity
46+
if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x()))
47+
return 1;
48+
49+
// Negative infinity
50+
if (test_extendhfxf2(-__builtin_huge_valf16(),
51+
(long double)-__builtin_huge_valf64x()))
52+
return 1;
53+
54+
// NaN
55+
if (test_extendhfxf2(__builtin_nanf16(""),
56+
(long double)__builtin_nanf64x("")))
57+
return 1;
58+
59+
return 0;
60+
}

0 commit comments

Comments
 (0)