[libc-commits] [libc] [libc][math][c23] Add log10p1f16 C23 math function (PR #184739)

via libc-commits libc-commits at lists.llvm.org
Wed Mar 4 21:09:10 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Shikhar Soni (shikharish)

<details>
<summary>Changes</summary>

Closes #<!-- -->133202 

---

Patch is 23.81 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/184739.diff


24 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/gpu/amdgpu/entrypoints.txt (+1) 
- (modified) libc/config/gpu/nvptx/entrypoints.txt (+1) 
- (modified) libc/config/linux/riscv/entrypoints.txt (+1) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+1) 
- (modified) libc/docs/headers/math/index.rst (+1-1) 
- (modified) libc/include/math.yaml (+7) 
- (modified) libc/src/__support/math/CMakeLists.txt (+19) 
- (added) libc/src/__support/math/log10p1f16.h (+190) 
- (modified) libc/src/math/CMakeLists.txt (+1) 
- (modified) libc/src/math/generic/CMakeLists.txt (+11) 
- (added) libc/src/math/generic/log10p1f16.cpp (+18) 
- (added) libc/src/math/log10p1f16.h (+21) 
- (modified) libc/test/src/math/CMakeLists.txt (+11) 
- (added) libc/test/src/math/log10p1f16_test.cpp (+49) 
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+13) 
- (added) libc/test/src/math/smoke/log10p1f16_test.cpp (+50) 
- (modified) libc/utils/MPFRWrapper/MPCommon.cpp (+16) 
- (modified) libc/utils/MPFRWrapper/MPCommon.h (+1) 
- (modified) libc/utils/MPFRWrapper/MPFRUtils.cpp (+2) 
- (modified) libc/utils/MPFRWrapper/MPFRUtils.h (+1) 


``````````diff
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 278e1f5afde70..0377458b0bb42 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -648,6 +648,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.llrintf16
     libc.src.math.llroundf16
     libc.src.math.log10f16
+    libc.src.math.log10p1f16
     libc.src.math.log2f16
     libc.src.math.logbf16
     libc.src.math.logf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 7bc92e84b7fa4..87fad2f6b920b 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -651,6 +651,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.llrintf16
     libc.src.math.llroundf16
     libc.src.math.log10f16
+    libc.src.math.log10p1f16
     libc.src.math.log2f16
     libc.src.math.logbf16
     libc.src.math.logf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 29be47dfbfd53..396d308ea9972 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -646,6 +646,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.llrintf16
     libc.src.math.llroundf16
     libc.src.math.log10f16
+    libc.src.math.log10p1f16
     libc.src.math.log2f16
     libc.src.math.logbf16
     libc.src.math.logf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index b4a1ee70764cb..905d746fefbd4 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -462,6 +462,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.llrintf16
     libc.src.math.llroundf16
     libc.src.math.log10f16
+    libc.src.math.log10p1f16
     libc.src.math.log2f16
     libc.src.math.logbf16
     libc.src.math.logf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index a65b6f0274fd8..38419faf2ba7c 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -580,6 +580,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.llrintf16
     libc.src.math.llroundf16
     libc.src.math.log10f16
+    libc.src.math.log10p1f16
     libc.src.math.log2f16
     libc.src.math.logbf16
     libc.src.math.logf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index fee0038c88cc0..481fb02e2f22b 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -582,6 +582,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.llrintf16
     libc.src.math.llroundf16
     libc.src.math.log10f16
+    libc.src.math.log10p1f16
     libc.src.math.log2f16
     libc.src.math.logbf16
     libc.src.math.logf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a69d1a1b0a642..7cf2cf49b63f9 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -737,6 +737,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.llrintf16
     libc.src.math.llroundf16
     libc.src.math.log10f16
+    libc.src.math.log10p1f16
     libc.src.math.log2f16
     libc.src.math.logbf16
     libc.src.math.logf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 4103ee0331a23..901c64d72dca5 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -786,6 +786,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
     libc.src.math.llrintf16
     libc.src.math.llroundf16
     libc.src.math.log10f16
+    libc.src.math.log10p1f16
     libc.src.math.log2f16
     libc.src.math.logbf16
     libc.src.math.logf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 7ea54fb4d8263..2066b8d8d1255 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -327,7 +327,7 @@ Higher Math Functions
 +-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | log10     | |check|          | |check|         |                        | |check|              |                        |                        | 7.12.6.12              | F.10.3.12                  |
 +-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| log10p1   |                  |                 |                        |                      |                        |                        | 7.12.6.13              | F.10.3.13                  |
+| log10p1   |                  |                 |                        | |check|              |                        |                        | 7.12.6.13              | F.10.3.13                  |
 +-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 | log1p     | |check|          | |check|         |                        |                      |                        |                        | 7.12.6.14              | F.10.3.14                  |
 +-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/include/math.yaml b/libc/include/math.yaml
index afd3ae33305c1..3a5c962020bc7 100644
--- a/libc/include/math.yaml
+++ b/libc/include/math.yaml
@@ -1777,6 +1777,13 @@ functions:
     arguments:
       - type: _Float16
     guard: LIBC_TYPES_HAS_FLOAT16
+  - name: log10p1f16
+    standards:
+      - stdc
+    return_type: _Float16
+    arguments:
+      - type: _Float16
+    guard: LIBC_TYPES_HAS_FLOAT16
   - name: log1p
     standards:
       - stdc
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 3bb8e76a54bfb..42cec4f054ffd 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2545,6 +2545,25 @@ add_header_library(
     libc.src.__support.macros.properties.cpu_features
 )
 
+add_header_library(
+  log10p1f16
+  HDRS
+    log10p1f16.h
+  DEPENDS
+    .exp10_float16_constants
+    .expxf16_utils
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.cast
+    libc.src.__support.FPUtil.except_value_utils
+    libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.FPUtil.polyeval
+    libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.cpu_features
+)
+
 add_header_library(
   log10f
   HDRS
diff --git a/libc/src/__support/math/log10p1f16.h b/libc/src/__support/math/log10p1f16.h
new file mode 100644
index 0000000000000..e2b01a504975d
--- /dev/null
+++ b/libc/src/__support/math/log10p1f16.h
@@ -0,0 +1,190 @@
+//===-- Implementation header for log10p1f16 ---------------------*- 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_LOG10P1F16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOG10P1F16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "exp10_float16_constants.h"
+#include "expxf16_utils.h"
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/cpu_features.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+namespace log10p1f16_internal {
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+// ExceptValues for the small-|x| polynomial path (|x| <= 2^-3).
+LIBC_INLINE_VAR constexpr size_t N_LOG10P1F16_EXCEPTS = 3;
+
+LIBC_INLINE_VAR constexpr fputil::ExceptValues<float16, N_LOG10P1F16_EXCEPTS>
+    LOG10P1F16_EXCEPTS = {{
+        // (input, RZ output, RU offset, RD offset, RN offset)
+        // x = 0x1.ep-13
+        {0x0B80U, 0x0683U, 1U, 0U, 0U},
+        // x = -0x1.b8p-13
+        {0x89DCU, 0x8516U, 0U, 1U, 1U},
+        // x = -0x1.42p-8
+        {0x9D08U, 0x9861U, 0U, 1U, 0U},
+    }};
+
+// ExceptValues for the large-|x| table-based path (|x| > 2^-3).
+LIBC_INLINE_VAR constexpr size_t N_LOG10P1F16_EXCEPTS_HI = 6;
+
+LIBC_INLINE_VAR constexpr fputil::ExceptValues<float16,
+                                                N_LOG10P1F16_EXCEPTS_HI>
+    LOG10P1F16_EXCEPTS_HI = {{
+        // (input, RZ output, RU offset, RD offset, RN offset)
+        // x = 0x1.4c4p-2, log10p1f16(x) = 0x1.f3cp-4 (RZ)
+        {0x3531U, 0x2FCFU, 1U, 0U, 0U},
+        // x = 0x1.2p+3, log10p1f16(x) = 0x1p+0 (RZ)
+        {0x4880U, 0x3C00U, 0U, 0U, 0U},
+        // x = 0x1.8cp+6, log10p1f16(x) = 0x1p+1 (RZ)
+        {0x5630U, 0x4000U, 0U, 0U, 0U},
+        // x = 0x1.f44p+6, log10p1f16(x) = 0x1.0ccp+1 (RZ)
+        {0x57D1U, 0x4033U, 1U, 0U, 0U},
+        // x = 0x1.f38p+9, log10p1f16(x) = 0x1.8p+1 (RZ)
+        {0x63CEU, 0x4200U, 0U, 0U, 0U},
+        // x = -0x1.808p-1, log10p1f16(x) = -0x1.354p-1 (RZ)
+        {0xBA02U, 0xB8D4U, 0U, 1U, 1U},
+    }};
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+} // namespace log10p1f16_internal
+
+LIBC_INLINE float16 log10p1f16(float16 x) {
+  using namespace math::expxf16_internal;
+  using FPBits = fputil::FPBits<float16>;
+  FPBits x_bits(x);
+
+  uint16_t x_u = x_bits.uintval();
+  uint16_t x_abs = x_u & 0x7fffU;
+
+  // If x is +-0, +inf, NaN, -1, x < -1, or |x| <= 2^-3.
+  if (LIBC_UNLIKELY(x_abs == 0U || x_abs <= 0x3000U || x_u == 0x7c00U ||
+                    x_u >= 0xbc00U || x_bits.is_nan())) {
+    // log10p1(NaN) = NaN
+    if (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;
+    }
+
+    // log10p1(+/-0) = +/-0
+    if (x_abs == 0U)
+      return x;
+
+    // log10p1(+inf) = +inf
+    if (x_u == 0x7c00U)
+      return FPBits::inf().get_val();
+
+    // log10p1(-1) = -inf
+    if (x_u == 0xbc00U) {
+      fputil::raise_except_if_required(FE_DIVBYZERO);
+      return FPBits::inf(Sign::NEG).get_val();
+    }
+
+    // log10p1(x) = NaN for x < -1
+    if (x_u > 0xbc00U) {
+      fputil::set_errno_if_required(EDOM);
+      fputil::raise_except_if_required(FE_INVALID);
+      return FPBits::quiet_nan().get_val();
+    }
+
+    // When |x| <= 2^-3, use a polynomial approximation directly on x.
+    // For y = 1+x near 1, the table-based range reduction suffers from
+    // catastrophic cancellation (m*log10(2) + log10(f) nearly cancel).
+    // Computing log10(1+x) directly via polynomial avoids this.
+    //   log10(1+x) = x * (c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 + c5*x^5 +
+    //                      c6*x^6)
+    // where ck = (-1)^k / ((k+1) * ln(10)), the Taylor coefficients of
+    // log10(1+x)/x.
+    if (x_abs <= 0x3000U) {
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+      if (auto r = log10p1f16_internal::LOG10P1F16_EXCEPTS.lookup(x_u);
+          LIBC_UNLIKELY(r.has_value()))
+        return r.value();
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+      float xf = x;
+      return fputil::cast<float16>(
+          xf * fputil::polyeval(xf, 0x1.bcb7b2p-2f, -0x1.bcb7b2p-3f,
+                                0x1.287a76p-3f, -0x1.bcb7b2p-4f,
+                                0x1.63c628p-4f, -0x1.287a76p-4f,
+                                0x1.fc3fa6p-5f));
+    }
+  }
+
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  if (auto r = log10p1f16_internal::LOG10P1F16_EXCEPTS_HI.lookup(x_u);
+      LIBC_UNLIKELY(r.has_value()))
+    return r.value();
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+  // For the range reduction, we compute y = 1 + x in float. For |x| > 2^-3,
+  // the addition 1.0f + xf is exact in float, and the result y is bounded away
+  // from 1.0, avoiding catastrophic cancellation in the table decomposition.
+  float xf = x;
+  float y = 1.0f + xf;
+
+  using FPBitsFloat = fputil::FPBits<float>;
+  FPBitsFloat y_bits(y);
+
+  // When y is subnormal or zero, which shouldn't happen since y = 1 + x and
+  // x >= -1 + eps in f16, so y >= eps > 0. But handle y = 0 just in case.
+  if (LIBC_UNLIKELY(y_bits.is_zero()))
+    return FPBits::inf(Sign::NEG).get_val();
+
+  int m = y_bits.get_exponent();
+  // Set y_bits to 1.mant (biased exponent = 127).
+  y_bits.set_biased_exponent(FPBitsFloat::EXP_BIAS);
+  float mant_f = y_bits.get_val();
+
+  // Leading 23 - 5 = 18, so top 5 mantissa bits give index f in [0, 31].
+  int f = y_bits.get_mantissa() >> (FPBitsFloat::FRACTION_LEN - 5);
+
+  // v = 1.mant * 1/f - 1 = d/f
+  float v = fputil::multiply_add(mant_f, ONE_OVER_F_F[f], -1.0f);
+
+  // Degree-3 minimax polynomial generated by Sollya with the following
+  // commands:
+  //   > display = hexadecimal;
+  //   > P = fpminimax(log10(1 + x)/x, 2, [|SG...|], [-2^-5, 2^-5]);
+  //   > x * P;
+  float log10p1_d_over_f =
+      v * fputil::polyeval(v, 0x1.bcb7bp-2f, -0x1.bce168p-3f, 0x1.28acb8p-3f);
+  // log10(1.mant) = log10(f) + log10(1 + d/f)
+  float log10_1_mant = LOG10F_F[f] + log10p1_d_over_f;
+  return fputil::cast<float16>(
+      fputil::multiply_add(static_cast<float>(m), LOG10F_2, log10_1_mant));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG10P1F16_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index e617950368994..bfefc8fe39289 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -383,6 +383,7 @@ add_math_entrypoint_object(ldexpbf16)
 add_math_entrypoint_object(log10)
 add_math_entrypoint_object(log10f)
 add_math_entrypoint_object(log10f16)
+add_math_entrypoint_object(log10p1f16)
 
 add_math_entrypoint_object(log1p)
 add_math_entrypoint_object(log1pf)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f8ec25be61d12..2822d9745d0ea 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1833,6 +1833,17 @@ add_entrypoint_object(
     libc.src.errno.errno
 )
 
+add_entrypoint_object(
+  log10p1f16
+  SRCS
+    log10p1f16.cpp
+  HDRS
+    ../log10p1f16.h
+  DEPENDS
+    libc.src.__support.math.log10p1f16
+    libc.src.errno.errno
+)
+
 add_entrypoint_object(
   log1p
   SRCS
diff --git a/libc/src/math/generic/log10p1f16.cpp b/libc/src/math/generic/log10p1f16.cpp
new file mode 100644
index 0000000000000..3e3eaa631f12f
--- /dev/null
+++ b/libc/src/math/generic/log10p1f16.cpp
@@ -0,0 +1,18 @@
+//===-- Half-precision log10(1+x) 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/log10p1f16.h"
+#include "src/__support/math/log10p1f16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float16, log10p1f16, (float16 x)) {
+  return math::log10p1f16(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/log10p1f16.h b/libc/src/math/log10p1f16.h
new file mode 100644
index 0000000000000..849ea9ad6c2a4
--- /dev/null
+++ b/libc/src/math/log10p1f16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for log10p1f16 ---------------------*- 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_LOG10P1F16_H
+#define LLVM_LIBC_SRC_MATH_LOG10P1F16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float16 log10p1f16(float16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_LOG10P1F16_H
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 73b5ebf5a856e..ce44aae04eae0 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2178,6 +2178,17 @@ add_fp_unittest(
     libc.src.math.log10f16
 )
 
+add_fp_unittest(
+  log10p1f16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    log10p1f16_test.cpp
+  DEPENDS
+    libc.src.math.log10p1f16
+)
+
 add_fp_unittest(
 log1p_test
  NEED_MPFR
diff --git a/libc/test/src/math/log10p1f16_test.cpp b/libc/test/src/math/log10p1f16_test.cpp
new file mode 100644
index 0000000000000..d584f637b4166
--- /dev/null
+++ b/libc/test/src/math/log10p1f16_test.cpp
@@ -0,0 +1,49 @@
+//===-- Exhaustive test for log10p1f16 -------------------------------------===//
+//
+// 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/macros/optimization.h"
+#include "src/math/log10p1f16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+#define TOLERANCE 1
+#else
+#define TOLERANCE 0
+#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+using LlvmLibcLog10p1f16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// Range: [0, Inf];
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7c00U;
+
+// Range: [-1, 0];
+static constexpr uint16_t NEG_START = 0x8000U;
+static constexpr uint16_t NEG_STOP = 0xbc00U;
+
+TEST_F(LlvmLibcLog10p1f16Test, PositiveRange) {
+  for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
+    float16 x = FPBits(v).get_val();
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10p1, x,
+                                   LIBC_NAMESPACE::log10p1f16(x),
+                                   TOLERANCE + 0.5);
+  }
+}
+
+TEST_F(LlvmLibcLog10p1f16Test, NegativeRange) {
+  for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
+    float16 x = FPBits(v).get_val();
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10p1, x,
+                                   LIBC_NAMESPACE::log10p1f16(x),
+                                   TOLERANCE + 0.5);
+  }
+}
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 3d52873c40bb8..f3af21b20599b 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4442,6 +4442,19 @@ add_fp_unittest(
     libc.src.__support.FPUtil.cast
 )
 
+add_fp_unittest(
+  log10p1f16_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    log10p1f16_test.cpp
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.fenv_macros
+    libc.src.math.log10p1f16
+    libc.src.__support.FPUtil.cast
+)
+
 add_fp_unittest(
   log1p_test
   SUITE
diff --git a/libc/test/src/math/smoke/log10p1f16_test.cpp b/libc/test/src/math/smoke/log10p1f16_test.cpp
new file mode 100644
index 0000000000000..3a27089582d3b
--- /dev/null
+++ b/libc/test/src/math/smoke/log10p1f16_test.cpp
@@ -0,0 +1,50 @@
+//===-- Unittests for log10p1f16 -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Ap...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/184739


More information about the libc-commits mailing list