[libc-commits] [libc] [libc][math][c23] Add hypotbf16 function (PR #183460)
via libc-commits
libc-commits at lists.llvm.org
Wed Feb 25 22:52:44 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Zorojuro (Sukumarsawant)
<details>
<summary>Changes</summary>
This PR intends to add hypotbf16 higher math function for BFloat16 type along with the tests.
---
Full diff: https://github.com/llvm/llvm-project/pull/183460.diff
23 Files Affected:
- (modified) libc/config/baremetal/aarch64/entrypoints.txt (+1)
- (modified) libc/config/baremetal/arm/entrypoints.txt (+1)
- (modified) libc/config/baremetal/riscv/entrypoints.txt (+1)
- (modified) libc/config/darwin/aarch64/entrypoints.txt (+1)
- (modified) libc/config/darwin/x86_64/entrypoints.txt (+1)
- (modified) libc/config/gpu/amdgpu/entrypoints.txt (+1)
- (modified) libc/config/gpu/nvptx/entrypoints.txt (+1)
- (modified) libc/config/linux/aarch64/entrypoints.txt (+1)
- (modified) libc/config/linux/arm/entrypoints.txt (+1)
- (modified) libc/config/linux/riscv/entrypoints.txt (+1)
- (modified) libc/config/linux/x86_64/entrypoints.txt (+1)
- (modified) libc/config/windows/entrypoints.txt (+1)
- (modified) libc/docs/headers/math/index.rst (+1-1)
- (modified) libc/src/math/CMakeLists.txt (+1)
- (modified) libc/src/math/generic/CMakeLists.txt (+13)
- (added) libc/src/math/generic/hypotbf16.cpp (+22)
- (added) libc/src/math/hypotbf16.h (+21)
- (modified) libc/test/src/math/CMakeLists.txt (+13)
- (modified) libc/test/src/math/exhaustive/CMakeLists.txt (+19)
- (added) libc/test/src/math/exhaustive/hypotbf16_test.cpp (+103)
- (added) libc/test/src/math/hypotbf16_test.cpp (+22)
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+16)
- (added) libc/test/src/math/smoke/hypotbf16_test.cpp (+33)
``````````diff
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 742d96761c415..a89f9bd65a043 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -447,6 +447,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 95cb0dea8e49e..4470208c6f211 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -450,6 +450,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 3fc71280f5163..b23e8d71bac81 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -448,6 +448,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 3909417f9730d..7f7a22fded002 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -263,6 +263,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index e899bf97ea3f6..3d205b5a10895 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -162,6 +162,7 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.fsub
#libc.src.math.fsubl
#libc.src.math.hypot
+ #libc.src.math.hypotbf16
#libc.src.math.hypotf
#libc.src.math.ilogb
#libc.src.math.ilogbf
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 0dda7d5c683ec..39da9588ea28e 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -390,6 +390,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 6070fb5b17b3c..bfc562ba01c36 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -391,6 +391,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 0d99a2d63d249..b4483c2e67516 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -528,6 +528,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index f04ac40145d3a..7c3c932663de9 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -349,6 +349,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 7baf4de9d8a5b..edede92ed9565 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -537,6 +537,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 6485c24f5736a..04ad792d30512 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -579,6 +579,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 3a76595b258e2..474e970e4678d 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -222,6 +222,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 4b443e3e49ddb..166fe84407a73 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -319,7 +319,7 @@ Higher Math Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fsqrt | N/A | |check| | |check| | N/A | |check|\* | | 7.12.14.6 | F.10.11 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| hypot | |check| | |check| | | |check| | | | 7.12.7.4 | F.10.4.4 |
+| hypot | |check| | |check| | | |check| | | |check| | 7.12.7.4 | F.10.4.4 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| lgamma | | | | | | | 7.12.8.3 | F.10.5.3 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index e37e22fdb58e6..3e9d41e9ed478 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -343,6 +343,7 @@ add_math_entrypoint_object(getpayloadf128)
add_math_entrypoint_object(getpayloadbf16)
add_math_entrypoint_object(hypot)
+add_math_entrypoint_object(hypotbf16)
add_math_entrypoint_object(hypotf)
add_math_entrypoint_object(hypotf16)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index b66382ef09d82..e8ab0ccf3efc8 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3040,6 +3040,19 @@ add_entrypoint_object(
libc.src.__support.macros.config
)
+add_entrypoint_object(
+ hypotbf16
+ SRCS
+ hypotbf16.cpp
+ HDRS
+ ../hypotbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.hypot
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
add_entrypoint_object(
hypotf
SRCS
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
new file mode 100644
index 0000000000000..52c9d88f681cd
--- /dev/null
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of hypotbf16 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/__support/FPUtil/Hypot.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/math/hypotbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, hypotbf16, (bfloat16 x, bfloat16 y)) {
+ return fputil::hypot<bfloat16>(x, y);
+}
+
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/hypotbf16.h b/libc/src/math/hypotbf16.h
new file mode 100644
index 0000000000000..db1365d791dba
--- /dev/null
+++ b/libc/src/math/hypotbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for hypotbf16 ---------------------*- 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_HYPOTBF16_H
+#define LLVM_LIBC_SRC_MATH_HYPOTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 hypotbf16(bfloat16 x, bfloat16 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_HYPOTBF16_H
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 83cf506968b9b..8f95094e36946 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1896,6 +1896,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ hypotbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ hypotbf16_test.cpp
+ DEPENDS
+ libc.src.math.hypotbf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
hypotf16_test
NEED_MPFR
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index 9ca4f93e6c411..037a69de4948f 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -357,6 +357,25 @@ add_fp_unittest(
-lpthread
)
+
+add_fp_unittest(
+ hypotbf16_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ hypotbf16_test.cpp
+ COMPILE_OPTIONS
+ ${libc_opt_high_flag}
+ DEPENDS
+ .exhaustive_test
+ libc.src.math.hypotbf16
+ libc.src.__support.FPUtil.fp_bits
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
hypotf_test
NO_RUN_POSTBUILD
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
new file mode 100644
index 0000000000000..4001d20f5b843
--- /dev/null
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -0,0 +1,103 @@
+//===-- Exhaustive test for hypotbf16 -------------------------------------===//
+//
+// 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/hypotbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcHypotBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// Normal range: [+0, +int]
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7f80U;
+
+// Normal range: [-0, -int]
+static constexpr uint16_t NEG_START = 0x8000U;
+static constexpr uint16_t NEG_STOP = 0xff80U;
+
+// Subnormal range (positive)
+static constexpr uint16_t SUBNORM_POS_START = 0x0001U;
+static constexpr uint16_t SUBNORM_POS_STOP = 0x007FU;
+
+// Subnormal range (negative)
+static constexpr uint16_t SUBNORM_NEG_START = 0x8001U;
+static constexpr uint16_t SUBNORM_NEG_STOP = 0x807FU;
+
+TEST_F(LlvmLibcHypotBf16Test,NormalPositiveRange){
+ for (uint16_t v1 = POS_START; v1 <= POS_STOP; v1++) {
+ for (uint16_t v2 = v1; v2 <= POS_STOP; v2++) {
+
+ bfloat16 x = FPBits(v1).get_val();
+ bfloat16 y = FPBits(v2).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ }
+ }
+}
+
+TEST_F(LlvmLibcHypotBf16Test,NormalNegativeRange){
+ for (uint16_t v1 = NEG_START; v1 <= NEG_STOP; v1++) {
+ for (uint16_t v2 = v1; v2 <= NEG_STOP; v2++) {
+
+ bfloat16 x = FPBits(v1).get_val();
+ bfloat16 y = FPBits(v2).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ }
+ }
+}
+
+TEST_F(LlvmLibcHypotBf16Test, SubnormalNegativeRange) {
+ for (uint16_t v1 = SUBNORM_NEG_START; v1 <= SUBNORM_NEG_STOP; v1++) {
+ for (uint16_t v2 = v1; v2 <= SUBNORM_NEG_STOP; v2++) {
+
+ bfloat16 x = FPBits(v1).get_val();
+ bfloat16 y = FPBits(v2).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ }
+ }
+}
+
+TEST_F(LlvmLibcHypotBf16Test, SubnormalPositiveRange) {
+ for (uint16_t v1 = SUBNORM_POS_START; v1 <= SUBNORM_POS_STOP; v1++) {
+ for (uint16_t v2 = v1; v2 <= SUBNORM_POS_STOP; v2++) {
+
+ bfloat16 x = FPBits(v1).get_val();
+ bfloat16 y = FPBits(v2).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ }
+ }
+}
+TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
+ constexpr bfloat16 VALUES[] = {zero, neg_zero, inf,
+ neg_inf, min_normal, max_normal};
+ for (size_t i = 0; i < 6; ++i) {
+ for (size_t j = i; j < 6; ++j) {
+ bfloat16 x = VALUES[i];
+ bfloat16 y = VALUES[j];
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ }
+ }
+}
diff --git a/libc/test/src/math/hypotbf16_test.cpp b/libc/test/src/math/hypotbf16_test.cpp
new file mode 100644
index 0000000000000..a757ff751ba77
--- /dev/null
+++ b/libc/test/src/math/hypotbf16_test.cpp
@@ -0,0 +1,22 @@
+//===-- Unittests tests for hypotbf16 ------------------------------------===//
+//
+// 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 "HypotTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/hypotbf16.h"
+
+using LlvmLibcHypotbf16Test = HypotTestTemplate<bfloat16>;
+
+TEST_F(LlvmLibcHypotbf16Test, SubnormalRange) {
+ test_subnormal_range(&LIBC_NAMESPACE::hypotbf16);
+}
+
+TEST_F(LlvmLibcHypotbf16Test, NormalRange) {
+ test_normal_range(&LIBC_NAMESPACE::hypotbf16);
+}
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index b58eeda678149..83a4e337c514b 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3743,6 +3743,22 @@ add_fp_unittest(
libc.src.__support.macros.properties.architectures
)
+add_fp_unittest(
+ hypotbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ hypotbf16_test.cpp
+ HDRS
+ HypotTest.h
+ DEPENDS
+ libc.src.math.hypotbf16
+ libc.src.__support.FPUtil.bfloat16
+ libc.test.UnitTest.FPMatcher
+ libc.test.UnitTest.Test
+ libc.utils.MPFRWrapper.MPFRUtils
+)
+
add_fp_unittest(
nanf_test
SUITE
diff --git a/libc/test/src/math/smoke/hypotbf16_test.cpp b/libc/test/src/math/smoke/hypotbf16_test.cpp
new file mode 100644
index 0000000000000..a0935a58d1f38
--- /dev/null
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -0,0 +1,33 @@
+//===-- Unittests for hypotbf16 -------------------------------------------===//
+//
+// 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/hypotbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcHypotBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
+ constexpr bfloat16 VAL[] = {zero, neg_zero, inf,
+ neg_inf, min_normal, max_normal};
+ for (size_t v1 = 0; v1 < 6; ++v1) {
+ for (size_t v2 = v1; v2 < 6; ++v2) {
+
+ bfloat16 x = VAL[v1];
+ bfloat16 y = VAL[v2];
+ mpfr::BinaryInput<bfloat16> input{x, y};
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ }
+ }
+}
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/183460
More information about the libc-commits
mailing list