Skip to content

Commit

Permalink
Add test case for extendhfxf2
Browse files Browse the repository at this point in the history
  • Loading branch information
biabbas committed Sep 30, 2024
1 parent 81cb9d5 commit 7750d70
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler-rt/lib/builtins/extendhfxf2.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//===-- lib/extendhfxf2.c - half -> long double conversion -------------*- C -*-===//
//===-- lib/extendhfxf2.c - half -> long double conversion -------------*- C
//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
60 changes: 60 additions & 0 deletions compiler-rt/test/builtins/Unit/extendhfxf2_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_extendhfxf2

#include <limits.h>
#include <math.h> // for isnan, isinf
#include <stdio.h>

long double __extendhfxf2(_Float16 f);

int test_extendhfxf2(_Float16 a, long double expected) {
long double x = __extendhfxf2(a);
int ret = !(x == expected || (isnan(x) && isnan(expected)) ||
(isinf(x) && isinf(expected) && x == expected));
if (ret) {
printf("error in test__extendhfsf2(%f) = %.20Lf, "
"expected %.20Lf\n",
a, x, expected);
}
return ret;
}

char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0};

int main() {
// Small positive value
if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000f))
return 1;

// Small negative value
if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000f))
return 1;

// Zero
if (test_extendhfxf2(0.0f, 0.0L))
return 1;

// Smallest positive non-zero value
if (test_extendhfxf2(0x1p-16f, 0x1p-16f))
return 1;

// Smallest negative non-zero value
if (test_extendhfxf2(-0x1p-16f, -0x1p-16f))
return 1;

// Positive infinity
if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x()))
return 1;

// Negative infinity
if (test_extendhfxf2(-__builtin_huge_valf16(),
(long double)-__builtin_huge_valf64x()))
return 1;

// NaN
if (test_extendhfxf2(__builtin_nanf16(""),
(long double)__builtin_nanf64x("")))
return 1;

return 0;
}

0 comments on commit 7750d70

Please sign in to comment.