[libc-commits] [libc] [libc][math][c++23] Add hypotbf16 function (PR #183460)
via libc-commits
libc-commits at lists.llvm.org
Wed Feb 25 22:53:59 PST 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- libc/src/math/generic/hypotbf16.cpp libc/src/math/hypotbf16.h libc/test/src/math/exhaustive/hypotbf16_test.cpp libc/test/src/math/hypotbf16_test.cpp libc/test/src/math/smoke/hypotbf16_test.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index 52c9d88f6..6852d6fa7 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//
+#include "src/math/hypotbf16.h"
#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 {
@@ -18,5 +18,4 @@ LLVM_LIBC_FUNCTION(bfloat16, hypotbf16, (bfloat16 x, bfloat16 y)) {
return fputil::hypot<bfloat16>(x, y);
}
-
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
index 4001d20f5..4001c0a35 100644
--- a/libc/test/src/math/exhaustive/hypotbf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -32,30 +32,30 @@ static constexpr uint16_t SUBNORM_POS_STOP = 0x007FU;
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++) {
+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};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ 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++) {
+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};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
@@ -66,10 +66,10 @@ TEST_F(LlvmLibcHypotBf16Test, SubnormalNegativeRange) {
bfloat16 x = FPBits(v1).get_val();
bfloat16 y = FPBits(v2).get_val();
- mpfr::BinaryInput<bfloat16> input{x, y};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
@@ -80,10 +80,10 @@ TEST_F(LlvmLibcHypotBf16Test, SubnormalPositiveRange) {
bfloat16 x = FPBits(v1).get_val();
bfloat16 y = FPBits(v2).get_val();
- mpfr::BinaryInput<bfloat16> input{x, y};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
@@ -94,10 +94,10 @@ TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
for (size_t j = i; j < 6; ++j) {
bfloat16 x = VALUES[i];
bfloat16 y = VALUES[j];
- mpfr::BinaryInput<bfloat16> input{x, y};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
diff --git a/libc/test/src/math/smoke/hypotbf16_test.cpp b/libc/test/src/math/smoke/hypotbf16_test.cpp
index a0935a58d..679ad9bd4 100644
--- a/libc/test/src/math/smoke/hypotbf16_test.cpp
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -30,4 +30,3 @@ TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
}
}
}
-
``````````
</details>
https://github.com/llvm/llvm-project/pull/183460
More information about the libc-commits
mailing list