[libc-commits] [libc] [libc][math] Update BFloat16 basic operation exhaustive tests to include mixed signs. (PR #182131)

via libc-commits libc-commits at lists.llvm.org
Wed Feb 18 12:47:13 PST 2026


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/182131

https://github.com/llvm/llvm-project/issues/181121

>From 74c33235fd451065b60ea32f515386be88c038f3 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Wed, 18 Feb 2026 20:43:40 +0000
Subject: [PATCH] [libc][math] Update BFloat16 basic operation exhaustive tests
 to include mixed signs.

---
 libc/test/src/math/exhaustive/bfloat16_add_test.cpp | 10 +++++++++-
 libc/test/src/math/exhaustive/bfloat16_div_test.cpp | 10 +++++++++-
 libc/test/src/math/exhaustive/bfloat16_mul_test.cpp | 10 +++++++++-
 libc/test/src/math/exhaustive/bfloat16_sub_test.cpp | 10 +++++++++-
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/libc/test/src/math/exhaustive/bfloat16_add_test.cpp b/libc/test/src/math/exhaustive/bfloat16_add_test.cpp
index 3f4c77978a93d..c523badeb7e8a 100644
--- a/libc/test/src/math/exhaustive/bfloat16_add_test.cpp
+++ b/libc/test/src/math/exhaustive/bfloat16_add_test.cpp
@@ -32,7 +32,7 @@ struct Bfloat16AddChecker : public virtual LIBC_NAMESPACE::testing::Test {
     uint64_t failed = 0;
     do {
       BFloat16 x = FPBits(xbits).get_val();
-      uint16_t ybits = xbits;
+      uint16_t ybits = y_start;
       do {
         BFloat16 y = FPBits(ybits).get_val();
         mpfr::BinaryInput<BFloat16> input{x, y};
@@ -63,3 +63,11 @@ TEST_F(LlvmLibcBfloat16ExhaustiveAddTest, PositiveRange) {
 TEST_F(LlvmLibcBfloat16ExhaustiveAddTest, NegativeRange) {
   test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP);
 }
+
+TEST_F(LlvmLibcBfloat16ExhaustiveAddTest, PositiveNegative) {
+  test_full_range_all_roundings(POS_START, POS_STOP, NEG_START, NEG_STOP);
+}
+
+TEST_F(LlvmLibcBfloat16ExhaustiveAddTest, NegativePositive) {
+  test_full_range_all_roundings(NEG_START, NEG_STOP, POS_START, POS_STOP);
+}
diff --git a/libc/test/src/math/exhaustive/bfloat16_div_test.cpp b/libc/test/src/math/exhaustive/bfloat16_div_test.cpp
index 2648d5f775af5..fa614db206f96 100644
--- a/libc/test/src/math/exhaustive/bfloat16_div_test.cpp
+++ b/libc/test/src/math/exhaustive/bfloat16_div_test.cpp
@@ -32,7 +32,7 @@ struct Bfloat16DivChecker : public virtual LIBC_NAMESPACE::testing::Test {
     uint64_t failed = 0;
     do {
       BFloat16 x = FPBits(xbits).get_val();
-      uint16_t ybits = xbits;
+      uint16_t ybits = y_start;
       do {
         BFloat16 y = FPBits(ybits).get_val();
         mpfr::BinaryInput<BFloat16> input{x, y};
@@ -63,3 +63,11 @@ TEST_F(LlvmLibcBfloat16ExhaustiveDivTest, PositiveRange) {
 TEST_F(LlvmLibcBfloat16ExhaustiveDivTest, NegativeRange) {
   test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP);
 }
+
+TEST_F(LlvmLibcBfloat16ExhaustiveDivTest, PositiveNegative) {
+  test_full_range_all_roundings(POS_START, POS_STOP, NEG_START, NEG_STOP);
+}
+
+TEST_F(LlvmLibcBfloat16ExhaustiveDivTest, NegativePositive) {
+  test_full_range_all_roundings(NEG_START, NEG_STOP, POS_START, POS_STOP);
+}
diff --git a/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp b/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp
index 3cbbcb500a4fb..d827401f4ce76 100644
--- a/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp
+++ b/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp
@@ -32,7 +32,7 @@ struct Bfloat16MulChecker : public virtual LIBC_NAMESPACE::testing::Test {
     uint64_t failed = 0;
     do {
       BFloat16 x = FPBits(xbits).get_val();
-      uint16_t ybits = xbits;
+      uint16_t ybits = y_start;
       do {
         BFloat16 y = FPBits(ybits).get_val();
         mpfr::BinaryInput<BFloat16> input{x, y};
@@ -63,3 +63,11 @@ TEST_F(LlvmLibcBfloat16ExhaustiveMulTest, PositiveRange) {
 TEST_F(LlvmLibcBfloat16ExhaustiveMulTest, NegativeRange) {
   test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP);
 }
+
+TEST_F(LlvmLibcBfloat16ExhaustiveMulTest, PositiveNegative) {
+  test_full_range_all_roundings(POS_START, POS_STOP, NEG_START, NEG_STOP);
+}
+
+TEST_F(LlvmLibcBfloat16ExhaustiveMulTest, NegativePositive) {
+  test_full_range_all_roundings(NEG_START, NEG_STOP, POS_START, POS_STOP);
+}
diff --git a/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp b/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp
index 11bc6f59dd294..2109ee957abbe 100644
--- a/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp
+++ b/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp
@@ -32,7 +32,7 @@ struct Bfloat16SubChecker : public virtual LIBC_NAMESPACE::testing::Test {
     uint64_t failed = 0;
     do {
       BFloat16 x = FPBits(xbits).get_val();
-      uint16_t ybits = xbits;
+      uint16_t ybits = y_start;
       do {
         BFloat16 y = FPBits(ybits).get_val();
         mpfr::BinaryInput<BFloat16> input{x, y};
@@ -63,3 +63,11 @@ TEST_F(LlvmLibcBfloat16ExhaustiveSubTest, PositiveRange) {
 TEST_F(LlvmLibcBfloat16ExhaustiveSubTest, NegativeRange) {
   test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP);
 }
+
+TEST_F(LlvmLibcBfloat16ExhaustiveSubTest, PositiveNegative) {
+  test_full_range_all_roundings(POS_START, POS_STOP, NEG_START, NEG_STOP);
+}
+
+TEST_F(LlvmLibcBfloat16ExhaustiveSubTest, NegativePositive) {
+  test_full_range_all_roundings(NEG_START, NEG_STOP, POS_START, POS_STOP);
+}



More information about the libc-commits mailing list