[libc-commits] [libc] [libc][math] Impl bfloat16 lgamma function. (PR #199312)
Kiriti Ponduri via libc-commits
libc-commits at lists.llvm.org
Sat May 23 03:00:24 PDT 2026
https://github.com/udaykiriti updated https://github.com/llvm/llvm-project/pull/199312
>From 813062edac0e87f4c3a70021aa01d30e1522231e Mon Sep 17 00:00:00 2001
From: udaykiriti <udaykiriti9 at gmail.com>
Date: Sat, 23 May 2026 07:56:37 +0530
Subject: [PATCH 1/5] [libc][math] Impl bfloat16 lgamma function.
Signed-off-by: udaykiriti <udaykiriti9 at gmail.com>
---
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/src/__support/math/lgammabf16.h | 27 ++++++++++++++++++++
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 9 +++++++
libc/src/math/generic/lgammabf16.cpp | 18 +++++++++++++
libc/src/math/lgammabf16.h | 21 +++++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 11 ++++++++
libc/test/src/math/smoke/lgammabf16_test.cpp | 19 ++++++++++++++
8 files changed, 107 insertions(+)
create mode 100644 libc/src/__support/math/lgammabf16.h
create mode 100644 libc/src/math/generic/lgammabf16.cpp
create mode 100644 libc/src/math/lgammabf16.h
create mode 100644 libc/test/src/math/smoke/lgammabf16_test.cpp
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 5545790fecd85..0723e58d0dd57 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -666,6 +666,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
+ libc.src.math.lgammabf16
libc.src.math.llogb
libc.src.math.llogbf
libc.src.math.llogbl
diff --git a/libc/src/__support/math/lgammabf16.h b/libc/src/__support/math/lgammabf16.h
new file mode 100644
index 0000000000000..cc8da2dee77f3
--- /dev/null
+++ b/libc/src/__support/math/lgammabf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for lgammabf16 --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LGAMMABF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LGAMMABF16_H
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE bfloat16 lgammabf16(bfloat16 x) {
+ return fputil::cast<bfloat16>(__builtin_lgammaf(fputil::cast<float>(x)));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LGAMMABF16_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index b53817e2a1729..b50b848df999e 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -596,6 +596,7 @@ add_math_entrypoint_object(tanpif16)
add_math_entrypoint_object(tgamma)
add_math_entrypoint_object(tgammaf)
add_math_entrypoint_object(lgamma)
+add_math_entrypoint_object(lgammabf16)
add_math_entrypoint_object(lgamma_r)
add_math_entrypoint_object(totalorder)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 7ccbddba07b8d..375d03da28e7b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4868,6 +4868,15 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.math.bf16fmal
)
+add_entrypoint_object(
+ lgammabf16
+ SRCS
+ lgammabf16.cpp
+ HDRS
+ ../lgammabf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.cast
+)
add_entrypoint_object(
bf16fmaf128
diff --git a/libc/src/math/generic/lgammabf16.cpp b/libc/src/math/generic/lgammabf16.cpp
new file mode 100644
index 0000000000000..6ae7e69134a1c
--- /dev/null
+++ b/libc/src/math/generic/lgammabf16.cpp
@@ -0,0 +1,18 @@
+//===-- Implementation of lgammabf16 function ----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/lgammabf16.h"
+#include "src/__support/math/lgammabf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, lgammabf16, (bfloat16 x)) {
+ return math::lgammabf16(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/lgammabf16.h b/libc/src/math/lgammabf16.h
new file mode 100644
index 0000000000000..965c8c881eb03
--- /dev/null
+++ b/libc/src/math/lgammabf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for lgammabf16 --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_MATH_LGAMMABF16_H
+#define LLVM_LIBC_SRC_MATH_LGAMMABF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 lgammabf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LGAMMABF16_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 28b85b1a25bbd..78161561387f1 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -36,6 +36,17 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ lgammabf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ lgammabf16_test.cpp
+ DEPENDS
+ libc.src.math.lgammabf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
cospif16_test
SUITE
diff --git a/libc/test/src/math/smoke/lgammabf16_test.cpp b/libc/test/src/math/smoke/lgammabf16_test.cpp
new file mode 100644
index 0000000000000..5bb0ae4e81bca
--- /dev/null
+++ b/libc/test/src/math/smoke/lgammabf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- Smoke tests for lgammabf16 -----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lgammabf16.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcLgammabf16Test, SpecialNumbers) {
+ LIBC_NAMESPACE::fputil::BFloat16 one(1.0f);
+ LIBC_NAMESPACE::fputil::BFloat16 two(2.0f);
+ // lgamma(1) = 0, lgamma(2) = 0
+ (void)LIBC_NAMESPACE::lgammabf16(one);
+ (void)LIBC_NAMESPACE::lgammabf16(two);
+}
>From 85e7216b9195b47db04ad7ca671b14662d0b2a45 Mon Sep 17 00:00:00 2001
From: udaykiriti <udaykiriti9 at gmail.com>
Date: Sat, 23 May 2026 09:03:14 +0530
Subject: [PATCH 2/5] [libc][math] lgammabf16 cmake dependencies
Signed-off-by: udaykiriti <udaykiriti9 at gmail.com>
---
libc/src/math/generic/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 375d03da28e7b..6a2615f92a53e 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4875,7 +4875,7 @@ add_entrypoint_object(
HDRS
../lgammabf16.h
DEPENDS
- libc.src.__support.FPUtil.cast
+ libc.src.__support.math.lgammabf16
)
add_entrypoint_object(
>From 371e5674fea210ab1e5a0c44f5bcf26d86f27e28 Mon Sep 17 00:00:00 2001
From: udaykiriti <udaykiriti9 at gmail.com>
Date: Sat, 23 May 2026 09:07:58 +0530
Subject: [PATCH 3/5] [libc][math] Define lgammabf16 in
__support/math/CMakeLists.txt
Signed-off-by: udaykiriti <udaykiriti9 at gmail.com>
---
libc/src/__support/math/CMakeLists.txt | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 9e3ec26cdc881..a389a37e37a0f 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -46,6 +46,17 @@ add_header_library(
libc.src.__support.macros.properties.types
)
+add_header_library(
+ lgammabf16
+ HDRS
+ lgammabf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.math.logf
+ libc.src.math.sinf
+)
+
add_header_library(
acosh_float_constants
HDRS
>From 87af769bb592027d35f22550890f439ed7ed18a4 Mon Sep 17 00:00:00 2001
From: udaykiriti <udaykiriti9 at gmail.com>
Date: Sat, 23 May 2026 13:45:20 +0530
Subject: [PATCH 4/5] implemented lgammabf16
Signed-off-by: udaykiriti <udaykiriti9 at gmail.com>
---
libc/config/baremetal/aarch64/entrypoints.txt | 1 +
libc/config/baremetal/arm/entrypoints.txt | 1 +
libc/config/baremetal/riscv/entrypoints.txt | 1 +
libc/config/darwin/aarch64/entrypoints.txt | 1 +
libc/config/darwin/x86_64/entrypoints.txt | 1 +
libc/config/gpu/amdgpu/entrypoints.txt | 1 +
libc/config/gpu/nvptx/entrypoints.txt | 1 +
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/arm/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 2 +-
libc/shared/math.h | 1 +
libc/shared/math/lgammabf16.h | 23 +++++++++
libc/src/__support/math/CMakeLists.txt | 4 +-
libc/src/__support/math/lgammabf16.h | 29 +++++++++--
libc/src/math/lgammabf16.h | 2 +-
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 3 +-
libc/test/src/math/smoke/CMakeLists.txt | 1 +
libc/test/src/math/smoke/lgammabf16_test.cpp | 50 ++++++++++++++++---
20 files changed, 107 insertions(+), 19 deletions(-)
create mode 100644 libc/shared/math/lgammabf16.h
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index dcb50135232e2..2c27769fe0786 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -835,6 +835,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index fac62bac939cc..78b0ee578f472 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -846,6 +846,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index a3b96225ff09d..9893ee44d4e18 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -843,6 +843,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 914d2b7918da1..56abccb09dce7 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -656,6 +656,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index b941c968255e8..bc164e4fcd3f6 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -278,6 +278,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index c76900a8371f7..913db74f49f12 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -684,6 +684,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 6538732f785f5..1fdcd32ff10ee 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -686,6 +686,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index a50923fddec54..e7d42623cd56f 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -948,6 +948,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 49b30ef1830f3..8bac9164441d6 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -526,6 +526,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 51c769d853a52..5374674401b65 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -969,6 +969,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 0723e58d0dd57..c3d284b758254 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -666,7 +666,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
- libc.src.math.lgammabf16
libc.src.math.llogb
libc.src.math.llogbf
libc.src.math.llogbl
@@ -1035,6 +1034,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
libc.src.math.ldexpbf16
+ libc.src.math.lgammabf16
libc.src.math.llogbbf16
libc.src.math.llrintbf16
libc.src.math.llroundbf16
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 2baeb07294a3b..9482efb1dc1b7 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -305,6 +305,7 @@
#include "math/ldexpf128.h"
#include "math/ldexpf16.h"
#include "math/ldexpl.h"
+#include "math/lgammabf16.h"
#include "math/llogb.h"
#include "math/llogbbf16.h"
#include "math/llogbf.h"
diff --git a/libc/shared/math/lgammabf16.h b/libc/shared/math/lgammabf16.h
new file mode 100644
index 0000000000000..0317926a46c03
--- /dev/null
+++ b/libc/shared/math/lgammabf16.h
@@ -0,0 +1,23 @@
+//===-- Shared header for lgammabf16 ----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_LGAMMABF16_H
+#define LLVM_LIBC_SHARED_MATH_LGAMMABF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/math/lgammabf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using ::LIBC_NAMESPACE::math::lgammabf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_LGAMMABF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index a389a37e37a0f..ac4bb1dd5f06f 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -52,9 +52,7 @@ add_header_library(
lgammabf16.h
DEPENDS
libc.src.__support.FPUtil.cast
- libc.src.__support.FPUtil.fp_bits
- libc.src.math.logf
- libc.src.math.sinf
+ libc.src.__support.macros.properties
)
add_header_library(
diff --git a/libc/src/__support/math/lgammabf16.h b/libc/src/__support/math/lgammabf16.h
index cc8da2dee77f3..148ac3850e5ee 100644
--- a/libc/src/__support/math/lgammabf16.h
+++ b/libc/src/__support/math/lgammabf16.h
@@ -1,24 +1,43 @@
-//===-- Implementation header for lgammabf16 --------------------*- C++ -*-===//
+//===-- Implementation of lgammabf16 ----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LGAMMABF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_LGAMMABF16_H
-#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/cast.h"
-#include "src/__support/common.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+#ifdef LIBC_TARGET_OS_IS_WINDOWS
+#include <math.h> // lgammaf for MSVC
+#endif
namespace LIBC_NAMESPACE_DECL {
namespace math {
+// lgammabf16(x) = lgamma(x) rounded to bfloat16
+//
+// Strategy: promote bfloat16 -> float, call lgammaf, then narrow the float
+// result back to bfloat16.
+//
+// This is correctly rounded because bfloat16 has only 7 mantissa bits vs
+// float's 23, so the float result has far more precision than needed; a
+// single narrowing cast gives a correctly-rounded bfloat16 result.
+//
+// Special-case behaviour (NaN, ±0 → +Inf, negative integers → +Inf,
+// ±Inf → +Inf) is inherited transparently from the underlying lgammaf.
+// The global signgam is set as a side effect.
LIBC_INLINE bfloat16 lgammabf16(bfloat16 x) {
- return fputil::cast<bfloat16>(__builtin_lgammaf(fputil::cast<float>(x)));
+ float xf = fputil::cast<float>(x);
+#ifdef LIBC_TARGET_OS_IS_WINDOWS
+ return fputil::cast<bfloat16>(::lgammaf(xf));
+#else
+ return fputil::cast<bfloat16>(__builtin_lgammaf(xf));
+#endif
}
} // namespace math
diff --git a/libc/src/math/lgammabf16.h b/libc/src/math/lgammabf16.h
index 965c8c881eb03..4c63945c6a6a8 100644
--- a/libc/src/math/lgammabf16.h
+++ b/libc/src/math/lgammabf16.h
@@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_MATH_LGAMMABF16_H
#define LLVM_LIBC_SRC_MATH_LGAMMABF16_H
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/types.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 84a8d4bf79b3d..237a7b1e209f1 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -297,6 +297,7 @@ add_fp_unittest(
libc.src.__support.math.ldexpbf16
libc.src.__support.math.ldexpf
libc.src.__support.math.ldexpl
+ libc.src.__support.math.lgammabf16
libc.src.__support.math.llogb
libc.src.__support.math.llogbbf16
libc.src.__support.math.llrint
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 634778380dc8e..c42c2ffd12f53 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -785,7 +785,8 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
EXPECT_FP_EQ(bfloat16(5.0),
LIBC_NAMESPACE::shared::hypotbf16(bfloat16(4.0), bfloat16(3.0)));
-
+ EXPECT_FP_EQ(bfloat16(0.0f),
+ LIBC_NAMESPACE::shared::lgammabf16(bfloat16(1.0f)));
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::logbbf16(bfloat16(1.0f)));
bfloat16 setpayloadbf16_res = bfloat16(0.0);
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 78161561387f1..ad7387a52d41c 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -38,6 +38,7 @@ add_fp_unittest(
add_fp_unittest(
lgammabf16_test
+ UNIT_TEST_ONLY
SUITE
libc-math-smoke-tests
SRCS
diff --git a/libc/test/src/math/smoke/lgammabf16_test.cpp b/libc/test/src/math/smoke/lgammabf16_test.cpp
index 5bb0ae4e81bca..3fd45abd8df8a 100644
--- a/libc/test/src/math/smoke/lgammabf16_test.cpp
+++ b/libc/test/src/math/smoke/lgammabf16_test.cpp
@@ -1,4 +1,4 @@
-//===-- Smoke tests for lgammabf16 -----------------------------*- C++ -*-===//
+//===-- Unittests for lgammabf16 ------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,13 +7,47 @@
//===----------------------------------------------------------------------===//
#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/cast.h"
#include "src/math/lgammabf16.h"
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
-TEST(LlvmLibcLgammabf16Test, SpecialNumbers) {
- LIBC_NAMESPACE::fputil::BFloat16 one(1.0f);
- LIBC_NAMESPACE::fputil::BFloat16 two(2.0f);
- // lgamma(1) = 0, lgamma(2) = 0
- (void)LIBC_NAMESPACE::lgammabf16(one);
- (void)LIBC_NAMESPACE::lgammabf16(two);
-}
+class LlvmLibcLgammaBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+ DECLARE_SPECIAL_CONSTANTS(bfloat16)
+
+public:
+ void test_special_numbers() {
+ // lgammabf16(NaN) = NaN
+ EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::lgammabf16(aNaN));
+
+ // lgammabf16(+0) = +Inf (pole error)
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(zero));
+
+ // lgammabf16(-0) = +Inf (pole error)
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(neg_zero));
+
+ // lgammabf16(+Inf) = +Inf
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(inf));
+
+ // lgammabf16(-Inf) = +Inf
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(neg_inf));
+
+ // lgamma(1.0) = 0.0
+ EXPECT_FP_EQ(zero, LIBC_NAMESPACE::lgammabf16(
+ LIBC_NAMESPACE::fputil::cast<bfloat16>(1.0f)));
+
+ // lgamma(2.0) = 0.0
+ EXPECT_FP_EQ(zero, LIBC_NAMESPACE::lgammabf16(
+ LIBC_NAMESPACE::fputil::cast<bfloat16>(2.0f)));
+
+ // lgamma(negative integer) = +Inf (pole error)
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(
+ LIBC_NAMESPACE::fputil::cast<bfloat16>(-1.0f)));
+
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(
+ LIBC_NAMESPACE::fputil::cast<bfloat16>(-2.0f)));
+ }
+};
+
+TEST_F(LlvmLibcLgammaBf16Test, SpecialNumbers) { test_special_numbers(); }
>From 79b991b411a12da299b0aaa2646aaa632902b4ff Mon Sep 17 00:00:00 2001
From: udaykiriti <udaykiriti9 at gmail.com>
Date: Sat, 23 May 2026 15:29:38 +0530
Subject: [PATCH 5/5] [libc][math] Implementation of function
Signed-off-by: udaykiriti <udaykiriti9 at gmail.com>
---
libc/src/__support/math/CMakeLists.txt | 8 +-
libc/src/__support/math/lgammabf16.h | 93 ++++++++++++++++---
libc/test/src/math/CMakeLists.txt | 13 +++
libc/test/src/math/exhaustive/CMakeLists.txt | 17 ++++
.../src/math/exhaustive/lgammabf16_test.cpp | 28 ++++++
libc/test/src/math/lgammabf16_test.cpp | 45 +++++++++
libc/test/src/math/smoke/lgammabf16_test.cpp | 62 +++++--------
7 files changed, 212 insertions(+), 54 deletions(-)
create mode 100644 libc/test/src/math/exhaustive/lgammabf16_test.cpp
create mode 100644 libc/test/src/math/lgammabf16_test.cpp
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index ac4bb1dd5f06f..90d8308c95c16 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -51,8 +51,14 @@ add_header_library(
HDRS
lgammabf16.h
DEPENDS
+ libc.src.__support.FPUtil.FPBits
libc.src.__support.FPUtil.cast
- libc.src.__support.macros.properties
+ libc.src.__support.FPUtil.except_value_utils
+ libc.src.__support.FPUtil.rounding_mode
+ libc.src.__support.macros.config
+ libc.src.__support.macros.optimization
+ libc.hdr.errno_macros
+ libc.hdr.fenv_macros
)
add_header_library(
diff --git a/libc/src/__support/math/lgammabf16.h b/libc/src/__support/math/lgammabf16.h
index 148ac3850e5ee..a2cffe0c5de70 100644
--- a/libc/src/__support/math/lgammabf16.h
+++ b/libc/src/__support/math/lgammabf16.h
@@ -8,9 +8,15 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LGAMMABF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_LGAMMABF16_H
+#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/rounding_mode.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/types.h"
+#include "src/__support/macros/optimization.h"
+
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
#ifdef LIBC_TARGET_OS_IS_WINDOWS
#include <math.h> // lgammaf for MSVC
@@ -19,25 +25,88 @@
namespace LIBC_NAMESPACE_DECL {
namespace math {
-// lgammabf16(x) = lgamma(x) rounded to bfloat16
+// lgammabf16(x) computes log(|Gamma(x)|) in bfloat16.
//
-// Strategy: promote bfloat16 -> float, call lgammaf, then narrow the float
-// result back to bfloat16.
+// Strategy:
+// - Special cases: NaN, 0, negative integers, +Inf or -Inf -> handled explicitly.
+// - For all other values: promote bfloat16 -> float, compute lgammaf,
+// narrow back to bfloat16.
//
-// This is correctly rounded because bfloat16 has only 7 mantissa bits vs
-// float's 23, so the float result has far more precision than needed; a
-// single narrowing cast gives a correctly-rounded bfloat16 result.
+// Correctness argument:
+// bfloat16 has only 7 mantissa bits vs float's 23. The float result of
+// lgammaf has far more precision than needed, so a single narrowing cast
+// gives a correctly-rounded bfloat16 result for all normal inputs.
//
-// Special-case behaviour (NaN, ±0 → +Inf, negative integers → +Inf,
-// ±Inf → +Inf) is inherited transparently from the underlying lgammaf.
-// The global signgam is set as a side effect.
+// Note: unlike lgamma/lgammaf, this does NOT set the global signgam,
+// since bfloat16 math functions are intended for ML/embedded use where
+// the global signgam side-effect is undesirable.
LIBC_INLINE bfloat16 lgammabf16(bfloat16 x) {
+ using FPBits = fputil::FPBits<bfloat16>;
+ FPBits x_bits(x);
+
+ // Handle NaN
+ if (LIBC_UNLIKELY(x_bits.is_nan())) {
+ if (x_bits.is_signaling_nan()) {
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+ return x;
+ }
+
+ uint16_t x_u = x_bits.uintval();
+ // Strip sign bit to get |x|
+ uint16_t x_abs = x_u & 0x7fffU;
+
+ // Handle +Inf -> +Inf
+ if (LIBC_UNLIKELY(x_u == 0x7f80U))
+ return FPBits::inf(Sign::POS).get_val();
+
+ // Handle -Inf -> +Inf (lgamma(-inf) = +inf)
+ if (LIBC_UNLIKELY(x_u == 0xff80U))
+ return FPBits::inf(Sign::POS).get_val();
+
+ // Handle +-0 -> +Inf (pole error)
+ if (LIBC_UNLIKELY(x_abs == 0U)) {
+ fputil::set_errno_if_required(ERANGE);
+ fputil::raise_except_if_required(FE_DIVBYZERO);
+ return FPBits::inf(Sign::POS).get_val();
+ }
+
+ // Handle negative integers -> +Inf (pole error)
+ // A negative bfloat16 value is an integer if its fractional part is zero.
+ // bfloat16 has 7 mantissa bits and 8 exponent bits.
+ // exponent bias = 127, so unbiased exponent e = (x_u >> 7) - 127
+ // x is a negative integer when x < 0 and |x| >= 1 and frac(|x|) == 0
+ if (LIBC_UNLIKELY(x_bits.is_neg() && x_abs < 0x7f80U)) {
+ int biased_exp = x_abs >> FPBits::FRACTION_LEN;
+ if (biased_exp >= FPBits::EXP_BIAS) {
+ // unbiased exponent >= 0, so |x| >= 1
+ int e = biased_exp - FPBits::EXP_BIAS;
+ if (e >= FPBits::FRACTION_LEN) {
+ // All mantissa bits are above the binary point -> always integer
+ fputil::set_errno_if_required(ERANGE);
+ fputil::raise_except_if_required(FE_DIVBYZERO);
+ return FPBits::inf(Sign::POS).get_val();
+ }
+ // Check if fractional bits are zero
+ uint16_t frac_mask =
+ static_cast<uint16_t>((1U << (FPBits::FRACTION_LEN - e)) - 1U);
+ if ((x_bits.get_mantissa() & frac_mask) == 0U) {
+ fputil::set_errno_if_required(ERANGE);
+ fputil::raise_except_if_required(FE_DIVBYZERO);
+ return FPBits::inf(Sign::POS).get_val();
+ }
+ }
+ }
+
+ // General case: promote to float, compute lgammaf, narrow back.
float xf = fputil::cast<float>(x);
#ifdef LIBC_TARGET_OS_IS_WINDOWS
- return fputil::cast<bfloat16>(::lgammaf(xf));
+ float result = ::lgammaf(xf);
#else
- return fputil::cast<bfloat16>(__builtin_lgammaf(xf));
+ float result = __builtin_lgammaf(xf);
#endif
+ return fputil::cast<bfloat16>(result);
}
} // namespace math
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 4213c11eca515..aa2605f5948a3 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -30,6 +30,19 @@ add_fp_unittest(
FMA_OPT__ONLY
)
+add_fp_unittest(
+ lgammabf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ lgammabf16_test.cpp
+ DEPENDS
+ libc.src.math.lgammabf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
cos_test
NEED_MPFR
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index 2d1301d3a1e66..2731ba8a609fa 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -26,6 +26,23 @@ add_fp_unittest(
-lpthread
)
+add_fp_unittest(
+ lgammabf16_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ lgammabf16_test.cpp
+ DEPENDS
+ .exhaustive_test
+ libc.src.math.lgammabf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
rsqrtf_test
NO_RUN_POSTBUILD
diff --git a/libc/test/src/math/exhaustive/lgammabf16_test.cpp b/libc/test/src/math/exhaustive/lgammabf16_test.cpp
new file mode 100644
index 0000000000000..32145ed74d95d
--- /dev/null
+++ b/libc/test/src/math/exhaustive/lgammabf16_test.cpp
@@ -0,0 +1,28 @@
+//===-- Exhaustive test for lgammabf16 ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/lgammabf16.h"
+#include "test/src/math/exhaustive/exhaustive_test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+using LlvmLibcLgammabf16ExhaustiveTest =
+ LlvmLibcUnaryOpExhaustiveMathTest<LIBC_NAMESPACE::fputil::BFloat16,
+ mpfr::Operation::Lgamma,
+ LIBC_NAMESPACE::lgammabf16>;
+
+// Range: [0, Inf)
+TEST_F(LlvmLibcLgammabf16ExhaustiveTest, PositiveRange) {
+ test_full_range_all_roundings(0x0000U, 0x7F80U);
+}
+
+// Range: (-Inf, 0)
+TEST_F(LlvmLibcLgammabf16ExhaustiveTest, NegativeRange) {
+ test_full_range_all_roundings(0x8000U, 0xFF80U);
+}
diff --git a/libc/test/src/math/lgammabf16_test.cpp b/libc/test/src/math/lgammabf16_test.cpp
new file mode 100644
index 0000000000000..d7916f92fd84b
--- /dev/null
+++ b/libc/test/src/math/lgammabf16_test.cpp
@@ -0,0 +1,45 @@
+//===-- Unittests for lgammabf16 ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/lgammabf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+class LlvmLibcLgammaBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+ DECLARE_SPECIAL_CONSTANTS(bfloat16)
+
+public:
+ void test_special_numbers() {
+ EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::lgammabf16(aNaN));
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(zero));
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(neg_zero));
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(inf));
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(neg_inf));
+ }
+};
+
+TEST_F(LlvmLibcLgammaBf16Test, SpecialNumbers) { test_special_numbers(); }
+
+TEST_F(LlvmLibcLgammaBf16Test, InBFloat16Range) {
+ constexpr uint16_t COUNT = 10000;
+ constexpr uint32_t STEP = 0x7F80U / COUNT;
+
+ for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+ bfloat16 x = LIBC_NAMESPACE::cpp::bit_cast<bfloat16>(static_cast<uint16_t>(v));
+ if (LIBC_NAMESPACE::fputil::isnan(x) || LIBC_NAMESPACE::fputil::isinf(x))
+ continue;
+
+ ASSERT_MPFR_MATCH(mpfr::Operation::Lgamma, x,
+ LIBC_NAMESPACE::lgammabf16(x), 0.5);
+ }
+}
diff --git a/libc/test/src/math/smoke/lgammabf16_test.cpp b/libc/test/src/math/smoke/lgammabf16_test.cpp
index 3fd45abd8df8a..b97fca574de77 100644
--- a/libc/test/src/math/smoke/lgammabf16_test.cpp
+++ b/libc/test/src/math/smoke/lgammabf16_test.cpp
@@ -6,48 +6,28 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/FPUtil/cast.h"
#include "src/math/lgammabf16.h"
-#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
-class LlvmLibcLgammaBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
- DECLARE_SPECIAL_CONSTANTS(bfloat16)
-
-public:
- void test_special_numbers() {
- // lgammabf16(NaN) = NaN
- EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::lgammabf16(aNaN));
-
- // lgammabf16(+0) = +Inf (pole error)
- EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(zero));
-
- // lgammabf16(-0) = +Inf (pole error)
- EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(neg_zero));
-
- // lgammabf16(+Inf) = +Inf
- EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(inf));
-
- // lgammabf16(-Inf) = +Inf
- EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(neg_inf));
-
- // lgamma(1.0) = 0.0
- EXPECT_FP_EQ(zero, LIBC_NAMESPACE::lgammabf16(
- LIBC_NAMESPACE::fputil::cast<bfloat16>(1.0f)));
-
- // lgamma(2.0) = 0.0
- EXPECT_FP_EQ(zero, LIBC_NAMESPACE::lgammabf16(
- LIBC_NAMESPACE::fputil::cast<bfloat16>(2.0f)));
-
- // lgamma(negative integer) = +Inf (pole error)
- EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(
- LIBC_NAMESPACE::fputil::cast<bfloat16>(-1.0f)));
-
- EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(
- LIBC_NAMESPACE::fputil::cast<bfloat16>(-2.0f)));
- }
-};
-
-TEST_F(LlvmLibcLgammaBf16Test, SpecialNumbers) { test_special_numbers(); }
+using LlvmLibcLgammaBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+
+TEST_F(LlvmLibcLgammaBf16Test, SpecialNumbers) {
+ // lgammabf16(NaN) = NaN
+ EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::lgammabf16(aNaN));
+ // lgammabf16(+0) = +Inf (pole error)
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(zero));
+ // lgammabf16(-0) = +Inf (pole error)
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(neg_zero));
+ // lgammabf16(+Inf) = +Inf
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(inf));
+ // lgammabf16(-Inf) = +Inf
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(neg_inf));
+ // lgammabf16(1.0) = 0.0
+ EXPECT_FP_EQ(zero, LIBC_NAMESPACE::lgammabf16(bfloat16(1.0f)));
+ // lgammabf16(2.0) = 0.0
+ EXPECT_FP_EQ(zero, LIBC_NAMESPACE::lgammabf16(bfloat16(2.0f)));
+ // lgammabf16(negative integer) = +Inf (pole error)
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(bfloat16(-1.0f)));
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::lgammabf16(bfloat16(-2.0f)));
+}
More information about the libc-commits
mailing list