[libc-commits] [libc] [llvm] [libc] Add missing MPFR-based tests for math functions (PR #218281)

via libc-commits libc-commits at lists.llvm.org
Sun Aug 30 01:52:37 PDT 2026


https://github.com/tht2005 updated https://github.com/llvm/llvm-project/pull/218281

>From 7425994a5e8d60b65a2f33089473b31646ca8cf7 Mon Sep 17 00:00:00 2001
From: Nguyen Dinh Dang Duong <dangduong31205 at gmail.com>
Date: Mon, 24 Aug 2026 00:10:26 +0700
Subject: [PATCH 1/5] [libc] Add missing MPFR-based tests for math functions

BFloat16:
- ceilbf16
- floorbf16
- truncbf16
- roundbf16
- roundevenbf16
- fabsbf16
- frexpbf16
- remquobf16

Float16:
- fabsf16
- frexpf16
- remquof16
---
 libc/test/src/math/CMakeLists.txt             | 169 ++++++++++++++++++
 libc/test/src/math/CeilTest.h                 |   4 +-
 libc/test/src/math/FloorTest.h                |   4 +-
 libc/test/src/math/TruncTest.h                |   4 +-
 libc/test/src/math/ceilbf16_test.cpp          |  14 ++
 libc/test/src/math/fabsbf16_test.cpp          |  14 ++
 libc/test/src/math/fabsf16_test.cpp           |  13 ++
 libc/test/src/math/floorbf16_test.cpp         |  14 ++
 libc/test/src/math/frexpbf16_test.cpp         |  14 ++
 libc/test/src/math/frexpf16_test.cpp          |  13 ++
 libc/test/src/math/remquobf16_test.cpp        |  14 ++
 libc/test/src/math/remquof16_test.cpp         |  13 ++
 libc/test/src/math/roundbf16_test.cpp         |  14 ++
 libc/test/src/math/roundevenbf16_test.cpp     |  14 ++
 libc/test/src/math/truncbf16_test.cpp         |  14 ++
 libc/utils/MPFRWrapper/MPFRUtils.cpp          |  28 +++
 .../libc/test/src/math/BUILD.bazel            |  63 +++++++
 17 files changed, 417 insertions(+), 6 deletions(-)
 create mode 100644 libc/test/src/math/ceilbf16_test.cpp
 create mode 100644 libc/test/src/math/fabsbf16_test.cpp
 create mode 100644 libc/test/src/math/fabsf16_test.cpp
 create mode 100644 libc/test/src/math/floorbf16_test.cpp
 create mode 100644 libc/test/src/math/frexpbf16_test.cpp
 create mode 100644 libc/test/src/math/frexpf16_test.cpp
 create mode 100644 libc/test/src/math/remquobf16_test.cpp
 create mode 100644 libc/test/src/math/remquof16_test.cpp
 create mode 100644 libc/test/src/math/roundbf16_test.cpp
 create mode 100644 libc/test/src/math/roundevenbf16_test.cpp
 create mode 100644 libc/test/src/math/truncbf16_test.cpp

diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 0b31146d2b821..aa4bbe247f178 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -318,6 +318,35 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  fabsf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    fabsf16_test.cpp
+  HDRS
+    FAbsTest.h
+  DEPENDS
+    libc.src.math.fabsf16
+    libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+  fabsbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    fabsbf16_test.cpp
+  HDRS
+    FAbsTest.h
+  DEPENDS
+    libc.src.math.fabsbf16
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   fabsl_test
   NEED_MPFR
@@ -435,6 +464,22 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  truncbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    truncbf16_test.cpp
+  HDRS
+    TruncTest.h
+  DEPENDS
+    libc.src.math.truncbf16
+    libc.src.__support.CPP.algorithm
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   ceil_test
   NEED_MPFR
@@ -511,6 +556,22 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  ceilbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    ceilbf16_test.cpp
+  HDRS
+    CeilTest.h
+  DEPENDS
+    libc.src.math.ceilbf16
+    libc.src.__support.CPP.algorithm
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   floor_test
   NEED_MPFR
@@ -587,6 +648,22 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  floorbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    floorbf16_test.cpp
+  HDRS
+    FloorTest.h
+  DEPENDS
+    libc.src.math.floorbf16
+    libc.src.__support.CPP.algorithm
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   round_test
   NEED_MPFR
@@ -647,6 +724,22 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  roundbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    roundbf16_test.cpp
+  HDRS
+    RoundTest.h
+  DEPENDS
+    libc.src.math.roundbf16
+    libc.src.__support.CPP.algorithm
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   roundf128_test
   NEED_MPFR_F128
@@ -722,6 +815,22 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  roundevenbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    roundevenbf16_test.cpp
+  HDRS
+    RoundEvenTest.h
+  DEPENDS
+    libc.src.math.roundevenbf16
+    libc.src.__support.CPP.algorithm
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   lround_test
   NEED_MPFR
@@ -1478,6 +1587,35 @@ add_fp_unittest(
     libc.src.__support.FPUtil.basic_operations
 )
 
+add_fp_unittest(
+  frexpf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    frexpf16_test.cpp
+  HDRS
+    FrexpTest.h
+  DEPENDS
+    libc.src.math.frexpf16
+    libc.src.__support.FPUtil.basic_operations
+)
+
+add_fp_unittest(
+  frexpbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    frexpbf16_test.cpp
+  HDRS
+    FrexpTest.h
+  DEPENDS
+    libc.src.math.frexpbf16
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.bfloat16
+)
+
 add_fp_unittest(
   frexpl_test
   NEED_MPFR
@@ -1941,6 +2079,37 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  remquof16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    remquof16_test.cpp
+  HDRS
+    RemQuoTest.h
+  DEPENDS
+    libc.src.math.remquof16
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+  remquobf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    remquobf16_test.cpp
+  HDRS
+    RemQuoTest.h
+  DEPENDS
+    libc.src.math.remquobf16
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   remquo_test
   NEED_MPFR
diff --git a/libc/test/src/math/CeilTest.h b/libc/test/src/math/CeilTest.h
index d30bd200b02ba..29b2e96c3f6ad 100644
--- a/libc/test/src/math/CeilTest.h
+++ b/libc/test/src/math/CeilTest.h
@@ -65,8 +65,8 @@ class CeilTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
     EXPECT_FP_EQ(T(124.0), func(T(123.38)));
     EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
-    EXPECT_FP_EQ(T(124.0), func(T(123.96)));
-    EXPECT_FP_EQ(T(-123.0), func(T(-123.96)));
+    EXPECT_FP_EQ(T(124.0), func(T(123.5)));
+    EXPECT_FP_EQ(T(-123.0), func(T(-123.5)));
   }
 
   void testRange(CeilFunc func) {
diff --git a/libc/test/src/math/FloorTest.h b/libc/test/src/math/FloorTest.h
index 0ac31c0306cfa..bbf34164186aa 100644
--- a/libc/test/src/math/FloorTest.h
+++ b/libc/test/src/math/FloorTest.h
@@ -65,8 +65,8 @@ class FloorTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
     EXPECT_FP_EQ(T(123.0), func(T(123.38)));
     EXPECT_FP_EQ(T(-124.0), func(T(-123.38)));
-    EXPECT_FP_EQ(T(123.0), func(T(123.96)));
-    EXPECT_FP_EQ(T(-124.0), func(T(-123.96)));
+    EXPECT_FP_EQ(T(123.0), func(T(123.5)));
+    EXPECT_FP_EQ(T(-124.0), func(T(-123.5)));
   }
 
   void testRange(FloorFunc func) {
diff --git a/libc/test/src/math/TruncTest.h b/libc/test/src/math/TruncTest.h
index db0f19c83265f..179243e576865 100644
--- a/libc/test/src/math/TruncTest.h
+++ b/libc/test/src/math/TruncTest.h
@@ -65,8 +65,8 @@ class TruncTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
     EXPECT_FP_EQ(T(123.0), func(T(123.38)));
     EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
-    EXPECT_FP_EQ(T(123.0), func(T(123.96)));
-    EXPECT_FP_EQ(T(-123.0), func(T(-123.96)));
+    EXPECT_FP_EQ(T(123.0), func(T(123.5)));
+    EXPECT_FP_EQ(T(-123.0), func(T(-123.5)));
   }
 
   void testRange(TruncFunc func) {
diff --git a/libc/test/src/math/ceilbf16_test.cpp b/libc/test/src/math/ceilbf16_test.cpp
new file mode 100644
index 0000000000000..dcaf058344ff0
--- /dev/null
+++ b/libc/test/src/math/ceilbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for ceilbf16 --------------------------------------------===//
+//
+// 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 "CeilTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/ceilbf16.h"
+
+LIST_CEIL_TESTS(bfloat16, LIBC_NAMESPACE::ceilbf16)
diff --git a/libc/test/src/math/fabsbf16_test.cpp b/libc/test/src/math/fabsbf16_test.cpp
new file mode 100644
index 0000000000000..611050a7775ab
--- /dev/null
+++ b/libc/test/src/math/fabsbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for fabsbf16 --------------------------------------------===//
+//
+// 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 "FAbsTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/fabsbf16.h"
+
+LIST_FABS_TESTS(bfloat16, LIBC_NAMESPACE::fabsbf16)
diff --git a/libc/test/src/math/fabsf16_test.cpp b/libc/test/src/math/fabsf16_test.cpp
new file mode 100644
index 0000000000000..c43bd5090f90b
--- /dev/null
+++ b/libc/test/src/math/fabsf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fabsf16 ---------------------------------------------===//
+//
+// 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 "FAbsTest.h"
+
+#include "src/math/fabsf16.h"
+
+LIST_FABS_TESTS(float16, LIBC_NAMESPACE::fabsf16)
diff --git a/libc/test/src/math/floorbf16_test.cpp b/libc/test/src/math/floorbf16_test.cpp
new file mode 100644
index 0000000000000..9cc77cd15aa1c
--- /dev/null
+++ b/libc/test/src/math/floorbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for floorbf16 -------------------------------------------===//
+//
+// 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 "FloorTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/floorbf16.h"
+
+LIST_FLOOR_TESTS(bfloat16, LIBC_NAMESPACE::floorbf16)
diff --git a/libc/test/src/math/frexpbf16_test.cpp b/libc/test/src/math/frexpbf16_test.cpp
new file mode 100644
index 0000000000000..70c9b63db3a15
--- /dev/null
+++ b/libc/test/src/math/frexpbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for frexpbf16 -------------------------------------------===//
+//
+// 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 "FrexpTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/frexpbf16.h"
+
+LIST_FREXP_TESTS(bfloat16, LIBC_NAMESPACE::frexpbf16)
diff --git a/libc/test/src/math/frexpf16_test.cpp b/libc/test/src/math/frexpf16_test.cpp
new file mode 100644
index 0000000000000..b039d28fe5e92
--- /dev/null
+++ b/libc/test/src/math/frexpf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for frexpf16 --------------------------------------------===//
+//
+// 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 "FrexpTest.h"
+
+#include "src/math/frexpf16.h"
+
+LIST_FREXP_TESTS(float16, LIBC_NAMESPACE::frexpf16)
diff --git a/libc/test/src/math/remquobf16_test.cpp b/libc/test/src/math/remquobf16_test.cpp
new file mode 100644
index 0000000000000..3f754bbd28a41
--- /dev/null
+++ b/libc/test/src/math/remquobf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for remquobf16 ------------------------------------------===//
+//
+// 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 "RemQuoTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/remquobf16.h"
+
+LIST_REMQUO_TESTS(bfloat16, LIBC_NAMESPACE::remquobf16)
diff --git a/libc/test/src/math/remquof16_test.cpp b/libc/test/src/math/remquof16_test.cpp
new file mode 100644
index 0000000000000..18f2aba71aabe
--- /dev/null
+++ b/libc/test/src/math/remquof16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for remquof16 -------------------------------------------===//
+//
+// 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 "RemQuoTest.h"
+
+#include "src/math/remquof16.h"
+
+LIST_REMQUO_TESTS(float16, LIBC_NAMESPACE::remquof16)
diff --git a/libc/test/src/math/roundbf16_test.cpp b/libc/test/src/math/roundbf16_test.cpp
new file mode 100644
index 0000000000000..51638689e8092
--- /dev/null
+++ b/libc/test/src/math/roundbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for roundbf16 -------------------------------------------===//
+//
+// 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 "RoundTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/roundbf16.h"
+
+LIST_ROUND_TESTS(bfloat16, LIBC_NAMESPACE::roundbf16)
diff --git a/libc/test/src/math/roundevenbf16_test.cpp b/libc/test/src/math/roundevenbf16_test.cpp
new file mode 100644
index 0000000000000..711c37a4e5115
--- /dev/null
+++ b/libc/test/src/math/roundevenbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for roundevenbf16 ---------------------------------------===//
+//
+// 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 "RoundEvenTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/roundevenbf16.h"
+
+LIST_ROUNDEVEN_TESTS(bfloat16, LIBC_NAMESPACE::roundevenbf16)
diff --git a/libc/test/src/math/truncbf16_test.cpp b/libc/test/src/math/truncbf16_test.cpp
new file mode 100644
index 0000000000000..970fa69b3c7a1
--- /dev/null
+++ b/libc/test/src/math/truncbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for truncbf16 -------------------------------------------===//
+//
+// 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 "TruncTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/truncbf16.h"
+
+LIST_TRUNC_TESTS(bfloat16, LIBC_NAMESPACE::truncbf16)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index bc32b11466e5a..83500cb59de9d 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -332,6 +332,12 @@ template void explain_unary_operation_two_outputs_error<double>(
 template void explain_unary_operation_two_outputs_error<long double>(
     Operation, long double, const BinaryOutput<long double> &, double,
     RoundingMode);
+#ifdef LIBC_TYPES_HAS_FLOAT16
+template void explain_unary_operation_two_outputs_error<float16>(
+    Operation, float16, const BinaryOutput<float16> &, double, RoundingMode);
+#endif
+template void explain_unary_operation_two_outputs_error<bfloat16>(
+    Operation, bfloat16, const BinaryOutput<bfloat16> &, double, RoundingMode);
 
 template <typename T>
 void explain_binary_operation_two_outputs_error(
@@ -368,6 +374,14 @@ template void explain_binary_operation_two_outputs_error<double>(
 template void explain_binary_operation_two_outputs_error<long double>(
     Operation, const BinaryInput<long double> &,
     const BinaryOutput<long double> &, double, RoundingMode);
+#ifdef LIBC_TYPES_HAS_FLOAT16
+template void explain_binary_operation_two_outputs_error<float16>(
+    Operation, const BinaryInput<float16> &, const BinaryOutput<float16> &,
+    double, RoundingMode);
+#endif
+template void explain_binary_operation_two_outputs_error<bfloat16>(
+    Operation, const BinaryInput<bfloat16> &, const BinaryOutput<bfloat16> &,
+    double, RoundingMode);
 
 template <typename InputType, typename OutputType>
 void explain_binary_operation_one_output_error(
@@ -605,6 +619,12 @@ template bool compare_unary_operation_two_outputs<double>(
 template bool compare_unary_operation_two_outputs<long double>(
     Operation, long double, const BinaryOutput<long double> &, double,
     RoundingMode);
+#ifdef LIBC_TYPES_HAS_FLOAT16
+template bool compare_unary_operation_two_outputs<float16>(
+    Operation, float16, const BinaryOutput<float16> &, double, RoundingMode);
+#endif
+template bool compare_unary_operation_two_outputs<bfloat16>(
+    Operation, bfloat16, const BinaryOutput<bfloat16> &, double, RoundingMode);
 
 template <typename T>
 bool compare_binary_operation_two_outputs(Operation op,
@@ -639,6 +659,14 @@ template bool compare_binary_operation_two_outputs<double>(
 template bool compare_binary_operation_two_outputs<long double>(
     Operation, const BinaryInput<long double> &,
     const BinaryOutput<long double> &, double, RoundingMode);
+#ifdef LIBC_TYPES_HAS_FLOAT16
+template bool compare_binary_operation_two_outputs<float16>(
+    Operation, const BinaryInput<float16> &, const BinaryOutput<float16> &,
+    double, RoundingMode);
+#endif
+template bool compare_binary_operation_two_outputs<bfloat16>(
+    Operation, const BinaryInput<bfloat16> &, const BinaryOutput<bfloat16> &,
+    double, RoundingMode);
 
 template <typename InputType, typename OutputType>
 bool compare_binary_operation_one_output(Operation op,
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
index 601db61b6a6fc..d8914aa3b8ec7 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
@@ -59,6 +59,12 @@ math_mpfr_test(
     hdrs = ["CeilTest.h"],
 )
 
+math_mpfr_test(
+    name = "ceilbf16",
+    hdrs = ["CeilTest.h"],
+    deps = ["//libc:__support_fputil_bfloat16"],
+)
+
 math_mpfr_test(
     name = "ceilf128",
     hdrs = ["CeilTest.h"],
@@ -149,6 +155,17 @@ math_mpfr_test(
     hdrs = ["FAbsTest.h"],
 )
 
+math_mpfr_test(
+    name = "fabsf16",
+    hdrs = ["FAbsTest.h"],
+)
+
+math_mpfr_test(
+    name = "fabsbf16",
+    hdrs = ["FAbsTest.h"],
+    deps = ["//libc:__support_fputil_bfloat16"],
+)
+
 math_mpfr_test(
     name = "fabsl",
     hdrs = ["FAbsTest.h"],
@@ -226,6 +243,12 @@ math_mpfr_test(
     hdrs = ["FloorTest.h"],
 )
 
+math_mpfr_test(
+    name = "floorbf16",
+    hdrs = ["FloorTest.h"],
+    deps = ["//libc:__support_fputil_bfloat16"],
+)
+
 # TODO: Add fma, fmaf, fmal, fmul, fmull tests.  Missing stdlib/rand dependency.
 
 # math_mpfr_test(name = "f16mul")
@@ -246,6 +269,17 @@ math_mpfr_test(
     hdrs = ["FrexpTest.h"],
 )
 
+math_mpfr_test(
+    name = "frexpf16",
+    hdrs = ["FrexpTest.h"],
+)
+
+math_mpfr_test(
+    name = "frexpbf16",
+    hdrs = ["FrexpTest.h"],
+    deps = ["//libc:__support_fputil_bfloat16"],
+)
+
 math_mpfr_test(
     name = "frexpl",
     hdrs = ["FrexpTest.h"],
@@ -450,6 +484,17 @@ math_mpfr_test(
     hdrs = ["RemQuoTest.h"],
 )
 
+math_mpfr_test(
+    name = "remquof16",
+    hdrs = ["RemQuoTest.h"],
+)
+
+math_mpfr_test(
+    name = "remquobf16",
+    hdrs = ["RemQuoTest.h"],
+    deps = ["//libc:__support_fputil_bfloat16"],
+)
+
 math_mpfr_test(
     name = "remquol",
     hdrs = ["RemQuoTest.h"],
@@ -495,6 +540,12 @@ math_mpfr_test(
     hdrs = ["RoundEvenTest.h"],
 )
 
+math_mpfr_test(
+    name = "roundevenbf16",
+    hdrs = ["RoundEvenTest.h"],
+    deps = ["//libc:__support_fputil_bfloat16"],
+)
+
 math_mpfr_test(
     name = "round",
     hdrs = ["RoundTest.h"],
@@ -505,6 +556,12 @@ math_mpfr_test(
     hdrs = ["RoundTest.h"],
 )
 
+math_mpfr_test(
+    name = "roundbf16",
+    hdrs = ["RoundTest.h"],
+    deps = ["//libc:__support_fputil_bfloat16"],
+)
+
 math_mpfr_test(
     name = "roundl",
     hdrs = ["RoundTest.h"],
@@ -635,6 +692,12 @@ math_mpfr_test(
     hdrs = ["TruncTest.h"],
 )
 
+math_mpfr_test(
+    name = "truncbf16",
+    hdrs = ["TruncTest.h"],
+    deps = ["//libc:__support_fputil_bfloat16"],
+)
+
 math_mpfr_test(name = "cbrtf16")
 
 math_mpfr_test(name = "cosf16")

>From 997f83009d9b9f044f3a474424a1b43bba4e7c39 Mon Sep 17 00:00:00 2001
From: Nguyen Dinh Dang Duong <dangduong31205 at gmail.com>
Date: Sat, 29 Aug 2026 14:21:28 +0700
Subject: [PATCH 2/5] Remove non-mpfr tests for Ceil, Floor, Trunc test

---
 libc/test/src/math/CeilTest.h  | 45 ----------------------------------
 libc/test/src/math/FloorTest.h | 45 ----------------------------------
 libc/test/src/math/TruncTest.h | 45 ----------------------------------
 3 files changed, 135 deletions(-)

diff --git a/libc/test/src/math/CeilTest.h b/libc/test/src/math/CeilTest.h
index 29b2e96c3f6ad..3856695d9f732 100644
--- a/libc/test/src/math/CeilTest.h
+++ b/libc/test/src/math/CeilTest.h
@@ -27,48 +27,6 @@ class CeilTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 public:
   typedef T (*CeilFunc)(T);
 
-  void testSpecialNumbers(CeilFunc func) {
-    EXPECT_FP_EQ(zero, func(zero));
-    EXPECT_FP_EQ(neg_zero, func(neg_zero));
-
-    EXPECT_FP_EQ(inf, func(inf));
-    EXPECT_FP_EQ(neg_inf, func(neg_inf));
-
-    EXPECT_FP_EQ(aNaN, func(aNaN));
-  }
-
-  void testRoundedNumbers(CeilFunc func) {
-    EXPECT_FP_EQ(T(1.0), func(T(1.0)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.0)));
-    EXPECT_FP_EQ(T(10.0), func(T(10.0)));
-    EXPECT_FP_EQ(T(-10.0), func(T(-10.0)));
-    EXPECT_FP_EQ(T(1234.0), func(T(1234.0)));
-    EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0)));
-  }
-
-  void testFractions(CeilFunc func) {
-    EXPECT_FP_EQ(T(1.0), func(T(0.5)));
-    EXPECT_FP_EQ(T(-0.0), func(T(-0.5)));
-    EXPECT_FP_EQ(T(1.0), func(T(0.115)));
-    EXPECT_FP_EQ(T(-0.0), func(T(-0.115)));
-    EXPECT_FP_EQ(T(1.0), func(T(0.715)));
-    EXPECT_FP_EQ(T(-0.0), func(T(-0.715)));
-    EXPECT_FP_EQ(T(2.0), func(T(1.3)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.3)));
-    EXPECT_FP_EQ(T(2.0), func(T(1.5)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.5)));
-    EXPECT_FP_EQ(T(2.0), func(T(1.75)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.75)));
-    EXPECT_FP_EQ(T(11.0), func(T(10.32)));
-    EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
-    EXPECT_FP_EQ(T(11.0), func(T(10.65)));
-    EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
-    EXPECT_FP_EQ(T(124.0), func(T(123.38)));
-    EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
-    EXPECT_FP_EQ(T(124.0), func(T(123.5)));
-    EXPECT_FP_EQ(T(-123.0), func(T(-123.5)));
-  }
-
   void testRange(CeilFunc func) {
     constexpr int COUNT = 1'231;
     constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
@@ -87,9 +45,6 @@ class CeilTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
 #define LIST_CEIL_TESTS(T, func)                                               \
   using LlvmLibcCeilTest = CeilTest<T>;                                        \
-  TEST_F(LlvmLibcCeilTest, SpecialNumbers) { testSpecialNumbers(&func); }      \
-  TEST_F(LlvmLibcCeilTest, RoundedNubmers) { testRoundedNumbers(&func); }      \
-  TEST_F(LlvmLibcCeilTest, Fractions) { testFractions(&func); }                \
   TEST_F(LlvmLibcCeilTest, Range) { testRange(&func); }
 
 #endif // LLVM_LIBC_TEST_SRC_MATH_CEILTEST_H
diff --git a/libc/test/src/math/FloorTest.h b/libc/test/src/math/FloorTest.h
index bbf34164186aa..28c16f4421fa6 100644
--- a/libc/test/src/math/FloorTest.h
+++ b/libc/test/src/math/FloorTest.h
@@ -27,48 +27,6 @@ class FloorTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 public:
   typedef T (*FloorFunc)(T);
 
-  void testSpecialNumbers(FloorFunc func) {
-    EXPECT_FP_EQ(zero, func(zero));
-    EXPECT_FP_EQ(neg_zero, func(neg_zero));
-
-    EXPECT_FP_EQ(inf, func(inf));
-    EXPECT_FP_EQ(neg_inf, func(neg_inf));
-
-    EXPECT_FP_EQ(aNaN, func(aNaN));
-  }
-
-  void testRoundedNumbers(FloorFunc func) {
-    EXPECT_FP_EQ(T(1.0), func(T(1.0)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.0)));
-    EXPECT_FP_EQ(T(10.0), func(T(10.0)));
-    EXPECT_FP_EQ(T(-10.0), func(T(-10.0)));
-    EXPECT_FP_EQ(T(1234.0), func(T(1234.0)));
-    EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0)));
-  }
-
-  void testFractions(FloorFunc func) {
-    EXPECT_FP_EQ(T(0.0), func(T(0.5)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-0.5)));
-    EXPECT_FP_EQ(T(0.0), func(T(0.115)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-0.115)));
-    EXPECT_FP_EQ(T(0.0), func(T(0.715)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-0.715)));
-    EXPECT_FP_EQ(T(1.0), func(T(1.3)));
-    EXPECT_FP_EQ(T(-2.0), func(T(-1.3)));
-    EXPECT_FP_EQ(T(1.0), func(T(1.5)));
-    EXPECT_FP_EQ(T(-2.0), func(T(-1.5)));
-    EXPECT_FP_EQ(T(1.0), func(T(1.75)));
-    EXPECT_FP_EQ(T(-2.0), func(T(-1.75)));
-    EXPECT_FP_EQ(T(10.0), func(T(10.32)));
-    EXPECT_FP_EQ(T(-11.0), func(T(-10.32)));
-    EXPECT_FP_EQ(T(10.0), func(T(10.65)));
-    EXPECT_FP_EQ(T(-11.0), func(T(-10.65)));
-    EXPECT_FP_EQ(T(123.0), func(T(123.38)));
-    EXPECT_FP_EQ(T(-124.0), func(T(-123.38)));
-    EXPECT_FP_EQ(T(123.0), func(T(123.5)));
-    EXPECT_FP_EQ(T(-124.0), func(T(-123.5)));
-  }
-
   void testRange(FloorFunc func) {
     constexpr int COUNT = 1'231;
     constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
@@ -87,9 +45,6 @@ class FloorTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
 #define LIST_FLOOR_TESTS(T, func)                                              \
   using LlvmLibcFloorTest = FloorTest<T>;                                      \
-  TEST_F(LlvmLibcFloorTest, SpecialNumbers) { testSpecialNumbers(&func); }     \
-  TEST_F(LlvmLibcFloorTest, RoundedNubmers) { testRoundedNumbers(&func); }     \
-  TEST_F(LlvmLibcFloorTest, Fractions) { testFractions(&func); }               \
   TEST_F(LlvmLibcFloorTest, Range) { testRange(&func); }
 
 #endif // LLVM_LIBC_TEST_SRC_MATH_FLOORTEST_H
diff --git a/libc/test/src/math/TruncTest.h b/libc/test/src/math/TruncTest.h
index 179243e576865..2e1c2f64c07db 100644
--- a/libc/test/src/math/TruncTest.h
+++ b/libc/test/src/math/TruncTest.h
@@ -27,48 +27,6 @@ class TruncTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 public:
   typedef T (*TruncFunc)(T);
 
-  void testSpecialNumbers(TruncFunc func) {
-    EXPECT_FP_EQ(zero, func(zero));
-    EXPECT_FP_EQ(neg_zero, func(neg_zero));
-
-    EXPECT_FP_EQ(inf, func(inf));
-    EXPECT_FP_EQ(neg_inf, func(neg_inf));
-
-    EXPECT_FP_EQ(aNaN, func(aNaN));
-  }
-
-  void testRoundedNumbers(TruncFunc func) {
-    EXPECT_FP_EQ(T(1.0), func(T(1.0)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.0)));
-    EXPECT_FP_EQ(T(10.0), func(T(10.0)));
-    EXPECT_FP_EQ(T(-10.0), func(T(-10.0)));
-    EXPECT_FP_EQ(T(1234.0), func(T(1234.0)));
-    EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0)));
-  }
-
-  void testFractions(TruncFunc func) {
-    EXPECT_FP_EQ(T(0.0), func(T(0.5)));
-    EXPECT_FP_EQ(T(-0.0), func(T(-0.5)));
-    EXPECT_FP_EQ(T(0.0), func(T(0.115)));
-    EXPECT_FP_EQ(T(-0.0), func(T(-0.115)));
-    EXPECT_FP_EQ(T(0.0), func(T(0.715)));
-    EXPECT_FP_EQ(T(-0.0), func(T(-0.715)));
-    EXPECT_FP_EQ(T(1.0), func(T(1.3)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.3)));
-    EXPECT_FP_EQ(T(1.0), func(T(1.5)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.5)));
-    EXPECT_FP_EQ(T(1.0), func(T(1.75)));
-    EXPECT_FP_EQ(T(-1.0), func(T(-1.75)));
-    EXPECT_FP_EQ(T(10.0), func(T(10.32)));
-    EXPECT_FP_EQ(T(-10.0), func(T(-10.32)));
-    EXPECT_FP_EQ(T(10.0), func(T(10.65)));
-    EXPECT_FP_EQ(T(-10.0), func(T(-10.65)));
-    EXPECT_FP_EQ(T(123.0), func(T(123.38)));
-    EXPECT_FP_EQ(T(-123.0), func(T(-123.38)));
-    EXPECT_FP_EQ(T(123.0), func(T(123.5)));
-    EXPECT_FP_EQ(T(-123.0), func(T(-123.5)));
-  }
-
   void testRange(TruncFunc func) {
     constexpr int COUNT = 1'231;
     constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
@@ -87,9 +45,6 @@ class TruncTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
 #define LIST_TRUNC_TESTS(T, func)                                              \
   using LlvmLibcTruncTest = TruncTest<T>;                                      \
-  TEST_F(LlvmLibcTruncTest, SpecialNumbers) { testSpecialNumbers(&func); }     \
-  TEST_F(LlvmLibcTruncTest, RoundedNubmers) { testRoundedNumbers(&func); }     \
-  TEST_F(LlvmLibcTruncTest, Fractions) { testFractions(&func); }               \
   TEST_F(LlvmLibcTruncTest, Range) { testRange(&func); }
 
 #endif // LLVM_LIBC_TEST_SRC_MATH_TRUNCTEST_H

>From f2ace185163ff6d4645190c446594ef5cef15ca0 Mon Sep 17 00:00:00 2001
From: Nguyen Dinh Dang Duong <dangduong31205 at gmail.com>
Date: Sat, 29 Aug 2026 14:39:18 +0700
Subject: [PATCH 3/5] Remove libc/test/src/math/generic

---
 libc/test/src/math/CMakeLists.txt         |  1 -
 libc/test/src/math/generic/CMakeLists.txt | 32 -----------------------
 2 files changed, 33 deletions(-)
 delete mode 100644 libc/test/src/math/generic/CMakeLists.txt

diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index aa4bbe247f178..71e8e5b6ead8e 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -3917,7 +3917,6 @@ add_fp_unittest(
     libc.src.__support.FPUtil.bfloat16
 )
 
-add_subdirectory(generic)
 add_subdirectory(smoke)
 
 if(NOT LLVM_LIBC_FULL_BUILD)
diff --git a/libc/test/src/math/generic/CMakeLists.txt b/libc/test/src/math/generic/CMakeLists.txt
deleted file mode 100644
index a9d54d6424294..0000000000000
--- a/libc/test/src/math/generic/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-add_fp_unittest(
-  ceil_test
-  NEED_MPFR
-  SUITE
-    libc-math-unittests
-  SRCS
-    ../ceil_test.cpp
-  DEPENDS
-    libc.src.math.generic.ceil
-)
-
-add_fp_unittest(
-  ceilf_test
-  NEED_MPFR
-  SUITE
-    libc-math-unittests
-  SRCS
-    ../ceilf_test.cpp
-  DEPENDS
-    libc.src.math.generic.ceilf
-)
-
-add_fp_unittest(
-  ceill_test
-  NEED_MPFR
-  SUITE
-    libc-math-unittests
-  SRCS
-    ../ceill_test.cpp
-  DEPENDS
-    libc.src.math.generic.ceill
-)

>From 6d6fc4228132c09d918e820d2e5d07d8f3576f7f Mon Sep 17 00:00:00 2001
From: Nguyen Dinh Dang Duong <dangduong31205 at gmail.com>
Date: Sat, 29 Aug 2026 21:30:23 +0700
Subject: [PATCH 4/5] Add the missing doxygen file headers

---
 libc/test/src/math/ceilbf16_test.cpp      | 5 +++++
 libc/test/src/math/fabsbf16_test.cpp      | 5 +++++
 libc/test/src/math/fabsf16_test.cpp       | 5 +++++
 libc/test/src/math/floorbf16_test.cpp     | 5 +++++
 libc/test/src/math/frexpbf16_test.cpp     | 5 +++++
 libc/test/src/math/frexpf16_test.cpp      | 5 +++++
 libc/test/src/math/remquobf16_test.cpp    | 5 +++++
 libc/test/src/math/remquof16_test.cpp     | 5 +++++
 libc/test/src/math/roundbf16_test.cpp     | 5 +++++
 libc/test/src/math/roundevenbf16_test.cpp | 5 +++++
 libc/test/src/math/truncbf16_test.cpp     | 5 +++++
 11 files changed, 55 insertions(+)

diff --git a/libc/test/src/math/ceilbf16_test.cpp b/libc/test/src/math/ceilbf16_test.cpp
index dcaf058344ff0..3cbd9de0a611e 100644
--- a/libc/test/src/math/ceilbf16_test.cpp
+++ b/libc/test/src/math/ceilbf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for ceilbf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "CeilTest.h"
 
diff --git a/libc/test/src/math/fabsbf16_test.cpp b/libc/test/src/math/fabsbf16_test.cpp
index 611050a7775ab..2ac14763b7c41 100644
--- a/libc/test/src/math/fabsbf16_test.cpp
+++ b/libc/test/src/math/fabsbf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for fabsbf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "FAbsTest.h"
 
diff --git a/libc/test/src/math/fabsf16_test.cpp b/libc/test/src/math/fabsf16_test.cpp
index c43bd5090f90b..cf6b8f5e7a3cd 100644
--- a/libc/test/src/math/fabsf16_test.cpp
+++ b/libc/test/src/math/fabsf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for fabsf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "FAbsTest.h"
 
diff --git a/libc/test/src/math/floorbf16_test.cpp b/libc/test/src/math/floorbf16_test.cpp
index 9cc77cd15aa1c..d11ca17dad74c 100644
--- a/libc/test/src/math/floorbf16_test.cpp
+++ b/libc/test/src/math/floorbf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for floorbf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "FloorTest.h"
 
diff --git a/libc/test/src/math/frexpbf16_test.cpp b/libc/test/src/math/frexpbf16_test.cpp
index 70c9b63db3a15..913e3ac097c4d 100644
--- a/libc/test/src/math/frexpbf16_test.cpp
+++ b/libc/test/src/math/frexpbf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for frexpbf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "FrexpTest.h"
 
diff --git a/libc/test/src/math/frexpf16_test.cpp b/libc/test/src/math/frexpf16_test.cpp
index b039d28fe5e92..6a31033949910 100644
--- a/libc/test/src/math/frexpf16_test.cpp
+++ b/libc/test/src/math/frexpf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for frexpf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "FrexpTest.h"
 
diff --git a/libc/test/src/math/remquobf16_test.cpp b/libc/test/src/math/remquobf16_test.cpp
index 3f754bbd28a41..2c5ad5a7e2770 100644
--- a/libc/test/src/math/remquobf16_test.cpp
+++ b/libc/test/src/math/remquobf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for remquobf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "RemQuoTest.h"
 
diff --git a/libc/test/src/math/remquof16_test.cpp b/libc/test/src/math/remquof16_test.cpp
index 18f2aba71aabe..33b98fa3d38e1 100644
--- a/libc/test/src/math/remquof16_test.cpp
+++ b/libc/test/src/math/remquof16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for remquof16
+///
+//===----------------------------------------------------------------------===//
 
 #include "RemQuoTest.h"
 
diff --git a/libc/test/src/math/roundbf16_test.cpp b/libc/test/src/math/roundbf16_test.cpp
index 51638689e8092..2ee44fdbcc505 100644
--- a/libc/test/src/math/roundbf16_test.cpp
+++ b/libc/test/src/math/roundbf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for roundbf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "RoundTest.h"
 
diff --git a/libc/test/src/math/roundevenbf16_test.cpp b/libc/test/src/math/roundevenbf16_test.cpp
index 711c37a4e5115..ad73ee518fead 100644
--- a/libc/test/src/math/roundevenbf16_test.cpp
+++ b/libc/test/src/math/roundevenbf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for roundevenbf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "RoundEvenTest.h"
 
diff --git a/libc/test/src/math/truncbf16_test.cpp b/libc/test/src/math/truncbf16_test.cpp
index 970fa69b3c7a1..398185208947b 100644
--- a/libc/test/src/math/truncbf16_test.cpp
+++ b/libc/test/src/math/truncbf16_test.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for truncbf16
+///
+//===----------------------------------------------------------------------===//
 
 #include "TruncTest.h"
 

>From 62d9a69a8d3db04bf7fa1d9e1c0328757a083a4a Mon Sep 17 00:00:00 2001
From: Nguyen Dinh Dang Duong <dangduong31205 at gmail.com>
Date: Sun, 30 Aug 2026 15:39:12 +0700
Subject: [PATCH 5/5] Fix bazel test error

---
 libc/test/src/math/CMakeLists.txt | 5 +++++
 libc/test/src/math/RemQuoTest.h   | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 71e8e5b6ead8e..8f1a543de0a5e 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2075,6 +2075,7 @@ add_fp_unittest(
     RemQuoTest.h
   DEPENDS
     libc.src.math.remquof
+    libc.src.__support.CPP.algorithm
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.fp_bits
 )
@@ -2090,6 +2091,7 @@ add_fp_unittest(
     RemQuoTest.h
   DEPENDS
     libc.src.math.remquof16
+    libc.src.__support.CPP.algorithm
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.fp_bits
 )
@@ -2105,6 +2107,7 @@ add_fp_unittest(
     RemQuoTest.h
   DEPENDS
     libc.src.math.remquobf16
+    libc.src.__support.CPP.algorithm
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.bfloat16
     libc.src.__support.FPUtil.fp_bits
@@ -2121,6 +2124,7 @@ add_fp_unittest(
     RemQuoTest.h
   DEPENDS
     libc.src.math.remquo
+    libc.src.__support.CPP.algorithm
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.fp_bits
 )
@@ -2136,6 +2140,7 @@ add_fp_unittest(
     RemQuoTest.h
   DEPENDS
     libc.src.math.remquol
+    libc.src.__support.CPP.algorithm
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.fp_bits
 )
diff --git a/libc/test/src/math/RemQuoTest.h b/libc/test/src/math/RemQuoTest.h
index 40b4ce748fa6b..4e135ce7cc4f6 100644
--- a/libc/test/src/math/RemQuoTest.h
+++ b/libc/test/src/math/RemQuoTest.h
@@ -10,6 +10,7 @@
 #define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
 
 #include "hdr/math_macros.h"
+#include "src/__support/CPP/algorithm.h"
 #include "src/__support/FPUtil/BasicOperations.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "test/UnitTest/FEnvSafeTest.h"
@@ -105,7 +106,9 @@ class RemQuoTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
   void testSubnormalRange(RemQuoFunc func) {
     constexpr StorageType COUNT = 1'231;
-    constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
+    constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+        static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
+        StorageType(1));
     for (StorageType v = MIN_SUBNORMAL, w = MAX_SUBNORMAL;
          v <= MAX_SUBNORMAL && w >= MIN_SUBNORMAL; v += STEP, w -= STEP) {
       T x = FPBits(v).get_val(), y = FPBits(w).get_val();



More information about the libc-commits mailing list