[libc-commits] [libc] [llvm] [libc][math][NFC] Split log*f into *_double_eval.h and dispatch headers. (PR #240167)

via libc-commits libc-commits at lists.llvm.org
Sun Nov 8 08:54:00 PST 2026


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

- Move double-precision evaluations of log2f, logf, log10f, and log1pf into dedicated src/__support/math/*_double_eval.h headers under math::double_eval.
- Convert src/__support/math/{log2f,logf,log10f,log1pf}.h into dispatch headers matching exp*f.h and powf.h.
- Parameterize smoke and unit tests for Default and DoubleEval variants and update CMake and Bazel build targets.

Assisted-by: Gemini

>From b2d06f05cc496b7202f7f802cac3dccabc478c77 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Fri, 6 Nov 2026 22:36:39 +0000
Subject: [PATCH] [libc][math][NFC] Split log*f into *_double_eval.h and
 dispatch headers.

- Move double-precision evaluations of log2f, logf, log10f, and log1pf into dedicated src/__support/math/*_double_eval.h headers under math::double_eval.
- Convert src/__support/math/{log2f,logf,log10f,log1pf}.h into dispatch headers matching exp*f.h and powf.h.
- Parameterize smoke and unit tests for Default and DoubleEval variants and update CMake and Bazel build targets.

Assisted-by: Gemini
---
 libc/src/__support/math/CMakeLists.txt        |  75 +++++-
 libc/src/__support/math/log10f.h              | 226 +----------------
 libc/src/__support/math/log10f_double_eval.h  | 238 ++++++++++++++++++
 libc/src/__support/math/log1pf.h              | 138 +---------
 libc/src/__support/math/log1pf_double_eval.h  | 150 +++++++++++
 libc/src/__support/math/log2f.h               | 122 +--------
 libc/src/__support/math/log2f_double_eval.h   | 132 ++++++++++
 libc/src/__support/math/logf.h                | 181 +------------
 libc/src/__support/math/logf_double_eval.h    | 192 ++++++++++++++
 libc/test/src/math/CMakeLists.txt             |   8 +
 libc/test/src/math/log10f_test.cpp            | 143 +++++++----
 libc/test/src/math/log1pf_test.cpp            | 155 +++++++-----
 libc/test/src/math/log2f_test.cpp             | 121 +++++----
 libc/test/src/math/logf_test.cpp              | 176 ++++++++-----
 libc/test/src/math/smoke/CMakeLists.txt       |   8 +
 libc/test/src/math/smoke/log10f_test.cpp      | 139 ++++++----
 libc/test/src/math/smoke/log1pf_test.cpp      | 111 +++++---
 libc/test/src/math/smoke/log2f_test.cpp       | 124 ++++++---
 libc/test/src/math/smoke/logf_test.cpp        | 122 ++++++---
 .../llvm-project-overlay/libc/BUILD.bazel     |  58 ++++-
 .../libc/test/src/math/BUILD.bazel            |  28 ++-
 .../libc/test/src/math/smoke/BUILD.bazel      |  28 ++-
 22 files changed, 1647 insertions(+), 1028 deletions(-)
 create mode 100644 libc/src/__support/math/log10f_double_eval.h
 create mode 100644 libc/src/__support/math/log1pf_double_eval.h
 create mode 100644 libc/src/__support/math/log2f_double_eval.h
 create mode 100644 libc/src/__support/math/logf_double_eval.h

diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index ee57d082456c33..048dd20578029e 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -5558,16 +5558,32 @@ add_header_library(
 )
 
 add_header_library(
-  log10f
+  log10f_double_eval
   HDRS
-    log10f.h
+    log10f_double_eval.h
   DEPENDS
     .common_constants
     libc.src.__support.FPUtil.except_value_utils
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fma
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
     libc.src.__support.FPUtil.polyeval
+    libc.src.__support.common
+    libc.src.__support.macros.attributes
+    libc.src.__support.macros.config
+    libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.cpu_features
+)
+
+add_header_library(
+  log10f
+  HDRS
+    log10f.h
+  DEPENDS
+    .log10f_double_eval
+    libc.src.__support.common
+    libc.src.__support.macros.config
 )
 
 add_header_library(
@@ -5587,17 +5603,31 @@ add_header_library(
 )
 
 add_header_library(
-  log1pf
+  log1pf_double_eval
   HDRS
-    log1pf.h
+    log1pf_double_eval.h
   DEPENDS
     .acoshf_utils
     libc.src.__support.FPUtil.except_value_utils
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fma
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
     libc.src.__support.FPUtil.polyeval
+    libc.src.__support.common
+    libc.src.__support.macros.config
     libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.cpu_features
+)
+
+add_header_library(
+  log1pf
+  HDRS
+    log1pf.h
+  DEPENDS
+    .log1pf_double_eval
+    libc.src.__support.common
+    libc.src.__support.macros.config
 )
 
 add_header_library(
@@ -5636,17 +5666,30 @@ add_header_library(
 )
 
 add_header_library(
-  log2f
+  log2f_double_eval
   HDRS
-    log2f.h
+    log2f_double_eval.h
   DEPENDS
     .common_constants
     libc.src.__support.FPUtil.except_value_utils
     libc.src.__support.FPUtil.fenv_impl
-    libc.src.__support.FPUtil.fma
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.multiply_add
     libc.src.__support.FPUtil.polyeval
+    libc.src.__support.common
+    libc.src.__support.macros.config
     libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.cpu_features
+)
+
+add_header_library(
+  log2f
+  HDRS
+    log2f.h
+  DEPENDS
+    .log2f_double_eval
+    libc.src.__support.common
+    libc.src.__support.macros.config
 )
 
 add_header_library(
@@ -5689,22 +5732,32 @@ add_header_library(
 )
 
 add_header_library(
-  logf
+  logf_double_eval
   HDRS
-    logf.h
+    logf_double_eval.h
   DEPENDS
     .common_constants
+    libc.src.__support.FPUtil.except_value_utils
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
-    libc.src.__support.FPUtil.polyeval
-    libc.src.__support.FPUtil.except_value_utils
     libc.src.__support.FPUtil.multiply_add
+    libc.src.__support.FPUtil.polyeval
     libc.src.__support.common
     libc.src.__support.macros.config
     libc.src.__support.macros.optimization
     libc.src.__support.macros.properties.cpu_features
 )
 
+add_header_library(
+  logf
+  HDRS
+    logf.h
+  DEPENDS
+    .logf_double_eval
+    libc.src.__support.common
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   logbl
   HDRS
diff --git a/libc/src/__support/math/log10f.h b/libc/src/__support/math/log10f.h
index 0c0488bad5f15d..80e6a9bdf05b14 100644
--- a/libc/src/__support/math/log10f.h
+++ b/libc/src/__support/math/log10f.h
@@ -1,237 +1,33 @@
-//===-- Implementation header for log10f ------------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for log10f.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOG10F_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LOG10F_H
 
-#include "common_constants.h" // Lookup table for (1/f)
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/PolyEval.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/attributes.h"
 #include "src/__support/macros/config.h"
-#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-#include "src/__support/macros/properties/cpu_features.h"
-
-// This is an algorithm for log10(x) in single precision which is
-// correctly rounded for all rounding modes, based on the implementation of
-// log10(x) from the RLIBM project at:
-// https://people.cs.rutgers.edu/~sn349/rlibm
+#include "src/__support/math/log10f_double_eval.h"
 
-// Step 1 - Range reduction:
-//   For x = 2^m * 1.mant, log(x) = m * log10(2) + log10(1.m)
-//   If x is denormal, we normalize it by multiplying x by 2^23 and subtracting
-//   m by 23.
-
-// Step 2 - Another range reduction:
-//   To compute log(1.mant), let f be the highest 8 bits including the hidden
-// bit, and d be the difference (1.mant - f), i.e. the remaining 16 bits of the
-// mantissa. Then we have the following approximation formula:
-//   log10(1.mant) = log10(f) + log10(1.mant / f)
-//                 = log10(f) + log10(1 + d/f)
-//                 ~ log10(f) + P(d/f)
-// since d/f is sufficiently small.
-//   log10(f) and 1/f are then stored in two 2^7 = 128 entries look-up tables.
-
-// Step 3 - Polynomial approximation:
-//   To compute P(d/f), we use a single degree-5 polynomial in double precision
-// which provides correct rounding for all but few exception values.
-//   For more detail about how this polynomial is obtained, please refer to the
-// papers:
-//   Lim, J. and Nagarakatte, S., "One Polynomial Approximation to Produce
-// Correctly Rounded Results of an Elementary Function for Multiple
-// Representations and Rounding Modes", Proceedings of the 49th ACM SIGPLAN
-// Symposium on Principles of Programming Languages (POPL-2022), Philadelphia,
-// USA, Jan. 16-22, 2022.
-// https://people.cs.rutgers.edu/~sn349/papers/rlibmall-popl-2022.pdf
-//   Aanjaneya, M., Lim, J., and Nagarakatte, S., "RLibm-Prog: Progressive
-// Polynomial Approximations for Fast Correctly Rounded Math Libraries",
-// Dept. of Comp. Sci., Rutgets U., Technical Report DCS-TR-758, Nov. 2021.
-// https://arxiv.org/pdf/2111.12852.pdf.
+#define LIBC_MATH_LOG10F_IMPL double_eval
 
 namespace LIBC_NAMESPACE_DECL {
-
 namespace math {
 
-namespace log10f_internal {
-
-LIBC_INLINE_VAR constexpr double LOG10_2 = 0x1.34413509f79ffp-2;
-
-// Lookup table for -log10(r) where r is defined in common_constants.cpp.
-LIBC_INLINE_VAR constexpr double LOG10_R[128] = {
-    0x0.0000000000000p+0, 0x1.be76bd77b4fc3p-9, 0x1.c03a80ae5e054p-8,
-    0x1.51824c7587ebp-7,  0x1.c3d0837784c41p-7, 0x1.1b85d6044e9aep-6,
-    0x1.559bd2406c3bap-6, 0x1.902c31d62a843p-6, 0x1.cb38fccd8bfdbp-6,
-    0x1.e8eeb09f2f6cbp-6, 0x1.125d0432ea20ep-5, 0x1.30838cdc2fbfdp-5,
-    0x1.3faf7c663060ep-5, 0x1.5e3966b7e9295p-5, 0x1.7d070145f4fd7p-5,
-    0x1.8c878eeb05074p-5, 0x1.abbcebd84fcap-5,  0x1.bb7209d1e24e5p-5,
-    0x1.db11ed766abf4p-5, 0x1.eafd05035bd3bp-5, 0x1.0585283764178p-4,
-    0x1.0d966cc6500fap-4, 0x1.1dd5460c8b16fp-4, 0x1.2603072a25f82p-4,
-    0x1.367ba3aaa1883p-4, 0x1.3ec6ad5407868p-4, 0x1.4f7aad9bbcbafp-4,
-    0x1.57e3d47c3af7bp-4, 0x1.605735ee985f1p-4, 0x1.715d0ce367afcp-4,
-    0x1.79efb57b0f803p-4, 0x1.828cfed29a215p-4, 0x1.93e7de0fc3e8p-4,
-    0x1.9ca5aa1729f45p-4, 0x1.a56e8325f5c87p-4, 0x1.ae4285509950bp-4,
-    0x1.b721cd17157e3p-4, 0x1.c902a19e65111p-4, 0x1.d204698cb42bdp-4,
-    0x1.db11ed766abf4p-4, 0x1.e42b4c16caaf3p-4, 0x1.ed50a4a26eafcp-4,
-    0x1.ffbfc2bbc7803p-4, 0x1.0484e4942aa43p-3, 0x1.093025a19976cp-3,
-    0x1.0de1b56356b04p-3, 0x1.1299a4fb3e306p-3, 0x1.175805d1587c1p-3,
-    0x1.1c1ce9955c0c6p-3, 0x1.20e8624038fedp-3, 0x1.25ba8215af7fcp-3,
-    0x1.2a935ba5f1479p-3, 0x1.2f7301cf4e87bp-3, 0x1.345987bfeea91p-3,
-    0x1.394700f7953fdp-3, 0x1.3e3b8149739d4p-3, 0x1.43371cde076c2p-3,
-    0x1.4839e83506c87p-3, 0x1.4d43f8275a483p-3, 0x1.525561e9256eep-3,
-    0x1.576e3b0bde0a7p-3, 0x1.5c8e998072fe2p-3, 0x1.61b6939983048p-3,
-    0x1.66e6400da3f77p-3, 0x1.6c1db5f9bb336p-3, 0x1.6c1db5f9bb336p-3,
-    0x1.715d0ce367afcp-3, 0x1.76a45cbb7e6ffp-3, 0x1.7bf3bde099f3p-3,
-    0x1.814b4921bd52bp-3, 0x1.86ab17c10bc7fp-3, 0x1.86ab17c10bc7fp-3,
-    0x1.8c13437695532p-3, 0x1.9183e673394fap-3, 0x1.96fd1b639fc09p-3,
-    0x1.9c7efd734a2f9p-3, 0x1.a209a84fbcff8p-3, 0x1.a209a84fbcff8p-3,
-    0x1.a79d382bc21d9p-3, 0x1.ad39c9c2c608p-3,  0x1.b2df7a5c50299p-3,
-    0x1.b2df7a5c50299p-3, 0x1.b88e67cf9798p-3,  0x1.be46b087354bcp-3,
-    0x1.c4087384f4f8p-3,  0x1.c4087384f4f8p-3,  0x1.c9d3d065c5b42p-3,
-    0x1.cfa8e765cbb72p-3, 0x1.cfa8e765cbb72p-3, 0x1.d587d96494759p-3,
-    0x1.db70c7e96e7f3p-3, 0x1.db70c7e96e7f3p-3, 0x1.e163d527e68cfp-3,
-    0x1.e76124046b3f3p-3, 0x1.e76124046b3f3p-3, 0x1.ed68d819191fcp-3,
-    0x1.f37b15bab08d1p-3, 0x1.f37b15bab08d1p-3, 0x1.f99801fdb749dp-3,
-    0x1.ffbfc2bbc7803p-3, 0x1.ffbfc2bbc7803p-3, 0x1.02f93f4c87101p-2,
-    0x1.06182e84fd4acp-2, 0x1.06182e84fd4acp-2, 0x1.093cc32c90f84p-2,
-    0x1.093cc32c90f84p-2, 0x1.0c6711d6abd7ap-2, 0x1.0f972f87ff3d6p-2,
-    0x1.0f972f87ff3d6p-2, 0x1.12cd31b9c99ffp-2, 0x1.12cd31b9c99ffp-2,
-    0x1.16092e5d3a9a6p-2, 0x1.194b3bdef6b9ep-2, 0x1.194b3bdef6b9ep-2,
-    0x1.1c93712abc7ffp-2, 0x1.1c93712abc7ffp-2, 0x1.1fe1e5af2c141p-2,
-    0x1.1fe1e5af2c141p-2, 0x1.2336b161b3337p-2, 0x1.2336b161b3337p-2,
-    0x1.2691ecc29f042p-2, 0x1.2691ecc29f042p-2, 0x1.29f3b0e15584bp-2,
-    0x1.29f3b0e15584bp-2, 0x1.2d5c1760b86bbp-2, 0x1.2d5c1760b86bbp-2,
-    0x1.30cb3a7bb3625p-2, 0x1.34413509f79ffp-2};
-
-// Degree-5 polynomial approximation of log10 generated by:
-// > P = fpminimax(log10(1 + x)/x, 4, [|D...|], [-2^-8, 2^-7]);
-LIBC_INLINE_VAR constexpr double COEFFS[5] = {
-    0x1.bcb7b1526e2e5p-2, -0x1.bcb7b1528d43dp-3, 0x1.287a77eb4ca0dp-3,
-    -0x1.bcb8110a181b5p-4, 0x1.60e7e3e747129p-4};
-
-} // namespace log10f_internal
-
-LIBC_INLINE float log10f(float x) {
-  using namespace common_constants_internal;
-  using namespace log10f_internal;
-
-  using FPBits = typename fputil::FPBits<float>;
-
-  FPBits xbits(x);
-  uint32_t x_u = xbits.uintval();
-
-  // Exact powers of 10 and other hard-to-round cases.
-  if (LIBC_UNLIKELY((x_u & 0x3FF) == 0)) {
-    switch (x_u) {
-    case 0x3f80'0000U: // x = 1
-      return 0.0f;
-    case 0x4120'0000U: // x = 10
-      return 1.0f;
-    case 0x42c8'0000U: // x = 100
-      return 2.0f;
-    case 0x447a'0000U: // x = 1,000
-      return 3.0f;
-    case 0x461c'4000U: // x = 10,000
-      return 4.0f;
-    case 0x47c3'5000U: // x = 100,000
-      return 5.0f;
-    case 0x4974'2400U: // x = 1,000,000
-      return 6.0f;
-    }
-  } else {
-    switch (x_u) {
-    case 0x4b18'9680U: // x = 10,000,000
-      return 7.0f;
-    case 0x4cbe'bc20U: // x = 100,000,000
-      return 8.0f;
-    case 0x4e6e'6b28U: // x = 1,000,000,000
-      return 9.0f;
-    case 0x5015'02f9U: // x = 10,000,000,000
-      return 10.0f;
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-    case 0x0efe'ee7aU: // x = 0x1.fddcf4p-98f
-      return fputil::round_result_slightly_up(-0x1.d33a46p+4f);
-    case 0x3f5f'de1bU: // x = 0x1.bfbc36p-1f
-      return fputil::round_result_slightly_up(-0x1.dd2c6ep-5f);
-    case 0x3f80'70d8U: // x = 0x1.00e1bp0f
-      return fputil::round_result_slightly_up(0x1.8762c4p-10f);
-#ifndef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
-    case 0x08ae'a356U: // x = 0x1.5d46acp-110f
-      return fputil::round_result_slightly_up(-0x1.07d3b4p+5f);
-    case 0x120b'93dcU: // x = 0x1.1727b8p-91f
-      return fputil::round_result_slightly_down(-0x1.b5b2aep+4f);
-    case 0x13ae'78d3U: // x = 0x1.5cf1a6p-88f
-      return fputil::round_result_slightly_down(-0x1.a5b2aep+4f);
-    case 0x4f13'4f83U: // x = 2471461632.0
-      return fputil::round_result_slightly_down(0x1.2c9314p+3f);
-    case 0x7956'ba5eU: // x = 69683218960000541503257137270226944.0
-      return fputil::round_result_slightly_up(0x1.16bebap+5f);
-#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-    }
-  }
-
-  int m = -FPBits::EXP_BIAS;
-
-  if (LIBC_UNLIKELY(x_u < FPBits::min_normal().uintval() ||
-                    x_u > FPBits::max_normal().uintval())) {
-    if (x == 0.0f) {
-      // Return -inf and raise FE_DIVBYZERO
-      fputil::set_errno_if_required(ERANGE);
-      fputil::raise_except_if_required(FE_DIVBYZERO);
-      return FPBits::inf(Sign::NEG).get_val();
-    }
-    if (xbits.is_neg() && !xbits.is_nan()) {
-      // Return NaN and raise FE_INVALID
-      fputil::set_errno_if_required(EDOM);
-      fputil::raise_except_if_required(FE_INVALID);
-      return FPBits::quiet_nan().get_val();
-    }
-    if (xbits.is_inf_or_nan()) {
-      return x;
-    }
-    // Normalize denormal inputs.
-    xbits = FPBits(xbits.get_val() * 0x1.0p23f);
-    m -= 23;
-    x_u = xbits.uintval();
-  }
-
-  // Add unbiased exponent.
-  m += static_cast<int>(x_u >> 23);
-  // Extract 7 leading fractional bits of the mantissa
-  int index = (x_u >> 16) & 0x7F;
-  // Set bits to 1.m
-  xbits.set_biased_exponent(0x7F);
-
-  float u = xbits.get_val();
-#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-  double v =
-      static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.
-#else
-  double v = fputil::multiply_add(static_cast<double>(u),
-                                  static_cast<double>(R[index]), -1.0); // Exact
-#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
-
-  double v2 = v * v; // Exact
-  double p2 = fputil::multiply_add(v, COEFFS[4], COEFFS[3]);
-  double p1 = fputil::multiply_add(v, COEFFS[2], COEFFS[1]);
-  double p0 = fputil::multiply_add(v, COEFFS[0], LOG10_R[index]);
-  double r = fputil::multiply_add(static_cast<double>(m), LOG10_2,
-                                  fputil::polyeval(v2, p0, p1, p2));
-
-  return static_cast<float>(r);
-}
+using LIBC_MATH_LOG10F_IMPL::log10f;
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
+#undef LIBC_MATH_LOG10F_IMPL
+
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG10F_H
diff --git a/libc/src/__support/math/log10f_double_eval.h b/libc/src/__support/math/log10f_double_eval.h
new file mode 100644
index 00000000000000..e49614c6ed9fa0
--- /dev/null
+++ b/libc/src/__support/math/log10f_double_eval.h
@@ -0,0 +1,238 @@
+//===-- Double-precision implementation of log10f ---------------*- 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_LOG10F_DOUBLE_EVAL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOG10F_DOUBLE_EVAL_H
+
+#include "common_constants.h" // Lookup table for (1/f)
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.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/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+#include "src/__support/macros/properties/cpu_features.h"
+
+// This is an algorithm for log10(x) in single precision which is
+// correctly rounded for all rounding modes, based on the implementation of
+// log10(x) from the RLIBM project at:
+// https://people.cs.rutgers.edu/~sn349/rlibm
+
+// Step 1 - Range reduction:
+//   For x = 2^m * 1.mant, log(x) = m * log10(2) + log10(1.m)
+//   If x is denormal, we normalize it by multiplying x by 2^23 and subtracting
+//   m by 23.
+
+// Step 2 - Another range reduction:
+//   To compute log(1.mant), let f be the highest 8 bits including the hidden
+// bit, and d be the difference (1.mant - f), i.e. the remaining 16 bits of the
+// mantissa. Then we have the following approximation formula:
+//   log10(1.mant) = log10(f) + log10(1.mant / f)
+//                 = log10(f) + log10(1 + d/f)
+//                 ~ log10(f) + P(d/f)
+// since d/f is sufficiently small.
+//   log10(f) and 1/f are then stored in two 2^7 = 128 entries look-up tables.
+
+// Step 3 - Polynomial approximation:
+//   To compute P(d/f), we use a single degree-5 polynomial in double precision
+// which provides correct rounding for all but few exception values.
+//   For more detail about how this polynomial is obtained, please refer to the
+// papers:
+//   Lim, J. and Nagarakatte, S., "One Polynomial Approximation to Produce
+// Correctly Rounded Results of an Elementary Function for Multiple
+// Representations and Rounding Modes", Proceedings of the 49th ACM SIGPLAN
+// Symposium on Principles of Programming Languages (POPL-2022), Philadelphia,
+// USA, Jan. 16-22, 2022.
+// https://people.cs.rutgers.edu/~sn349/papers/rlibmall-popl-2022.pdf
+//   Aanjaneya, M., Lim, J., and Nagarakatte, S., "RLibm-Prog: Progressive
+// Polynomial Approximations for Fast Correctly Rounded Math Libraries",
+// Dept. of Comp. Sci., Rutgets U., Technical Report DCS-TR-758, Nov. 2021.
+// https://arxiv.org/pdf/2111.12852.pdf.
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+namespace double_eval {
+
+namespace log10f_internal {
+
+LIBC_INLINE_VAR constexpr double LOG10_2 = 0x1.34413509f79ffp-2;
+
+// Lookup table for -log10(r) where r is defined in common_constants.cpp.
+LIBC_INLINE_VAR constexpr double LOG10_R[128] = {
+    0x0.0000000000000p+0, 0x1.be76bd77b4fc3p-9, 0x1.c03a80ae5e054p-8,
+    0x1.51824c7587ebp-7,  0x1.c3d0837784c41p-7, 0x1.1b85d6044e9aep-6,
+    0x1.559bd2406c3bap-6, 0x1.902c31d62a843p-6, 0x1.cb38fccd8bfdbp-6,
+    0x1.e8eeb09f2f6cbp-6, 0x1.125d0432ea20ep-5, 0x1.30838cdc2fbfdp-5,
+    0x1.3faf7c663060ep-5, 0x1.5e3966b7e9295p-5, 0x1.7d070145f4fd7p-5,
+    0x1.8c878eeb05074p-5, 0x1.abbcebd84fcap-5,  0x1.bb7209d1e24e5p-5,
+    0x1.db11ed766abf4p-5, 0x1.eafd05035bd3bp-5, 0x1.0585283764178p-4,
+    0x1.0d966cc6500fap-4, 0x1.1dd5460c8b16fp-4, 0x1.2603072a25f82p-4,
+    0x1.367ba3aaa1883p-4, 0x1.3ec6ad5407868p-4, 0x1.4f7aad9bbcbafp-4,
+    0x1.57e3d47c3af7bp-4, 0x1.605735ee985f1p-4, 0x1.715d0ce367afcp-4,
+    0x1.79efb57b0f803p-4, 0x1.828cfed29a215p-4, 0x1.93e7de0fc3e8p-4,
+    0x1.9ca5aa1729f45p-4, 0x1.a56e8325f5c87p-4, 0x1.ae4285509950bp-4,
+    0x1.b721cd17157e3p-4, 0x1.c902a19e65111p-4, 0x1.d204698cb42bdp-4,
+    0x1.db11ed766abf4p-4, 0x1.e42b4c16caaf3p-4, 0x1.ed50a4a26eafcp-4,
+    0x1.ffbfc2bbc7803p-4, 0x1.0484e4942aa43p-3, 0x1.093025a19976cp-3,
+    0x1.0de1b56356b04p-3, 0x1.1299a4fb3e306p-3, 0x1.175805d1587c1p-3,
+    0x1.1c1ce9955c0c6p-3, 0x1.20e8624038fedp-3, 0x1.25ba8215af7fcp-3,
+    0x1.2a935ba5f1479p-3, 0x1.2f7301cf4e87bp-3, 0x1.345987bfeea91p-3,
+    0x1.394700f7953fdp-3, 0x1.3e3b8149739d4p-3, 0x1.43371cde076c2p-3,
+    0x1.4839e83506c87p-3, 0x1.4d43f8275a483p-3, 0x1.525561e9256eep-3,
+    0x1.576e3b0bde0a7p-3, 0x1.5c8e998072fe2p-3, 0x1.61b6939983048p-3,
+    0x1.66e6400da3f77p-3, 0x1.6c1db5f9bb336p-3, 0x1.6c1db5f9bb336p-3,
+    0x1.715d0ce367afcp-3, 0x1.76a45cbb7e6ffp-3, 0x1.7bf3bde099f3p-3,
+    0x1.814b4921bd52bp-3, 0x1.86ab17c10bc7fp-3, 0x1.86ab17c10bc7fp-3,
+    0x1.8c13437695532p-3, 0x1.9183e673394fap-3, 0x1.96fd1b639fc09p-3,
+    0x1.9c7efd734a2f9p-3, 0x1.a209a84fbcff8p-3, 0x1.a209a84fbcff8p-3,
+    0x1.a79d382bc21d9p-3, 0x1.ad39c9c2c608p-3,  0x1.b2df7a5c50299p-3,
+    0x1.b2df7a5c50299p-3, 0x1.b88e67cf9798p-3,  0x1.be46b087354bcp-3,
+    0x1.c4087384f4f8p-3,  0x1.c4087384f4f8p-3,  0x1.c9d3d065c5b42p-3,
+    0x1.cfa8e765cbb72p-3, 0x1.cfa8e765cbb72p-3, 0x1.d587d96494759p-3,
+    0x1.db70c7e96e7f3p-3, 0x1.db70c7e96e7f3p-3, 0x1.e163d527e68cfp-3,
+    0x1.e76124046b3f3p-3, 0x1.e76124046b3f3p-3, 0x1.ed68d819191fcp-3,
+    0x1.f37b15bab08d1p-3, 0x1.f37b15bab08d1p-3, 0x1.f99801fdb749dp-3,
+    0x1.ffbfc2bbc7803p-3, 0x1.ffbfc2bbc7803p-3, 0x1.02f93f4c87101p-2,
+    0x1.06182e84fd4acp-2, 0x1.06182e84fd4acp-2, 0x1.093cc32c90f84p-2,
+    0x1.093cc32c90f84p-2, 0x1.0c6711d6abd7ap-2, 0x1.0f972f87ff3d6p-2,
+    0x1.0f972f87ff3d6p-2, 0x1.12cd31b9c99ffp-2, 0x1.12cd31b9c99ffp-2,
+    0x1.16092e5d3a9a6p-2, 0x1.194b3bdef6b9ep-2, 0x1.194b3bdef6b9ep-2,
+    0x1.1c93712abc7ffp-2, 0x1.1c93712abc7ffp-2, 0x1.1fe1e5af2c141p-2,
+    0x1.1fe1e5af2c141p-2, 0x1.2336b161b3337p-2, 0x1.2336b161b3337p-2,
+    0x1.2691ecc29f042p-2, 0x1.2691ecc29f042p-2, 0x1.29f3b0e15584bp-2,
+    0x1.29f3b0e15584bp-2, 0x1.2d5c1760b86bbp-2, 0x1.2d5c1760b86bbp-2,
+    0x1.30cb3a7bb3625p-2, 0x1.34413509f79ffp-2};
+
+// Degree-5 polynomial approximation of log10 generated by:
+// > P = fpminimax(log10(1 + x)/x, 4, [|D...|], [-2^-8, 2^-7]);
+LIBC_INLINE_VAR constexpr double COEFFS[5] = {
+    0x1.bcb7b1526e2e5p-2, -0x1.bcb7b1528d43dp-3, 0x1.287a77eb4ca0dp-3,
+    -0x1.bcb8110a181b5p-4, 0x1.60e7e3e747129p-4};
+
+} // namespace log10f_internal
+
+LIBC_INLINE float log10f(float x) {
+  using namespace common_constants_internal;
+  using namespace log10f_internal;
+
+  using FPBits = typename fputil::FPBits<float>;
+
+  FPBits xbits(x);
+  uint32_t x_u = xbits.uintval();
+
+  // Exact powers of 10 and other hard-to-round cases.
+  if (LIBC_UNLIKELY((x_u & 0x3FF) == 0)) {
+    switch (x_u) {
+    case 0x3f80'0000U: // x = 1
+      return 0.0f;
+    case 0x4120'0000U: // x = 10
+      return 1.0f;
+    case 0x42c8'0000U: // x = 100
+      return 2.0f;
+    case 0x447a'0000U: // x = 1,000
+      return 3.0f;
+    case 0x461c'4000U: // x = 10,000
+      return 4.0f;
+    case 0x47c3'5000U: // x = 100,000
+      return 5.0f;
+    case 0x4974'2400U: // x = 1,000,000
+      return 6.0f;
+    }
+  } else {
+    switch (x_u) {
+    case 0x4b18'9680U: // x = 10,000,000
+      return 7.0f;
+    case 0x4cbe'bc20U: // x = 100,000,000
+      return 8.0f;
+    case 0x4e6e'6b28U: // x = 1,000,000,000
+      return 9.0f;
+    case 0x5015'02f9U: // x = 10,000,000,000
+      return 10.0f;
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+    case 0x0efe'ee7aU: // x = 0x1.fddcf4p-98f
+      return fputil::round_result_slightly_up(-0x1.d33a46p+4f);
+    case 0x3f5f'de1bU: // x = 0x1.bfbc36p-1f
+      return fputil::round_result_slightly_up(-0x1.dd2c6ep-5f);
+    case 0x3f80'70d8U: // x = 0x1.00e1bp0f
+      return fputil::round_result_slightly_up(0x1.8762c4p-10f);
+#ifndef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+    case 0x08ae'a356U: // x = 0x1.5d46acp-110f
+      return fputil::round_result_slightly_up(-0x1.07d3b4p+5f);
+    case 0x120b'93dcU: // x = 0x1.1727b8p-91f
+      return fputil::round_result_slightly_down(-0x1.b5b2aep+4f);
+    case 0x13ae'78d3U: // x = 0x1.5cf1a6p-88f
+      return fputil::round_result_slightly_down(-0x1.a5b2aep+4f);
+    case 0x4f13'4f83U: // x = 2471461632.0
+      return fputil::round_result_slightly_down(0x1.2c9314p+3f);
+    case 0x7956'ba5eU: // x = 69683218960000541503257137270226944.0
+      return fputil::round_result_slightly_up(0x1.16bebap+5f);
+#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+    }
+  }
+
+  int m = -FPBits::EXP_BIAS;
+
+  if (LIBC_UNLIKELY(x_u < FPBits::min_normal().uintval() ||
+                    x_u > FPBits::max_normal().uintval())) {
+    if (x == 0.0f) {
+      // Return -inf and raise FE_DIVBYZERO
+      fputil::set_errno_if_required(ERANGE);
+      fputil::raise_except_if_required(FE_DIVBYZERO);
+      return FPBits::inf(Sign::NEG).get_val();
+    }
+    if (xbits.is_neg() && !xbits.is_nan()) {
+      // Return NaN and raise FE_INVALID
+      fputil::set_errno_if_required(EDOM);
+      fputil::raise_except_if_required(FE_INVALID);
+      return FPBits::quiet_nan().get_val();
+    }
+    if (xbits.is_inf_or_nan()) {
+      return x;
+    }
+    // Normalize denormal inputs.
+    xbits = FPBits(xbits.get_val() * 0x1.0p23f);
+    m -= 23;
+    x_u = xbits.uintval();
+  }
+
+  // Add unbiased exponent.
+  m += static_cast<int>(x_u >> 23);
+  // Extract 7 leading fractional bits of the mantissa
+  int index = (x_u >> 16) & 0x7F;
+  // Set bits to 1.m
+  xbits.set_biased_exponent(0x7F);
+
+  float u = xbits.get_val();
+#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
+  double v =
+      static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.
+#else
+  double v = fputil::multiply_add(static_cast<double>(u),
+                                  static_cast<double>(R[index]), -1.0); // Exact
+#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
+
+  double v2 = v * v; // Exact
+  double p2 = fputil::multiply_add(v, COEFFS[4], COEFFS[3]);
+  double p1 = fputil::multiply_add(v, COEFFS[2], COEFFS[1]);
+  double p0 = fputil::multiply_add(v, COEFFS[0], LOG10_R[index]);
+  double r = fputil::multiply_add(static_cast<double>(m), LOG10_2,
+                                  fputil::polyeval(v2, p0, p1, p2));
+
+  return static_cast<float>(r);
+}
+
+} // namespace double_eval
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG10F_DOUBLE_EVAL_H
diff --git a/libc/src/__support/math/log1pf.h b/libc/src/__support/math/log1pf.h
index 49244f38f8905a..441017c1eb4c84 100644
--- a/libc/src/__support/math/log1pf.h
+++ b/libc/src/__support/math/log1pf.h
@@ -1,149 +1,33 @@
-//===-- Implementation header for log1pf ------------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for log1pf.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOG1PF_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LOG1PF_H
 
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FMA.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/PolyEval.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" // LIBC_UNLIKELY
-#include "src/__support/macros/properties/cpu_features.h"
-#include "src/__support/math/acoshf_utils.h"
+#include "src/__support/math/log1pf_double_eval.h"
 
-// This is an algorithm for log(1+x) in single precision which is
-// correctly rounded for all rounding modes.
-// - An exhaustive test show that when x >= 2^45, log1pf(x) == logf(x)
-// for all rounding modes.
-// - When 2^(-6) <= |x| < 2^45, the sum (double(x) + 1.0) is exact,
-// so we can adapt the correctly rounded algorithm of logf to compute
-// log(double(x) + 1.0) correctly.  For more information about the logf
-// algorithm, see `libc/src/math/generic/logf.cpp`.
-// - When |x| < 2^(-6), we use a degree-8 polynomial in double precision
-// generated with Sollya using the following command:
-//   fpminimax(log(1 + x)/x, 7, [|D...|], [-2^-6; 2^-6]);
+#define LIBC_MATH_LOG1PF_IMPL double_eval
 
 namespace LIBC_NAMESPACE_DECL {
-
 namespace math {
 
-LIBC_INLINE float log1pf(float x) {
-  using FPBits = typename fputil::FPBits<float>;
-  FPBits xbits(x);
-  uint32_t x_u = xbits.uintval();
-  uint32_t x_a = x_u & 0x7fff'ffffU;
-  double xd = static_cast<double>(x);
-
-  if (x_a <= 0x3c80'0000U) {
-    // |x| <= 2^-6.
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-    // Hard-to round cases.
-    switch (x_u) {
-    case 0x3540'0003U: // x = 0x1.800006p-21f
-      return fputil::round_result_slightly_down(0x1.7ffffep-21f);
-    case 0x3710'001bU: // x = 0x1.200036p-17f
-      return fputil::round_result_slightly_down(0x1.1fffe6p-17f);
-    case 0xb53f'fffdU: // x = -0x1.7ffffap-21
-      return fputil::round_result_slightly_down(-0x1.800002p-21f);
-    case 0xb70f'ffe5U: // x = -0x1.1fffcap-17
-      return fputil::round_result_slightly_down(-0x1.20001ap-17f);
-    case 0xbb0e'c8c4U: // x = -0x1.1d9188p-9
-      return fputil::round_result_slightly_up(-0x1.1de14ap-9f);
-    }
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-
-    // Polynomial generated by Sollya with:
-    // > P = fpminimax(log(1 + x)/x, 7, [|D...|], [-2^-6; 2^-6]);
-    // > dirtyinfnorm((log(1 + x) - x*P)/log(1 + x), [-2^-6, 2^-6]);
-    // 0x1.1447755e54a327941f7db7316f8dcd7cf33d15ffp-58
-    constexpr double COEFFS[7] = {-0x1.0000000000000p-1, 0x1.5555555556aadp-2,
-                                  -0x1.000000000181ap-2, 0x1.999998998124ep-3,
-                                  -0x1.55555452e2a2bp-3, 0x1.24adb8cde4aa7p-3,
-                                  -0x1.0019db915ef6fp-3};
-
-    double xsq = xd * xd;
-    double c0 = fputil::multiply_add(xd, COEFFS[1], COEFFS[0]);
-    double c1 = fputil::multiply_add(xd, COEFFS[3], COEFFS[2]);
-    double c2 = fputil::multiply_add(xd, COEFFS[5], COEFFS[4]);
-    double x4 = xsq * xsq;
-    double d0 = fputil::multiply_add(xsq, c1, c0);
-    double d1 = fputil::multiply_add(xsq, COEFFS[6], c2);
-    double d2 = fputil::multiply_add(x4, d1, d0);
-    double r = fputil::multiply_add(xsq, d2, xd);
-
-    return static_cast<float>(r);
-  }
-
-  // Use log1p(x) = log(1 + x) for |x| > 2^-6;
-
-  // Check for exceptional cases.
-  if (x_a >= 0x3f80'0000) {
-    // |x| >= 1.
-    if (LIBC_UNLIKELY(x_u >= 0x7f80'0000)) {
-      // x is inf, nan, or x <= -1.
-      if (x == -1.0f) {
-        // x = -1
-        fputil::set_errno_if_required(ERANGE);
-        fputil::raise_except_if_required(FE_DIVBYZERO);
-        return FPBits::inf(Sign::NEG).get_val();
-      }
-      if (xbits.is_signaling_nan() || x < 1.0f) {
-        // x is signaling NaNs or x < -1
-        if (x < 1.0f)
-          fputil::set_errno_if_required(EDOM);
-        fputil::raise_except_if_required(FE_INVALID);
-        return fputil::FPBits<float>::quiet_nan().get_val();
-      }
-      // x is +inf or quiet NaN
-      return x;
-    }
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-    // Filter hard-to-round cases:
-    if (LIBC_UNLIKELY(x >= 0x1.30bf04p+43f)) {
-      switch (x_u) {
-      case 0x5518'5f82U: // x = 0x1.30bf04p+43f
-        return fputil::round_result_slightly_up(0x1.dfac9p+4f);
-      case 0x5cd6'9e88U: // x = 0x1.ad3d1p+58f
-        return fputil::round_result_slightly_up(0x1.45c146p+5f);
-      case 0x5ee8'984eU: // x = 0x1.d1309cp+62f
-        return fputil::round_result_slightly_up(0x1.5c9442p+5f);
-      case 0x65d8'90d3U: // x = 0x1.b121a6p+76f
-        return fputil::round_result_slightly_down(0x1.a9a3f2p+5f);
-      case 0x6f31'a8ecU: // x = 0x1.6351d8p+95f
-        return fputil::round_result_slightly_down(0x1.08b512p+6f);
-      case 0x7a17'f30aU: // x = 0x1.2fe614p+117f
-        return fputil::round_result_slightly_up(0x1.451436p+6f);
-#ifndef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
-      case 0x58f1'9e31U: // x = 0x1.e33c62p+50f
-        return fputil::round_result_slightly_down(0x1.1a576cp+5f);
-      case 0x665e'7ca6U: // x = 0x1.bcf94cp+77f
-        return fputil::round_result_slightly_up(0x1.af66cp+5f);
-      case 0x79e7'ec37U: // x = 0x1.cfd86ep+116f
-        return fputil::round_result_slightly_up(0x1.43ff6ep+6f);
-#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
-      }
-    }
-  } else {
-    if (LIBC_UNLIKELY(x_u == 0x3efd'81adU)) // x = 0x1.fb035ap-2f
-      return fputil::round_result_slightly_up(0x1.9bddc2p-2f);
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  }
-
-  double r = acoshf_internal::log_eval(xd + 1.0);
-  return static_cast<float>(r);
-}
+using LIBC_MATH_LOG1PF_IMPL::log1pf;
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
+#undef LIBC_MATH_LOG1PF_IMPL
+
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG1PF_H
diff --git a/libc/src/__support/math/log1pf_double_eval.h b/libc/src/__support/math/log1pf_double_eval.h
new file mode 100644
index 00000000000000..c21a72bb6b29bf
--- /dev/null
+++ b/libc/src/__support/math/log1pf_double_eval.h
@@ -0,0 +1,150 @@
+//===-- Double-precision implementation of log1pf ---------------*- 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_LOG1PF_DOUBLE_EVAL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOG1PF_DOUBLE_EVAL_H
+
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FMA.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.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" // LIBC_UNLIKELY
+#include "src/__support/macros/properties/cpu_features.h"
+#include "src/__support/math/acoshf_utils.h"
+
+// This is an algorithm for log(1+x) in single precision which is
+// correctly rounded for all rounding modes.
+// - An exhaustive test show that when x >= 2^45, log1pf(x) == logf(x)
+// for all rounding modes.
+// - When 2^(-6) <= |x| < 2^45, the sum (double(x) + 1.0) is exact,
+// so we can adapt the correctly rounded algorithm of logf to compute
+// log(double(x) + 1.0) correctly.  For more information about the logf
+// algorithm, see `libc/src/math/generic/logf.cpp`.
+// - When |x| < 2^(-6), we use a degree-8 polynomial in double precision
+// generated with Sollya using the following command:
+//   fpminimax(log(1 + x)/x, 7, [|D...|], [-2^-6; 2^-6]);
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+namespace double_eval {
+
+LIBC_INLINE float log1pf(float x) {
+  using FPBits = typename fputil::FPBits<float>;
+  FPBits xbits(x);
+  uint32_t x_u = xbits.uintval();
+  uint32_t x_a = x_u & 0x7fff'ffffU;
+  double xd = static_cast<double>(x);
+
+  if (x_a <= 0x3c80'0000U) {
+    // |x| <= 2^-6.
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+    // Hard-to round cases.
+    switch (x_u) {
+    case 0x3540'0003U: // x = 0x1.800006p-21f
+      return fputil::round_result_slightly_down(0x1.7ffffep-21f);
+    case 0x3710'001bU: // x = 0x1.200036p-17f
+      return fputil::round_result_slightly_down(0x1.1fffe6p-17f);
+    case 0xb53f'fffdU: // x = -0x1.7ffffap-21
+      return fputil::round_result_slightly_down(-0x1.800002p-21f);
+    case 0xb70f'ffe5U: // x = -0x1.1fffcap-17
+      return fputil::round_result_slightly_down(-0x1.20001ap-17f);
+    case 0xbb0e'c8c4U: // x = -0x1.1d9188p-9
+      return fputil::round_result_slightly_up(-0x1.1de14ap-9f);
+    }
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
+    // Polynomial generated by Sollya with:
+    // > P = fpminimax(log(1 + x)/x, 7, [|D...|], [-2^-6; 2^-6]);
+    // > dirtyinfnorm((log(1 + x) - x*P)/log(1 + x), [-2^-6, 2^-6]);
+    // 0x1.1447755e54a327941f7db7316f8dcd7cf33d15ffp-58
+    constexpr double COEFFS[7] = {-0x1.0000000000000p-1, 0x1.5555555556aadp-2,
+                                  -0x1.000000000181ap-2, 0x1.999998998124ep-3,
+                                  -0x1.55555452e2a2bp-3, 0x1.24adb8cde4aa7p-3,
+                                  -0x1.0019db915ef6fp-3};
+
+    double xsq = xd * xd;
+    double c0 = fputil::multiply_add(xd, COEFFS[1], COEFFS[0]);
+    double c1 = fputil::multiply_add(xd, COEFFS[3], COEFFS[2]);
+    double c2 = fputil::multiply_add(xd, COEFFS[5], COEFFS[4]);
+    double x4 = xsq * xsq;
+    double d0 = fputil::multiply_add(xsq, c1, c0);
+    double d1 = fputil::multiply_add(xsq, COEFFS[6], c2);
+    double d2 = fputil::multiply_add(x4, d1, d0);
+    double r = fputil::multiply_add(xsq, d2, xd);
+
+    return static_cast<float>(r);
+  }
+
+  // Use log1p(x) = log(1 + x) for |x| > 2^-6;
+
+  // Check for exceptional cases.
+  if (x_a >= 0x3f80'0000) {
+    // |x| >= 1.
+    if (LIBC_UNLIKELY(x_u >= 0x7f80'0000)) {
+      // x is inf, nan, or x <= -1.
+      if (x == -1.0f) {
+        // x = -1
+        fputil::set_errno_if_required(ERANGE);
+        fputil::raise_except_if_required(FE_DIVBYZERO);
+        return FPBits::inf(Sign::NEG).get_val();
+      }
+      if (xbits.is_signaling_nan() || x < 1.0f) {
+        // x is signaling NaNs or x < -1
+        if (x < 1.0f)
+          fputil::set_errno_if_required(EDOM);
+        fputil::raise_except_if_required(FE_INVALID);
+        return fputil::FPBits<float>::quiet_nan().get_val();
+      }
+      // x is +inf or quiet NaN
+      return x;
+    }
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+    // Filter hard-to-round cases:
+    if (LIBC_UNLIKELY(x >= 0x1.30bf04p+43f)) {
+      switch (x_u) {
+      case 0x5518'5f82U: // x = 0x1.30bf04p+43f
+        return fputil::round_result_slightly_up(0x1.dfac9p+4f);
+      case 0x5cd6'9e88U: // x = 0x1.ad3d1p+58f
+        return fputil::round_result_slightly_up(0x1.45c146p+5f);
+      case 0x5ee8'984eU: // x = 0x1.d1309cp+62f
+        return fputil::round_result_slightly_up(0x1.5c9442p+5f);
+      case 0x65d8'90d3U: // x = 0x1.b121a6p+76f
+        return fputil::round_result_slightly_down(0x1.a9a3f2p+5f);
+      case 0x6f31'a8ecU: // x = 0x1.6351d8p+95f
+        return fputil::round_result_slightly_down(0x1.08b512p+6f);
+      case 0x7a17'f30aU: // x = 0x1.2fe614p+117f
+        return fputil::round_result_slightly_up(0x1.451436p+6f);
+#ifndef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+      case 0x58f1'9e31U: // x = 0x1.e33c62p+50f
+        return fputil::round_result_slightly_down(0x1.1a576cp+5f);
+      case 0x665e'7ca6U: // x = 0x1.bcf94cp+77f
+        return fputil::round_result_slightly_up(0x1.af66cp+5f);
+      case 0x79e7'ec37U: // x = 0x1.cfd86ep+116f
+        return fputil::round_result_slightly_up(0x1.43ff6ep+6f);
+#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+      }
+    }
+  } else {
+    if (LIBC_UNLIKELY(x_u == 0x3efd'81adU)) // x = 0x1.fb035ap-2f
+      return fputil::round_result_slightly_up(0x1.9bddc2p-2f);
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+  }
+
+  double r = acoshf_internal::log_eval(xd + 1.0);
+  return static_cast<float>(r);
+}
+
+} // namespace double_eval
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG1PF_DOUBLE_EVAL_H
diff --git a/libc/src/__support/math/log2f.h b/libc/src/__support/math/log2f.h
index 5e7fb902ef9961..294f1c253309f1 100644
--- a/libc/src/__support/math/log2f.h
+++ b/libc/src/__support/math/log2f.h
@@ -1,133 +1,33 @@
-//===-- Implementation header for log2f -------------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for log2f.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOG2F_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LOG2F_H
 
-#include "common_constants.h" // Lookup table for (1/f)
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/PolyEval.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" // LIBC_UNLIKELY
-
-// This is a correctly-rounded algorithm for log2(x) in single precision with
-// round-to-nearest, tie-to-even mode from the RLIBM project at:
-// https://people.cs.rutgers.edu/~sn349/rlibm
-
-// Step 1 - Range reduction:
-//   For x = 2^m * 1.mant, log2(x) = m + log2(1.m)
-//   If x is denormal, convert its integer significand to float exactly and
-//   account for the 2^-149 subnormal scale in m.
-
-// Step 2 - Another range reduction:
-//   To compute log(1.mant), let f be the highest 8 bits including the hidden
-// bit, and d be the difference (1.mant - f), i.e. the remaining 16 bits of the
-// mantissa. Then we have the following approximation formula:
-//   log2(1.mant) = log2(f) + log2(1.mant / f)
-//                = log2(f) + log2(1 + d/f)
-//                ~ log2(f) + P(d/f)
-// since d/f is sufficiently small.
-//   log2(f) and 1/f are then stored in two 2^7 = 128 entries look-up tables.
+#include "src/__support/math/log2f_double_eval.h"
 
-// Step 3 - Polynomial approximation:
-//   To compute P(d/f), we use a single degree-5 polynomial in double precision
-// which provides correct rounding for all but few exception values.
-//   For more detail about how this polynomial is obtained, please refer to the
-// papers:
-//   Lim, J. and Nagarakatte, S., "One Polynomial Approximation to Produce
-// Correctly Rounded Results of an Elementary Function for Multiple
-// Representations and Rounding Modes", Proceedings of the 49th ACM SIGPLAN
-// Symposium on Principles of Programming Languages (POPL-2022), Philadelphia,
-// USA, Jan. 16-22, 2022.
-// https://people.cs.rutgers.edu/~sn349/papers/rlibmall-popl-2022.pdf
-//   Aanjaneya, M., Lim, J., and Nagarakatte, S., "RLibm-Prog: Progressive
-// Polynomial Approximations for Fast Correctly Rounded Math Libraries",
-// Dept. of Comp. Sci., Rutgets U., Technical Report DCS-TR-758, Nov. 2021.
-// https://arxiv.org/pdf/2111.12852.pdf.
+#define LIBC_MATH_LOG2F_IMPL double_eval
 
 namespace LIBC_NAMESPACE_DECL {
-
 namespace math {
 
-LIBC_INLINE float log2f(float x) {
-  using namespace common_constants_internal;
-  using FPBits = typename fputil::FPBits<float>;
-
-  FPBits xbits(x);
-  uint32_t x_u = xbits.uintval();
-
-  // Hard to round value(s).
-  using fputil::round_result_slightly_up;
-
-  int m = -FPBits::EXP_BIAS;
-
-  // log2(1.0f) = 0.0f.
-  if (LIBC_UNLIKELY(x_u == 0x3f80'0000U))
-    return 0.0f;
-
-  // Exceptional inputs.
-  if (LIBC_UNLIKELY(x_u < FPBits::min_normal().uintval() ||
-                    x_u > FPBits::max_normal().uintval())) {
-    if (x == 0.0f) {
-      fputil::set_errno_if_required(ERANGE);
-      fputil::raise_except_if_required(FE_DIVBYZERO);
-      return FPBits::inf(Sign::NEG).get_val();
-    }
-    if (xbits.is_neg() && !xbits.is_nan()) {
-      fputil::set_errno_if_required(EDOM);
-      fputil::raise_except_if_required(FE_INVALID);
-      return FPBits::quiet_nan().get_val();
-    }
-    if (xbits.is_inf_or_nan()) {
-      return x;
-    }
-    // Normalize denormal inputs.
-    xbits = FPBits(static_cast<float>(static_cast<int32_t>(x_u)));
-    m -= 149;
-  }
-
-  m += xbits.get_biased_exponent();
-  int index = xbits.get_mantissa() >> 16;
-  // Set bits to 1.m
-  xbits.set_biased_exponent(0x7F);
-
-  float u = xbits.get_val();
-#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-  double v =
-      static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.
-#else
-  double v =
-      fputil::multiply_add(static_cast<double>(u), RD[index], -1.0); // Exact
-#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
-
-  double extra_factor = static_cast<double>(m) + LOG2_R[index];
-
-  // Degree-5 polynomial approximation of log2 generated by Sollya with:
-  // > P = fpminimax(log2(1 + x)/x, 4, [|1, D...|], [-2^-8, 2^-7]);
-  constexpr double COEFFS[5] = {0x1.71547652b8133p0, -0x1.71547652d1e33p-1,
-                                0x1.ec70a098473dep-2, -0x1.7154c5ccdf121p-2,
-                                0x1.2514fd90a130ap-2};
-
-  double vsq = v * v; // Exact
-  double c0 = fputil::multiply_add(v, COEFFS[0], extra_factor);
-  double c1 = fputil::multiply_add(v, COEFFS[2], COEFFS[1]);
-  double c2 = fputil::multiply_add(v, COEFFS[4], COEFFS[3]);
-
-  double r = fputil::polyeval(vsq, c0, c1, c2);
-
-  return static_cast<float>(r);
-}
+using LIBC_MATH_LOG2F_IMPL::log2f;
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
+#undef LIBC_MATH_LOG2F_IMPL
+
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG2F_H
diff --git a/libc/src/__support/math/log2f_double_eval.h b/libc/src/__support/math/log2f_double_eval.h
new file mode 100644
index 00000000000000..7b7868a9a33a43
--- /dev/null
+++ b/libc/src/__support/math/log2f_double_eval.h
@@ -0,0 +1,132 @@
+//===-- Double-precision implementation of log2f ----------------*- 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_LOG2F_DOUBLE_EVAL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOG2F_DOUBLE_EVAL_H
+
+#include "common_constants.h" // Lookup table for (1/f)
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.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" // LIBC_UNLIKELY
+#include "src/__support/macros/properties/cpu_features.h"
+
+// This is a correctly-rounded algorithm for log2(x) in single precision with
+// round-to-nearest, tie-to-even mode from the RLIBM project at:
+// https://people.cs.rutgers.edu/~sn349/rlibm
+
+// Step 1 - Range reduction:
+//   For x = 2^m * 1.mant, log2(x) = m + log2(1.m)
+//   If x is denormal, convert its integer significand to float exactly and
+//   account for the 2^-149 subnormal scale in m.
+
+// Step 2 - Another range reduction:
+//   To compute log(1.mant), let f be the highest 8 bits including the hidden
+// bit, and d be the difference (1.mant - f), i.e. the remaining 16 bits of the
+// mantissa. Then we have the following approximation formula:
+//   log2(1.mant) = log2(f) + log2(1.mant / f)
+//                = log2(f) + log2(1 + d/f)
+//                ~ log2(f) + P(d/f)
+// since d/f is sufficiently small.
+//   log2(f) and 1/f are then stored in two 2^7 = 128 entries look-up tables.
+
+// Step 3 - Polynomial approximation:
+//   To compute P(d/f), we use a single degree-5 polynomial in double precision
+// which provides correct rounding for all but few exception values.
+//   For more detail about how this polynomial is obtained, please refer to the
+// papers:
+//   Lim, J. and Nagarakatte, S., "One Polynomial Approximation to Produce
+// Correctly Rounded Results of an Elementary Function for Multiple
+// Representations and Rounding Modes", Proceedings of the 49th ACM SIGPLAN
+// Symposium on Principles of Programming Languages (POPL-2022), Philadelphia,
+// USA, Jan. 16-22, 2022.
+// https://people.cs.rutgers.edu/~sn349/papers/rlibmall-popl-2022.pdf
+//   Aanjaneya, M., Lim, J., and Nagarakatte, S., "RLibm-Prog: Progressive
+// Polynomial Approximations for Fast Correctly Rounded Math Libraries",
+// Dept. of Comp. Sci., Rutgets U., Technical Report DCS-TR-758, Nov. 2021.
+// https://arxiv.org/pdf/2111.12852.pdf.
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+namespace double_eval {
+
+LIBC_INLINE float log2f(float x) {
+  using namespace common_constants_internal;
+  using FPBits = typename fputil::FPBits<float>;
+
+  FPBits xbits(x);
+  uint32_t x_u = xbits.uintval();
+
+  int m = -FPBits::EXP_BIAS;
+
+  // log2(1.0f) = 0.0f.
+  if (LIBC_UNLIKELY(x_u == 0x3f80'0000U))
+    return 0.0f;
+
+  // Exceptional inputs.
+  if (LIBC_UNLIKELY(x_u < FPBits::min_normal().uintval() ||
+                    x_u > FPBits::max_normal().uintval())) {
+    if (x == 0.0f) {
+      fputil::set_errno_if_required(ERANGE);
+      fputil::raise_except_if_required(FE_DIVBYZERO);
+      return FPBits::inf(Sign::NEG).get_val();
+    }
+    if (xbits.is_neg() && !xbits.is_nan()) {
+      fputil::set_errno_if_required(EDOM);
+      fputil::raise_except_if_required(FE_INVALID);
+      return FPBits::quiet_nan().get_val();
+    }
+    if (xbits.is_inf_or_nan()) {
+      return x;
+    }
+    // Normalize denormal inputs.
+    xbits = FPBits(static_cast<float>(static_cast<int32_t>(x_u)));
+    m -= 149;
+  }
+
+  m += xbits.get_biased_exponent();
+  int index = xbits.get_mantissa() >> 16;
+  // Set bits to 1.m
+  xbits.set_biased_exponent(0x7F);
+
+  float u = xbits.get_val();
+#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
+  double v =
+      static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.
+#else
+  double v =
+      fputil::multiply_add(static_cast<double>(u), RD[index], -1.0); // Exact
+#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
+
+  double extra_factor = static_cast<double>(m) + LOG2_R[index];
+
+  // Degree-5 polynomial approximation of log2 generated by Sollya with:
+  // > P = fpminimax(log2(1 + x)/x, 4, [|1, D...|], [-2^-8, 2^-7]);
+  constexpr double COEFFS[5] = {0x1.71547652b8133p0, -0x1.71547652d1e33p-1,
+                                0x1.ec70a098473dep-2, -0x1.7154c5ccdf121p-2,
+                                0x1.2514fd90a130ap-2};
+
+  double vsq = v * v; // Exact
+  double c0 = fputil::multiply_add(v, COEFFS[0], extra_factor);
+  double c1 = fputil::multiply_add(v, COEFFS[2], COEFFS[1]);
+  double c2 = fputil::multiply_add(v, COEFFS[4], COEFFS[3]);
+
+  double r = fputil::polyeval(vsq, c0, c1, c2);
+
+  return static_cast<float>(r);
+}
+
+} // namespace double_eval
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG2F_DOUBLE_EVAL_H
diff --git a/libc/src/__support/math/logf.h b/libc/src/__support/math/logf.h
index 09baa283cb1207..5cdc77b7a11f13 100644
--- a/libc/src/__support/math/logf.h
+++ b/libc/src/__support/math/logf.h
@@ -1,192 +1,33 @@
-//===-- Single-precision log(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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for logf.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOGF_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LOGF_H
 
-#include "common_constants.h" // Lookup table for (1/f) and log(f)
-#include "src/__support/FPUtil/FEnvImpl.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/PolyEval.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" // LIBC_UNLIKELY
-#include "src/__support/macros/properties/cpu_features.h"
-
-// This is an algorithm for log(x) in single precision which is correctly
-// rounded for all rounding modes, based on the implementation of log(x) from
-// the RLIBM project at:
-// https://people.cs.rutgers.edu/~sn349/rlibm
-
-// Step 1 - Range reduction:
-//   For x = 2^m * 1.mant, log(x) = m * log(2) + log(1.m)
-//   If x is denormal, we normalize it by multiplying x by 2^23 and subtracting
-//   m by 23.
-
-// Step 2 - Another range reduction:
-//   To compute log(1.mant), let f be the highest 8 bits including the hidden
-// bit, and d be the difference (1.mant - f), i.e. the remaining 16 bits of the
-// mantissa. Then we have the following approximation formula:
-//   log(1.mant) = log(f) + log(1.mant / f)
-//               = log(f) + log(1 + d/f)
-//               ~ log(f) + P(d/f)
-// since d/f is sufficiently small.
-//   log(f) and 1/f are then stored in two 2^7 = 128 entries look-up tables.
+#include "src/__support/math/logf_double_eval.h"
 
-// Step 3 - Polynomial approximation:
-//   To compute P(d/f), we use a single degree-5 polynomial in double precision
-// which provides correct rounding for all but few exception values.
-//   For more detail about how this polynomial is obtained, please refer to the
-// paper:
-//   Lim, J. and Nagarakatte, S., "One Polynomial Approximation to Produce
-// Correctly Rounded Results of an Elementary Function for Multiple
-// Representations and Rounding Modes", Proceedings of the 49th ACM SIGPLAN
-// Symposium on Principles of Programming Languages (POPL-2022), Philadelphia,
-// USA, January 16-22, 2022.
-// https://people.cs.rutgers.edu/~sn349/papers/rlibmall-popl-2022.pdf
+#define LIBC_MATH_LOGF_IMPL double_eval
 
 namespace LIBC_NAMESPACE_DECL {
-
 namespace math {
 
-LIBC_INLINE float logf(float x) {
-  using namespace common_constants_internal;
-  constexpr double LOG_2 = 0x1.62e42fefa39efp-1;
-  using FPBits = typename fputil::FPBits<float>;
-
-  FPBits xbits(x);
-  uint32_t x_u = xbits.uintval();
-
-  int m = -FPBits::EXP_BIAS;
-
-  using fputil::round_result_slightly_down;
-  using fputil::round_result_slightly_up;
-
-  // Small inputs
-  if (x_u < 0x4c5d65a5U) {
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-    // Hard-to-round cases.
-    switch (x_u) {
-    case 0x3f7f4d6fU: // x = 0x1.fe9adep-1f
-      return round_result_slightly_up(-0x1.659ec8p-9f);
-    case 0x41178febU: // x = 0x1.2f1fd6p+3f
-      return round_result_slightly_up(0x1.1fcbcep+1f);
-#ifdef LIBC_TARGET_CPU_HAS_FMA
-    case 0x3f800000U: // x = 1.0f
-      return 0.0f;
-#else
-    case 0x1e88452dU: // x = 0x1.108a5ap-66f
-      return round_result_slightly_up(-0x1.6d7b18p+5f);
-#endif // LIBC_TARGET_CPU_HAS_FMA
-    }
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-    // Subnormal inputs.
-    if (LIBC_UNLIKELY(x_u < FPBits::min_normal().uintval())) {
-      if (x == 0.0f) {
-        // Return -inf and raise FE_DIVBYZERO
-        fputil::set_errno_if_required(ERANGE);
-        fputil::raise_except_if_required(FE_DIVBYZERO);
-        return FPBits::inf(Sign::NEG).get_val();
-      }
-      // Normalize denormal inputs.
-      xbits = FPBits(xbits.get_val() * 0x1.0p23f);
-      m -= 23;
-      x_u = xbits.uintval();
-    }
-  } else {
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-    // Hard-to-round cases.
-    switch (x_u) {
-    case 0x4c5d65a5U: // x = 0x1.bacb4ap+25f
-      return round_result_slightly_down(0x1.1e0696p+4f);
-    case 0x65d890d3U: // x = 0x1.b121a6p+76f
-      return round_result_slightly_down(0x1.a9a3f2p+5f);
-    case 0x6f31a8ecU: // x = 0x1.6351d8p+95f
-      return round_result_slightly_down(0x1.08b512p+6f);
-    case 0x7a17f30aU: // x = 0x1.2fe614p+117f
-      return round_result_slightly_up(0x1.451436p+6f);
-#ifndef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
-    case 0x500ffb03U: // x = 0x1.1ff606p+33f
-      return round_result_slightly_up(0x1.6fdd34p+4f);
-    case 0x5cd69e88U: // x = 0x1.ad3d1p+58f
-      return round_result_slightly_up(0x1.45c146p+5f);
-    case 0x5ee8984eU: // x = 0x1.d1309cp+62f;
-      return round_result_slightly_up(0x1.5c9442p+5f);
-#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
-    }
-#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-    // Exceptional inputs.
-    if (LIBC_UNLIKELY(x_u > FPBits::max_normal().uintval())) {
-      if (x_u == 0x8000'0000U) {
-        // Return -inf and raise FE_DIVBYZERO
-        fputil::set_errno_if_required(ERANGE);
-        fputil::raise_except_if_required(FE_DIVBYZERO);
-        return FPBits::inf(Sign::NEG).get_val();
-      }
-      if (xbits.is_neg() && !xbits.is_nan()) {
-        // Return NaN and raise FE_INVALID
-        fputil::set_errno_if_required(EDOM);
-        fputil::raise_except_if_required(FE_INVALID);
-        return FPBits::quiet_nan().get_val();
-      }
-      // x is +inf or nan
-      if (xbits.is_signaling_nan()) {
-        fputil::raise_except_if_required(FE_INVALID);
-        return FPBits::quiet_nan().get_val();
-      }
-
-      return x;
-    }
-  }
-
-#ifndef LIBC_TARGET_CPU_HAS_FMA
-  // Returning the correct +0 when x = 1.0 for non-FMA targets with FE_DOWNWARD
-  // rounding mode.
-  if (LIBC_UNLIKELY((x_u & 0x007f'ffffU) == 0))
-    return static_cast<float>(
-        static_cast<double>(m + xbits.get_biased_exponent()) * LOG_2);
-#endif // LIBC_TARGET_CPU_HAS_FMA
-
-  uint32_t mant = xbits.get_mantissa();
-  // Extract 7 leading fractional bits of the mantissa
-  int index = mant >> 16;
-  // Add unbiased exponent. Add an extra 1 if the 7 leading fractional bits are
-  // all 1's.
-  m += static_cast<int>((x_u + (1 << 16)) >> 23);
-
-  // Set bits to 1.m
-  xbits.set_biased_exponent(0x7F);
-
-  float u = xbits.get_val();
-  double v = 0.0;
-#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
-  v = static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.
-#else
-  v = fputil::multiply_add(static_cast<double>(u), RD[index], -1.0); // Exact
-#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
-
-  // Degree-5 polynomial approximation of log generated by Sollya with:
-  // > P = fpminimax(log(1 + x)/x, 4, [|1, D...|], [-2^-8, 2^-7]);
-  constexpr double COEFFS[4] = {-0x1.000000000fe63p-1, 0x1.555556e963c16p-2,
-                                -0x1.000028dedf986p-2, 0x1.966681bfda7f7p-3};
-  double v2 = v * v; // Exact
-  double p2 = fputil::multiply_add(v, COEFFS[3], COEFFS[2]);
-  double p1 = fputil::multiply_add(v, COEFFS[1], COEFFS[0]);
-  double p0 = LOG_R[index] + v;
-  double r = fputil::multiply_add(static_cast<double>(m), LOG_2,
-                                  fputil::polyeval(v2, p0, p1, p2));
-  return static_cast<float>(r);
-}
+using LIBC_MATH_LOGF_IMPL::logf;
 
 } // namespace math
-
 } // namespace LIBC_NAMESPACE_DECL
 
+#undef LIBC_MATH_LOGF_IMPL
+
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOGF_H
diff --git a/libc/src/__support/math/logf_double_eval.h b/libc/src/__support/math/logf_double_eval.h
new file mode 100644
index 00000000000000..a2c121c8978afb
--- /dev/null
+++ b/libc/src/__support/math/logf_double_eval.h
@@ -0,0 +1,192 @@
+//===-- Double-precision implementation of logf -----------------*- 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_LOGF_DOUBLE_EVAL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_LOGF_DOUBLE_EVAL_H
+
+#include "common_constants.h" // Lookup table for (1/f) and log(f)
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.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" // LIBC_UNLIKELY
+#include "src/__support/macros/properties/cpu_features.h"
+
+// This is an algorithm for log(x) in single precision which is correctly
+// rounded for all rounding modes, based on the implementation of log(x) from
+// the RLIBM project at:
+// https://people.cs.rutgers.edu/~sn349/rlibm
+
+// Step 1 - Range reduction:
+//   For x = 2^m * 1.mant, log(x) = m * log(2) + log(1.m)
+//   If x is denormal, we normalize it by multiplying x by 2^23 and subtracting
+//   m by 23.
+
+// Step 2 - Another range reduction:
+//   To compute log(1.mant), let f be the highest 8 bits including the hidden
+// bit, and d be the difference (1.mant - f), i.e. the remaining 16 bits of the
+// mantissa. Then we have the following approximation formula:
+//   log(1.mant) = log(f) + log(1.mant / f)
+//               = log(f) + log(1 + d/f)
+//               ~ log(f) + P(d/f)
+// since d/f is sufficiently small.
+//   log(f) and 1/f are then stored in two 2^7 = 128 entries look-up tables.
+
+// Step 3 - Polynomial approximation:
+//   To compute P(d/f), we use a single degree-5 polynomial in double precision
+// which provides correct rounding for all but few exception values.
+//   For more detail about how this polynomial is obtained, please refer to the
+// paper:
+//   Lim, J. and Nagarakatte, S., "One Polynomial Approximation to Produce
+// Correctly Rounded Results of an Elementary Function for Multiple
+// Representations and Rounding Modes", Proceedings of the 49th ACM SIGPLAN
+// Symposium on Principles of Programming Languages (POPL-2022), Philadelphia,
+// USA, January 16-22, 2022.
+// https://people.cs.rutgers.edu/~sn349/papers/rlibmall-popl-2022.pdf
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+namespace double_eval {
+
+LIBC_INLINE float logf(float x) {
+  using namespace common_constants_internal;
+  constexpr double LOG_2 = 0x1.62e42fefa39efp-1;
+  using FPBits = typename fputil::FPBits<float>;
+
+  FPBits xbits(x);
+  uint32_t x_u = xbits.uintval();
+
+  int m = -FPBits::EXP_BIAS;
+
+  using fputil::round_result_slightly_down;
+  using fputil::round_result_slightly_up;
+
+  // Small inputs
+  if (x_u < 0x4c5d65a5U) {
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+    // Hard-to-round cases.
+    switch (x_u) {
+    case 0x3f7f4d6fU: // x = 0x1.fe9adep-1f
+      return round_result_slightly_up(-0x1.659ec8p-9f);
+    case 0x41178febU: // x = 0x1.2f1fd6p+3f
+      return round_result_slightly_up(0x1.1fcbcep+1f);
+#ifdef LIBC_TARGET_CPU_HAS_FMA
+    case 0x3f800000U: // x = 1.0f
+      return 0.0f;
+#else
+    case 0x1e88452dU: // x = 0x1.108a5ap-66f
+      return round_result_slightly_up(-0x1.6d7b18p+5f);
+#endif // LIBC_TARGET_CPU_HAS_FMA
+    }
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+    // Subnormal inputs.
+    if (LIBC_UNLIKELY(x_u < FPBits::min_normal().uintval())) {
+      if (x == 0.0f) {
+        // Return -inf and raise FE_DIVBYZERO
+        fputil::set_errno_if_required(ERANGE);
+        fputil::raise_except_if_required(FE_DIVBYZERO);
+        return FPBits::inf(Sign::NEG).get_val();
+      }
+      // Normalize denormal inputs.
+      xbits = FPBits(xbits.get_val() * 0x1.0p23f);
+      m -= 23;
+      x_u = xbits.uintval();
+    }
+  } else {
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+    // Hard-to-round cases.
+    switch (x_u) {
+    case 0x4c5d65a5U: // x = 0x1.bacb4ap+25f
+      return round_result_slightly_down(0x1.1e0696p+4f);
+    case 0x65d890d3U: // x = 0x1.b121a6p+76f
+      return round_result_slightly_down(0x1.a9a3f2p+5f);
+    case 0x6f31a8ecU: // x = 0x1.6351d8p+95f
+      return round_result_slightly_down(0x1.08b512p+6f);
+    case 0x7a17f30aU: // x = 0x1.2fe614p+117f
+      return round_result_slightly_up(0x1.451436p+6f);
+#ifndef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+    case 0x500ffb03U: // x = 0x1.1ff606p+33f
+      return round_result_slightly_up(0x1.6fdd34p+4f);
+    case 0x5cd69e88U: // x = 0x1.ad3d1p+58f
+      return round_result_slightly_up(0x1.45c146p+5f);
+    case 0x5ee8984eU: // x = 0x1.d1309cp+62f;
+      return round_result_slightly_up(0x1.5c9442p+5f);
+#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
+    }
+#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+    // Exceptional inputs.
+    if (LIBC_UNLIKELY(x_u > FPBits::max_normal().uintval())) {
+      if (x_u == 0x8000'0000U) {
+        // Return -inf and raise FE_DIVBYZERO
+        fputil::set_errno_if_required(ERANGE);
+        fputil::raise_except_if_required(FE_DIVBYZERO);
+        return FPBits::inf(Sign::NEG).get_val();
+      }
+      if (xbits.is_neg() && !xbits.is_nan()) {
+        // Return NaN and raise FE_INVALID
+        fputil::set_errno_if_required(EDOM);
+        fputil::raise_except_if_required(FE_INVALID);
+        return FPBits::quiet_nan().get_val();
+      }
+      // x is +inf or nan
+      if (xbits.is_signaling_nan()) {
+        fputil::raise_except_if_required(FE_INVALID);
+        return FPBits::quiet_nan().get_val();
+      }
+
+      return x;
+    }
+  }
+
+#ifndef LIBC_TARGET_CPU_HAS_FMA
+  // Returning the correct +0 when x = 1.0 for non-FMA targets with FE_DOWNWARD
+  // rounding mode.
+  if (LIBC_UNLIKELY((x_u & 0x007f'ffffU) == 0))
+    return static_cast<float>(
+        static_cast<double>(m + xbits.get_biased_exponent()) * LOG_2);
+#endif // LIBC_TARGET_CPU_HAS_FMA
+
+  uint32_t mant = xbits.get_mantissa();
+  // Extract 7 leading fractional bits of the mantissa
+  int index = mant >> 16;
+  // Add unbiased exponent. Add an extra 1 if the 7 leading fractional bits are
+  // all 1's.
+  m += static_cast<int>((x_u + (1 << 16)) >> 23);
+
+  // Set bits to 1.m
+  xbits.set_biased_exponent(0x7F);
+
+  float u = xbits.get_val();
+  double v = 0.0;
+#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
+  v = static_cast<double>(fputil::multiply_add(u, R[index], -1.0f)); // Exact.
+#else
+  v = fputil::multiply_add(static_cast<double>(u), RD[index], -1.0); // Exact
+#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
+
+  // Degree-5 polynomial approximation of log generated by Sollya with:
+  // > P = fpminimax(log(1 + x)/x, 4, [|1, D...|], [-2^-8, 2^-7]);
+  constexpr double COEFFS[4] = {-0x1.000000000fe63p-1, 0x1.555556e963c16p-2,
+                                -0x1.000028dedf986p-2, 0x1.966681bfda7f7p-3};
+  double v2 = v * v; // Exact
+  double p2 = fputil::multiply_add(v, COEFFS[3], COEFFS[2]);
+  double p1 = fputil::multiply_add(v, COEFFS[1], COEFFS[0]);
+  double p0 = LOG_R[index] + v;
+  double r = fputil::multiply_add(static_cast<double>(m), LOG_2,
+                                  fputil::polyeval(v2, p0, p1, p2));
+  return static_cast<float>(r);
+}
+
+} // namespace double_eval
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOGF_DOUBLE_EVAL_H
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index ba0ab3a0fd8846..7be0f192e5062c 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2441,8 +2441,10 @@ add_fp_unittest(
   SRCS
     logf_test.cpp
   DEPENDS
+    libc.hdr.fenv_macros
     libc.src.math.logf
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.math.logf_double_eval
 )
 
 add_fp_unittest(
@@ -2488,8 +2490,10 @@ add_fp_unittest(
   SRCS
     log2f_test.cpp
   DEPENDS
+    libc.hdr.fenv_macros
     libc.src.math.log2f
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.math.log2f_double_eval
 )
 
 add_fp_unittest(
@@ -2523,8 +2527,10 @@ add_fp_unittest(
   SRCS
     log10f_test.cpp
   DEPENDS
+    libc.hdr.fenv_macros
     libc.src.math.log10f
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.math.log10f_double_eval
 )
 
 add_fp_unittest(
@@ -2580,8 +2586,10 @@ add_fp_unittest(
   SRCS
     log1pf_test.cpp
   DEPENDS
+    libc.hdr.fenv_macros
     libc.src.math.log1pf
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.math.log1pf_double_eval
 )
 
 add_fp_unittest(
diff --git a/libc/test/src/math/log10f_test.cpp b/libc/test/src/math/log10f_test.cpp
index e162163b529c0b..5512715a88c4ec 100644
--- a/libc/test/src/math/log10f_test.cpp
+++ b/libc/test/src/math/log10f_test.cpp
@@ -6,10 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/macros/optimization.h"
+#include "src/__support/math/log10f_double_eval.h"
 #include "src/math/log10f.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
@@ -21,61 +23,100 @@
 #define TOLERANCE 0
 #endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 
-using LlvmLibcLog10fTest = LIBC_NAMESPACE::testing::FPTest<float>;
-
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 
-TEST_F(LlvmLibcLog10fTest, SpecialNumbers) {
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::log10f(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::log10f(inf));
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log10f(neg_inf), FE_INVALID);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log10f(0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log10f(-0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log10f(-1.0f), FE_INVALID);
-  EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::log10f(1.0f));
-}
+class Log10fTest : public LIBC_NAMESPACE::testing::FPTest<float> {
+public:
+  void test_special_numbers(float (*func)(float), bool check_exception = true) {
+    EXPECT_FP_EQ(aNaN, func(aNaN));
+    EXPECT_FP_EQ(inf, func(inf));
+    if (check_exception) {
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf), FE_INVALID);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(0.0f), FE_DIVBYZERO);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(-0.0f), FE_DIVBYZERO);
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(-1.0f), FE_INVALID);
+    } else {
+      EXPECT_FP_IS_NAN(func(neg_inf));
+      EXPECT_FP_EQ(neg_inf, func(0.0f));
+      EXPECT_FP_EQ(neg_inf, func(-0.0f));
+      EXPECT_FP_IS_NAN(func(-1.0f));
+    }
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, func(1.0f));
+  }
 
-TEST_F(LlvmLibcLog10fTest, TrickyInputs) {
-  constexpr int N = 21;
-  constexpr uint32_t INPUTS[N] = {
-      0x3f800000U /*1.0f*/,
-      0x41200000U /*10.0f*/,
-      0x42c80000U /*100.0f*/,
-      0x447a0000U /*1,000.0f*/,
-      0x461c4000U /*10,000.0f*/,
-      0x47c35000U /*100,000.0f*/,
-      0x49742400U /*1,000,000.0f*/,
-      0x4b189680U /*10,000,000.0f*/,
-      0x4cbebc20U /*100,000,000.0f*/,
-      0x4e6e6b28U /*1,000,000,000.0f*/,
-      0x501502f9U /*10,000,000,000.0f*/,
-      0x4f134f83U /*2471461632.0f*/,
-      0x7956ba5eU /*69683218960000541503257137270226944.0f*/,
-      0x08ae'a356U /*0x1.5d46acp-110f*/,
-      0x1c7d'a337U /*0x1.fb466ep-71f*/,
-      0x69c8'c583U /*0x1.918b06p+84f*/,
-      0x0efe'ee7aU /*0x1.fddcf4p-98f*/,
-      0x3f5f'de1bU /*0x1.bfbc36p-1f*/,
-      0x3f80'70d8U /*0x1.00e1bp0f*/,
-      0x120b'93dcU /*0x1.1727b8p-91f*/,
-      0x13ae'78d3U /*0x1.5cf1a6p-88f*/,
-  };
+  void test_tricky_inputs(float (*func)(float), double ulp_tolerance = 0.5,
+                          bool all_rounding = true) {
+    constexpr int N = 22;
+    constexpr uint32_t INPUTS[N] = {
+        0x3f800000U /*1.0f*/,
+        0x41200000U /*10.0f*/,
+        0x42c80000U /*100.0f*/,
+        0x447a0000U /*1,000.0f*/,
+        0x461c4000U /*10,000.0f*/,
+        0x47c35000U /*100,000.0f*/,
+        0x49742400U /*1,000,000.0f*/,
+        0x4b189680U /*10,000,000.0f*/,
+        0x4cbebc20U /*100,000,000.0f*/,
+        0x4e6e6b28U /*1,000,000,000.0f*/,
+        0x501502f9U /*10,000,000,000.0f*/,
+        0x4f134f83U /*2471461632.0f*/,
+        0x610567e4U /*0x1.0acfcp+67f*/,
+        0x7956ba5eU /*69683218960000541503257137270226944.0f*/,
+        0x08ae'a356U /*0x1.5d46acp-110f*/,
+        0x1c7d'a337U /*0x1.fb466ep-71f*/,
+        0x69c8'c583U /*0x1.918b06p+84f*/,
+        0x0efe'ee7aU /*0x1.fddcf4p-98f*/,
+        0x3f5f'de1bU /*0x1.bfbc36p-1f*/,
+        0x3f80'70d8U /*0x1.00e1bp0f*/,
+        0x120b'93dcU /*0x1.1727b8p-91f*/,
+        0x13ae'78d3U /*0x1.5cf1a6p-88f*/,
+    };
 
-  for (int i = 0; i < N; ++i) {
-    float x = FPBits(INPUTS[i]).get_val();
-    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x,
-                                   LIBC_NAMESPACE::log10f(x), TOLERANCE + 0.5);
+    for (int i = 0; i < N; ++i) {
+      float x = FPBits(INPUTS[i]).get_val();
+      if (all_rounding) {
+        EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        EXPECT_MPFR_MATCH(mpfr::Operation::Log10, x, func(x), ulp_tolerance);
+      }
+    }
   }
-}
 
-TEST_F(LlvmLibcLog10fTest, InFloatRange) {
-  constexpr uint32_t COUNT = 1'231;
-  constexpr uint32_t STEP = UINT32_MAX / COUNT;
-  for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
-    float x = FPBits(v).get_val();
-    ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x,
-                                   LIBC_NAMESPACE::log10f(x), 0.5);
+  void test_in_range(float (*func)(float), double ulp_tolerance = 0.5,
+                     bool all_rounding = true) {
+    constexpr uint32_t COUNT = 1'231;
+    constexpr uint32_t STEP = UINT32_MAX / COUNT;
+    for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+      float x = FPBits(v).get_val();
+      if (FPBits(v).is_nan() || FPBits(v).is_inf())
+        continue;
+      if (all_rounding) {
+        ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        ASSERT_MPFR_MATCH(mpfr::Operation::Log10, x, func(x), ulp_tolerance);
+      }
+    }
   }
-}
+};
+
+#define LIST_LOG10F_TESTS(suffix, func, ulp_tolerance, all_rounding,           \
+                          check_exception)                                     \
+  using LlvmLibcLog10fTest##suffix = Log10fTest;                               \
+  TEST_F(LlvmLibcLog10fTest##suffix, SpecialNumbers) {                         \
+    test_special_numbers(&func, check_exception);                              \
+  }                                                                            \
+  TEST_F(LlvmLibcLog10fTest##suffix, TrickyInputs) {                           \
+    test_tricky_inputs(&func, ulp_tolerance, all_rounding);                    \
+  }                                                                            \
+  TEST_F(LlvmLibcLog10fTest##suffix, InFloatRange) {                           \
+    test_in_range(&func, ulp_tolerance, all_rounding);                         \
+  }
+
+LIST_LOG10F_TESTS(Default, LIBC_NAMESPACE::log10f,
+                  /*ulp_tolerance=*/TOLERANCE + 0.5, /*all_rounding=*/true,
+                  /*check_exception=*/true)
+LIST_LOG10F_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::log10f,
+                  /*ulp_tolerance=*/TOLERANCE + 0.5, /*all_rounding=*/true,
+                  /*check_exception=*/true)
diff --git a/libc/test/src/math/log1pf_test.cpp b/libc/test/src/math/log1pf_test.cpp
index 07a3329ea8db39..dd7a39a7f44cb5 100644
--- a/libc/test/src/math/log1pf_test.cpp
+++ b/libc/test/src/math/log1pf_test.cpp
@@ -6,10 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/macros/optimization.h"
+#include "src/__support/math/log1pf_double_eval.h"
 #include "src/math/log1pf.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
@@ -21,67 +23,104 @@
 #define TOLERANCE 0
 #endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 
-using LlvmLibcLog1pfTest = LIBC_NAMESPACE::testing::FPTest<float>;
-
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 
-TEST_F(LlvmLibcLog1pfTest, SpecialNumbers) {
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::log1pf(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::log1pf(inf));
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log1pf(neg_inf), FE_INVALID);
-  EXPECT_FP_EQ(zero, LIBC_NAMESPACE::log1pf(0.0f));
-  EXPECT_FP_EQ(neg_zero, LIBC_NAMESPACE::log1pf(-0.0f));
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log1pf(-1.0f),
-                              FE_DIVBYZERO);
-}
+class Log1pfTest : public LIBC_NAMESPACE::testing::FPTest<float> {
+public:
+  void test_special_numbers(float (*func)(float), bool check_exception = true) {
+    EXPECT_FP_EQ(aNaN, func(aNaN));
+    EXPECT_FP_EQ(inf, func(inf));
+    EXPECT_FP_EQ(zero, func(0.0f));
+    EXPECT_FP_EQ(neg_zero, func(-0.0f));
+    if (check_exception) {
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf), FE_INVALID);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(-1.0f), FE_DIVBYZERO);
+    } else {
+      EXPECT_FP_IS_NAN(func(neg_inf));
+      EXPECT_FP_EQ(neg_inf, func(-1.0f));
+    }
+  }
 
-TEST_F(LlvmLibcLog1pfTest, TrickyInputs) {
-  constexpr int N = 28;
-  constexpr uint32_t INPUTS[N] = {
-      0x35c00006U, /*0x1.80000cp-20f*/
-      0x35400003U, /*0x1.800006p-21f*/
-      0x3640000cU, /*0x1.800018p-19f*/
-      0x36c00018U, /*0x1.80003p-18f*/
-      0x3710001bU, /*0x1.200036p-17f*/
-      0x37400030U, /*0x1.80006p-17f*/
-      0x3770004bU, /*0x1.e00096p-17f*/
-      0x3b9315c8U, /*0x1.262b9p-8f*/
-      0x3c6eb7afU, /*0x1.dd6f5ep-7f*/
-      0x3ddbfec3U, /*0x1.b7fd86p-4f*/
-      0x3efd81adU, /*0x1.fb035ap-2f*/
-      0x41078febU, /*0x1.0f1fd6p+3f*/
-      0x4cc1c80bU, /*0x1.839016p+26f*/
-      0x55185f82U, /*0x1.30bf04p+43f*/
-      0x5cd69e88U, /*0x1.ad3d1p+58f*/
-      0x5ee8984eU, /*0x1.d1309cp+62f*/
-      0x65d890d3U, /*0x1.b121a6p+76f*/
-      0x665e7ca6U, /*0x1.bcf94cp+77f*/
-      0x6f31a8ecU, /*0x1.6351d8p+95f*/
-      0x79e7ec37U, /*0x1.cfd86ep+116f*/
-      0x7a17f30aU, /*0x1.2fe614p+117f*/
-      0xb53ffffdU, /*-0x1.7ffffap-21f*/
-      0xb70fffe5U, /*-0x1.1fffcap-17f*/
-      0xbb0ec8c4U, /*-0x1.1d9188p-9f*/
-      0xbc4d092cU, /*-0x1.9a1258p-7f*/
-      0xbc657728U, /*-0x1.caee5p-7f*/
-      0xbd1d20afU, /*-0x1.3a415ep-5f*/
-      0xbf800000U, /*-1.0f*/
-  };
-  for (int i = 0; i < N; ++i) {
-    float x = FPBits(INPUTS[i]).get_val();
-    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x,
-                                   LIBC_NAMESPACE::log1pf(x), TOLERANCE + 0.5);
+  void test_tricky_inputs(float (*func)(float), double ulp_tolerance = 0.5,
+                          bool all_rounding = true) {
+    constexpr int N = 30;
+    constexpr uint32_t INPUTS[N] = {
+        0x35c00006U, /*0x1.80000cp-20f*/
+        0x35400003U, /*0x1.800006p-21f*/
+        0x3640000cU, /*0x1.800018p-19f*/
+        0x36c00018U, /*0x1.80003p-18f*/
+        0x3710001bU, /*0x1.200036p-17f*/
+        0x37400030U, /*0x1.80006p-17f*/
+        0x3770004bU, /*0x1.e00096p-17f*/
+        0x3b9315c8U, /*0x1.262b9p-8f*/
+        0x3c6eb7afU, /*0x1.dd6f5ep-7f*/
+        0x3ddbfec3U, /*0x1.b7fd86p-4f*/
+        0x3efd81adU, /*0x1.fb035ap-2f*/
+        0x41078febU, /*0x1.0f1fd6p+3f*/
+        0x4cc1c80bU, /*0x1.839016p+26f*/
+        0x55185f82U, /*0x1.30bf04p+43f*/
+        0x5cd69e88U, /*0x1.ad3d1p+58f*/
+        0x5ee8984eU, /*0x1.d1309cp+62f*/
+        0x65d890d3U, /*0x1.b121a6p+76f*/
+        0x665e7ca6U, /*0x1.bcf94cp+77f*/
+        0x6f31a8ecU, /*0x1.6351d8p+95f*/
+        0x79e7ec37U, /*0x1.cfd86ep+116f*/
+        0x7a17f30aU, /*0x1.2fe614p+117f*/
+        0xb53ffffdU, /*-0x1.7ffffap-21f*/
+        0xb5bffffaU, /*-0x1.7ffff4p-20f*/
+        0xb63ffff4U, /*-0x1.7fffe8p-19f*/
+        0xb70fffe5U, /*-0x1.1fffcap-17f*/
+        0xbb0ec8c4U, /*-0x1.1d9188p-9f*/
+        0xbc4d092cU, /*-0x1.9a1258p-7f*/
+        0xbc657728U, /*-0x1.caee5p-7f*/
+        0xbd1d20afU, /*-0x1.3a415ep-5f*/
+        0xbf800000U, /*-1.0f*/
+    };
+    for (int i = 0; i < N; ++i) {
+      float x = FPBits(INPUTS[i]).get_val();
+      if (all_rounding) {
+        EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        EXPECT_MPFR_MATCH(mpfr::Operation::Log1p, x, func(x), ulp_tolerance);
+      }
+    }
   }
-}
 
-TEST_F(LlvmLibcLog1pfTest, InFloatRange) {
-  constexpr uint32_t COUNT = 1'231;
-  constexpr uint32_t STEP = UINT32_MAX / COUNT;
-  for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
-    float x = FPBits(v).get_val();
-    if (FPBits(v).is_nan() || FPBits(v).is_inf())
-      continue;
-    ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x,
-                                   LIBC_NAMESPACE::log1pf(x), TOLERANCE + 0.5);
+  void test_in_range(float (*func)(float), double ulp_tolerance = 0.5,
+                     bool all_rounding = true) {
+    constexpr uint32_t COUNT = 1'231;
+    constexpr uint32_t STEP = UINT32_MAX / COUNT;
+    for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+      float x = FPBits(v).get_val();
+      if (FPBits(v).is_nan() || FPBits(v).is_inf())
+        continue;
+      if (all_rounding) {
+        ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        ASSERT_MPFR_MATCH(mpfr::Operation::Log1p, x, func(x), ulp_tolerance);
+      }
+    }
   }
-}
+};
+
+#define LIST_LOG1PF_TESTS(suffix, func, ulp_tolerance, all_rounding,           \
+                          check_exception)                                     \
+  using LlvmLibcLog1pfTest##suffix = Log1pfTest;                               \
+  TEST_F(LlvmLibcLog1pfTest##suffix, SpecialNumbers) {                         \
+    test_special_numbers(&func, check_exception);                              \
+  }                                                                            \
+  TEST_F(LlvmLibcLog1pfTest##suffix, TrickyInputs) {                           \
+    test_tricky_inputs(&func, ulp_tolerance, all_rounding);                    \
+  }                                                                            \
+  TEST_F(LlvmLibcLog1pfTest##suffix, InFloatRange) {                           \
+    test_in_range(&func, ulp_tolerance, all_rounding);                         \
+  }
+
+LIST_LOG1PF_TESTS(Default, LIBC_NAMESPACE::log1pf,
+                  /*ulp_tolerance=*/TOLERANCE + 0.5, /*all_rounding=*/true,
+                  /*check_exception=*/true)
+LIST_LOG1PF_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::log1pf,
+                  /*ulp_tolerance=*/TOLERANCE + 0.5, /*all_rounding=*/true,
+                  /*check_exception=*/true)
diff --git a/libc/test/src/math/log2f_test.cpp b/libc/test/src/math/log2f_test.cpp
index ce6486e3880897..072395d274021f 100644
--- a/libc/test/src/math/log2f_test.cpp
+++ b/libc/test/src/math/log2f_test.cpp
@@ -6,61 +6,96 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
+#include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/libc_errno.h"
+#include "src/__support/math/log2f_double_eval.h"
 #include "src/math/log2f.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 
-#include "hdr/stdint_proxy.h"
-
-using LlvmLibcLog2fTest = LIBC_NAMESPACE::testing::FPTest<float>;
-
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 
-TEST_F(LlvmLibcLog2fTest, SpecialNumbers) {
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::log2f(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::log2f(inf));
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log2f(neg_inf), FE_INVALID);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log2f(0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log2f(-0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log2f(-1.0f), FE_INVALID);
-  EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::log2f(1.0f));
-}
+class Log2fTest : public LIBC_NAMESPACE::testing::FPTest<float> {
+public:
+  void test_special_numbers(float (*func)(float), bool check_exception = true) {
+    EXPECT_FP_EQ(aNaN, func(aNaN));
+    EXPECT_FP_EQ(inf, func(inf));
+    if (check_exception) {
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf), FE_INVALID);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(0.0f), FE_DIVBYZERO);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(-0.0f), FE_DIVBYZERO);
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(-1.0f), FE_INVALID);
+    } else {
+      EXPECT_FP_IS_NAN(func(neg_inf));
+      EXPECT_FP_EQ(neg_inf, func(0.0f));
+      EXPECT_FP_EQ(neg_inf, func(-0.0f));
+      EXPECT_FP_IS_NAN(func(-1.0f));
+    }
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, func(1.0f));
+  }
+
+  void test_tricky_inputs(float (*func)(float), double ulp_tolerance = 0.5,
+                          bool all_rounding = true) {
+    constexpr int N = 12;
+    constexpr uint32_t INPUTS[N] = {0x28114a90U, 0x3f7d57f5U, 0x3f7e3274U,
+                                    0x3f7ed848U, 0x3f7fd6ccU, 0x3f7fffffU,
+                                    0x3f80079bU, 0x3f81d0b5U, 0x3f82e602U,
+                                    0x3f83c98dU, 0x3f8cba39U, 0x6e114a90U};
 
-TEST_F(LlvmLibcLog2fTest, TrickyInputs) {
-  constexpr int N = 10;
-  constexpr uint32_t INPUTS[N] = {
-      0x3f7d57f5U, 0x3f7e3274U, 0x3f7ed848U, 0x3f7fd6ccU, 0x3f7fffffU,
-      0x3f80079bU, 0x3f81d0b5U, 0x3f82e602U, 0x3f83c98dU, 0x3f8cba39U};
+    for (int i = 0; i < N; ++i) {
+      float x = FPBits(INPUTS[i]).get_val();
+      if (all_rounding) {
+        EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        EXPECT_MPFR_MATCH(mpfr::Operation::Log2, x, func(x), ulp_tolerance);
+      }
+    }
+  }
 
-  for (int i = 0; i < N; ++i) {
-    float x = FPBits(INPUTS[i]).get_val();
-    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x,
-                                   LIBC_NAMESPACE::log2f(x), 0.5);
+  void test_in_range(float (*func)(float), double ulp_tolerance = 0.5,
+                     bool all_rounding = true, bool check_errno = true) {
+    constexpr uint32_t COUNT = 1'231;
+    constexpr uint32_t STEP = UINT32_MAX / COUNT;
+    for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+      float x = FPBits(v).get_val();
+      if (FPBits(v).is_nan() || FPBits(v).is_inf())
+        continue;
+      libc_errno = 0;
+      float result = func(x);
+      if (FPBits(result).is_nan() || FPBits(result).is_inf() ||
+          (check_errno && libc_errno != 0))
+        continue;
+      if (all_rounding) {
+        ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        ASSERT_MPFR_MATCH(mpfr::Operation::Log2, x, result, ulp_tolerance);
+      }
+    }
   }
-}
+};
 
-TEST_F(LlvmLibcLog2fTest, InFloatRange) {
-  constexpr uint32_t COUNT = 1'231;
-  constexpr uint32_t STEP = UINT32_MAX / COUNT;
-  for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
-    float x = FPBits(v).get_val();
-    if (FPBits(v).is_nan() || FPBits(v).is_inf())
-      continue;
-    libc_errno = 0;
-    float result = LIBC_NAMESPACE::log2f(x);
-    // If the computation resulted in an error or did not produce valid result
-    // in the single-precision floating point range, then ignore comparing with
-    // MPFR result as MPFR can still produce valid results because of its
-    // wider precision.
-    if (FPBits(result).is_nan() || FPBits(result).is_inf() || libc_errno != 0)
-      continue;
-    ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x,
-                                   LIBC_NAMESPACE::log2f(x), 0.5);
+#define LIST_LOG2F_TESTS(suffix, func, ulp_tolerance, all_rounding,            \
+                         check_exception, check_errno)                         \
+  using LlvmLibcLog2fTest##suffix = Log2fTest;                                 \
+  TEST_F(LlvmLibcLog2fTest##suffix, SpecialNumbers) {                          \
+    test_special_numbers(&func, check_exception);                              \
+  }                                                                            \
+  TEST_F(LlvmLibcLog2fTest##suffix, TrickyInputs) {                            \
+    test_tricky_inputs(&func, ulp_tolerance, all_rounding);                    \
+  }                                                                            \
+  TEST_F(LlvmLibcLog2fTest##suffix, InFloatRange) {                            \
+    test_in_range(&func, ulp_tolerance, all_rounding, check_errno);            \
   }
-}
+
+LIST_LOG2F_TESTS(Default, LIBC_NAMESPACE::log2f, /*ulp_tolerance=*/0.5,
+                 /*all_rounding=*/true, /*check_exception=*/true,
+                 /*check_errno=*/true)
+LIST_LOG2F_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::log2f,
+                 /*ulp_tolerance=*/0.5, /*all_rounding=*/true,
+                 /*check_exception=*/true, /*check_errno=*/true)
diff --git a/libc/test/src/math/logf_test.cpp b/libc/test/src/math/logf_test.cpp
index 1c85222af67326..46f64a1ba47253 100644
--- a/libc/test/src/math/logf_test.cpp
+++ b/libc/test/src/math/logf_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for logf-----------------------------------------------===//
+//===-- Unittests for logf ------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/macros/optimization.h"
+#include "src/__support/math/logf_double_eval.h"
 #include "src/math/logf.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
@@ -21,80 +23,116 @@
 #define TOLERANCE 0
 #endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 
-using LlvmLibcLogfTest = LIBC_NAMESPACE::testing::FPTest<float>;
-
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 
-TEST_F(LlvmLibcLogfTest, SpecialNumbers) {
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::logf(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::logf(inf));
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::logf(neg_inf), FE_INVALID);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::logf(0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::logf(-0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::logf(-1.0f), FE_INVALID);
+class LogfTest : public LIBC_NAMESPACE::testing::FPTest<float> {
+public:
+  void test_special_numbers(float (*func)(float), bool check_exception = true) {
+    EXPECT_FP_EQ(aNaN, func(aNaN));
+    EXPECT_FP_EQ(inf, func(inf));
+    if (check_exception) {
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf), FE_INVALID);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(0.0f), FE_DIVBYZERO);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(-0.0f), FE_DIVBYZERO);
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(-1.0f), FE_INVALID);
+    } else {
+      EXPECT_FP_IS_NAN(func(neg_inf));
+      EXPECT_FP_EQ(neg_inf, func(0.0f));
+      EXPECT_FP_EQ(neg_inf, func(-0.0f));
+      EXPECT_FP_IS_NAN(func(-1.0f));
+    }
 #ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  EXPECT_TRUE(0.0f == LIBC_NAMESPACE::logf(1.0f));
+    EXPECT_TRUE(0.0f == func(1.0f));
 #else
-  EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::logf(1.0f));
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, func(1.0f));
 #endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-}
+  }
 
-TEST_F(LlvmLibcLogfTest, TrickyInputs) {
-  constexpr int N = 35;
-  constexpr uint32_t INPUTS[N] = {
-      0x1b7679ffU, /*0x1.ecf3fep-73f*/
-      0x1e88452dU, /*0x1.108a5ap-66f*/
-      0x3f800001U, /*0x1.000002p+0f*/
-      0x3509dcf6U, /*0x1.13b9ecp-21f*/
-      0x3bf86ef0U, /*0x1.f0ddep-8f*/
-      0x3c413d3aU, /*0x1.827a74p-7f*/
-      0x3ca1c99fU, /*0x1.43933ep-6f*/
-      0x3d13e105U, /*0x1.27c20ap-5f*/
-      0x3f7ff1f2U, /*0x1.ffe3e4p-1f*/
-      0x3f7fffffU, /*0x1.fffffep-1f*/
-      0x3f800001U, /*0x1.000002p+0f*/
-      0x3f800006U, /*0x1.00000cp+0f*/
-      0x3f800014U, /*0x1.000028p+0f*/
-      0x3f80001cU, /*0x1.000038p+0f*/
-      0x3f80c777U, /*0x1.018eeep+0f*/
-      0x3f80ce72U, /*0x1.019ce4p+0f*/
-      0x3f80d19fU, /*0x1.01a33ep+0f*/
-      0x3f80f7bfU, /*0x1.01ef7ep+0f*/
-      0x3f80fcfeU, /*0x1.01f9fcp+0f*/
-      0x3f81feb4U, /*0x1.03fd68p+0f*/
-      0x3f83d731U, /*0x1.07ae62p+0f*/
-      0x3f90cb1dU, /*0x1.21963ap+0f*/
-      0x3fc55379U, /*0x1.8aa6f2p+0f*/
-      0x3fd364d7U, /*0x1.a6c9aep+0f*/
-      0x41178febU, /*0x1.2f1fd6p+3f*/
-      0x4c5d65a5U, /*0x1.bacb4ap+25f*/
-      0x4e85f412U, /*0x1.0be824p+30f*/
-      0x500ffb03U, /*0x1.1ff606p+33f*/
-      0x5cd69e88U, /*0x1.ad3d1p+58f*/
-      0x5ee8984eU, /*0x1.d1309cp+62f*/
-      0x65d890d3U, /*0x1.b121a6p+76f*/
-      0x665e7ca6U, /*0x1.bcf94cp+77f*/
-      0x6f31a8ecU, /*0x1.6351d8p+95f*/
-      0x79e7ec37U, /*0x1.cfd86ep+116f*/
-      0x7a17f30aU, /*0x1.2fe614p+117f*/
-  };
-  for (int i = 0; i < N; ++i) {
-    float x = FPBits(INPUTS[i]).get_val();
-    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x,
-                                   LIBC_NAMESPACE::logf(x), TOLERANCE + 0.5);
+  void test_tricky_inputs(float (*func)(float), double ulp_tolerance = 0.5,
+                          bool all_rounding = true) {
+    constexpr int N = 35;
+    constexpr uint32_t INPUTS[N] = {
+        0x1b7679ffU, /*0x1.ecf3fep-73f*/
+        0x1e88452dU, /*0x1.108a5ap-66f*/
+        0x3f800001U, /*0x1.000002p+0f*/
+        0x3509dcf6U, /*0x1.13b9ecp-21f*/
+        0x3bf86ef0U, /*0x1.f0ddep-8f*/
+        0x3c413d3aU, /*0x1.827a74p-7f*/
+        0x3ca1c99fU, /*0x1.43933ep-6f*/
+        0x3d13e105U, /*0x1.27c20ap-5f*/
+        0x3f7ff1f2U, /*0x1.ffe3e4p-1f*/
+        0x3f7fffffU, /*0x1.fffffep-1f*/
+        0x3f800001U, /*0x1.000002p+0f*/
+        0x3f800006U, /*0x1.00000cp+0f*/
+        0x3f800014U, /*0x1.000028p+0f*/
+        0x3f80001cU, /*0x1.000038p+0f*/
+        0x3f80c777U, /*0x1.018eeep+0f*/
+        0x3f80ce72U, /*0x1.019ce4p+0f*/
+        0x3f80d19fU, /*0x1.01a33ep+0f*/
+        0x3f80f7bfU, /*0x1.01ef7ep+0f*/
+        0x3f80fcfeU, /*0x1.01f9fcp+0f*/
+        0x3f81feb4U, /*0x1.03fd68p+0f*/
+        0x3f83d731U, /*0x1.07ae62p+0f*/
+        0x3f90cb1dU, /*0x1.21963ap+0f*/
+        0x3fc55379U, /*0x1.8aa6f2p+0f*/
+        0x3fd364d7U, /*0x1.a6c9aep+0f*/
+        0x41178febU, /*0x1.2f1fd6p+3f*/
+        0x4c5d65a5U, /*0x1.bacb4ap+25f*/
+        0x4e85f412U, /*0x1.0be824p+30f*/
+        0x500ffb03U, /*0x1.1ff606p+33f*/
+        0x5cd69e88U, /*0x1.ad3d1p+58f*/
+        0x5ee8984eU, /*0x1.d1309cp+62f*/
+        0x65d890d3U, /*0x1.b121a6p+76f*/
+        0x665e7ca6U, /*0x1.bcf94cp+77f*/
+        0x6f31a8ecU, /*0x1.6351d8p+95f*/
+        0x79e7ec37U, /*0x1.cfd86ep+116f*/
+        0x7a17f30aU, /*0x1.2fe614p+117f*/
+    };
+    for (int i = 0; i < N; ++i) {
+      float x = FPBits(INPUTS[i]).get_val();
+      if (all_rounding) {
+        EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        EXPECT_MPFR_MATCH(mpfr::Operation::Log, x, func(x), ulp_tolerance);
+      }
+    }
   }
-}
 
-TEST_F(LlvmLibcLogfTest, InFloatRange) {
-  constexpr uint32_t COUNT = 1'231;
-  constexpr uint32_t STEP = UINT32_MAX / COUNT;
-  for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
-    float x = FPBits(v).get_val();
-    if (FPBits(v).is_nan() || FPBits(v).is_inf())
-      continue;
-    ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x,
-                                   LIBC_NAMESPACE::logf(x), 0.5);
+  void test_in_range(float (*func)(float), double ulp_tolerance = 0.5,
+                     bool all_rounding = true) {
+    constexpr uint32_t COUNT = 1'231;
+    constexpr uint32_t STEP = UINT32_MAX / COUNT;
+    for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+      float x = FPBits(v).get_val();
+      if (FPBits(v).is_nan() || FPBits(v).is_inf())
+        continue;
+      if (all_rounding) {
+        ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x, func(x),
+                                       ulp_tolerance);
+      } else {
+        ASSERT_MPFR_MATCH(mpfr::Operation::Log, x, func(x), ulp_tolerance);
+      }
+    }
   }
-}
+};
+
+#define LIST_LOGF_TESTS(suffix, func, ulp_tolerance, all_rounding,             \
+                        check_exception)                                       \
+  using LlvmLibcLogfTest##suffix = LogfTest;                                   \
+  TEST_F(LlvmLibcLogfTest##suffix, SpecialNumbers) {                           \
+    test_special_numbers(&func, check_exception);                              \
+  }                                                                            \
+  TEST_F(LlvmLibcLogfTest##suffix, TrickyInputs) {                             \
+    test_tricky_inputs(&func, ulp_tolerance, all_rounding);                    \
+  }                                                                            \
+  TEST_F(LlvmLibcLogfTest##suffix, InFloatRange) {                             \
+    test_in_range(&func, ulp_tolerance, all_rounding);                         \
+  }
+
+LIST_LOGF_TESTS(Default, LIBC_NAMESPACE::logf,
+                /*ulp_tolerance=*/TOLERANCE + 0.5, /*all_rounding=*/true,
+                /*check_exception=*/true)
+LIST_LOGF_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::logf,
+                /*ulp_tolerance=*/TOLERANCE + 0.5, /*all_rounding=*/true,
+                /*check_exception=*/true)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 7f2b50feaacf78..436e864342beef 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4729,8 +4729,10 @@ add_fp_unittest(
     logf_test.cpp
   DEPENDS
     libc.hdr.errno_macros
+    libc.hdr.fenv_macros
     libc.src.math.logf
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.math.logf_double_eval
 )
 
 add_fp_unittest(
@@ -4779,8 +4781,10 @@ add_fp_unittest(
     log2f_test.cpp
   DEPENDS
     libc.hdr.errno_macros
+    libc.hdr.fenv_macros
     libc.src.math.log2f
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.math.log2f_double_eval
 )
 
 add_fp_unittest(
@@ -4816,8 +4820,10 @@ add_fp_unittest(
     log10f_test.cpp
   DEPENDS
     libc.hdr.errno_macros
+    libc.hdr.fenv_macros
     libc.src.math.log10f
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.math.log10f_double_eval
 )
 
 add_fp_unittest(
@@ -4879,8 +4885,10 @@ add_fp_unittest(
     log1pf_test.cpp
   DEPENDS
     libc.hdr.errno_macros
+    libc.hdr.fenv_macros
     libc.src.math.log1pf
     libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.math.log1pf_double_eval
 )
 
 add_fp_unittest(
diff --git a/libc/test/src/math/smoke/log10f_test.cpp b/libc/test/src/math/smoke/log10f_test.cpp
index a8b4bd0e72fd79..386d86aac0dd7c 100644
--- a/libc/test/src/math/smoke/log10f_test.cpp
+++ b/libc/test/src/math/smoke/log10f_test.cpp
@@ -7,64 +7,107 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/math/log10f_double_eval.h"
 #include "src/math/log10f.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-using LlvmLibcLog10fTest = LIBC_NAMESPACE::testing::FPTest<float>;
-
-TEST_F(LlvmLibcLog10fTest, SpecialNumbers) {
-  EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::log10f(sNaN), FE_INVALID);
-  EXPECT_MATH_ERRNO(0);
-
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::log10f(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::log10f(inf));
-  EXPECT_MATH_ERRNO(0);
-
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log10f(neg_inf), FE_INVALID);
-  EXPECT_MATH_ERRNO(EDOM);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log10f(0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_MATH_ERRNO(ERANGE);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log10f(-0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_MATH_ERRNO(ERANGE);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log10f(-1.0f), FE_INVALID);
-  EXPECT_MATH_ERRNO(EDOM);
-
-  EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::log10f(1.0f));
-
-  float x = 1.0f;
-  for (int i = 0; i < 11; ++i, x *= 10.0f) {
-    EXPECT_FP_EQ_ALL_ROUNDING(static_cast<float>(i), LIBC_NAMESPACE::log10f(x));
+class Log10fTest : public LIBC_NAMESPACE::testing::FPTest<float> {
+public:
+  void test_special_numbers(float (*func)(float),
+                            bool check_snan_invalid = false,
+                            bool check_exception_and_errno = true,
+                            bool check_errno = true) {
+    if (check_snan_invalid) {
+      EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(sNaN), FE_INVALID);
+    } else {
+      EXPECT_FP_EQ(aNaN, func(sNaN));
+    }
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(aNaN, func(aNaN));
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(inf, func(inf));
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
+
+    if (check_exception_and_errno) {
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf), FE_INVALID);
+      EXPECT_MATH_ERRNO(EDOM);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(0.0f), FE_DIVBYZERO);
+      EXPECT_MATH_ERRNO(ERANGE);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(-0.0f), FE_DIVBYZERO);
+      EXPECT_MATH_ERRNO(ERANGE);
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(-1.0f), FE_INVALID);
+      EXPECT_MATH_ERRNO(EDOM);
+    } else {
+      EXPECT_FP_IS_NAN(func(neg_inf));
+      EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, func(0.0f));
+      EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, func(-0.0f));
+      EXPECT_FP_IS_NAN(func(-1.0f));
+    }
+
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, func(1.0f));
+
+    float x = 1.0f;
+    for (int i = 0; i < 11; ++i, x *= 10.0f) {
+      EXPECT_FP_EQ_ALL_ROUNDING(static_cast<float>(i), func(x));
+    }
   }
-}
 
 #ifdef LIBC_TEST_FTZ_DAZ
+  void test_ftz(float (*func)(float)) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(-0x1.66d3e7bd9a403p5f, func(d));
+  }
 
-using namespace LIBC_NAMESPACE::testing;
-
-TEST_F(LlvmLibcLog10fTest, FTZMode) {
-  ModifyMXCSR mxcsr(FTZ);
-
-  EXPECT_FP_EQ(-0x1.66d3e7bd9a403p5f, LIBC_NAMESPACE::log10f(min_denormal));
-}
-
-TEST_F(LlvmLibcLog10fTest, DAZMode) {
-  ModifyMXCSR mxcsr(DAZ);
-
-  EXPECT_FP_EQ(FPBits::inf(Sign::NEG).get_val(),
-               LIBC_NAMESPACE::log10f(min_denormal));
-}
-
-TEST_F(LlvmLibcLog10fTest, FTZDAZMode) {
-  ModifyMXCSR mxcsr(FTZ | DAZ);
+  void test_daz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::DAZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? neg_inf : -0x1.66d3e7bd9a403p5f, func(d));
+  }
 
-  EXPECT_FP_EQ(FPBits::inf(Sign::NEG).get_val(),
-               LIBC_NAMESPACE::log10f(min_denormal));
-}
+  void test_ftzdaz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ |
+                                               LIBC_NAMESPACE::testing::DAZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? neg_inf : -0x1.66d3e7bd9a403p5f, func(d));
+  }
+#endif // LIBC_TEST_FTZ_DAZ
+};
 
-#endif
+#ifdef LIBC_TEST_FTZ_DAZ
+#define LIST_LOG10F_FTZ_DAZ_TESTS(suffix, func, uses_fpu)                      \
+  TEST_F(LlvmLibcLog10fTest##suffix, FTZMode) { test_ftz(&func); }             \
+  TEST_F(LlvmLibcLog10fTest##suffix, DAZMode) { test_daz(&func, uses_fpu); }   \
+  TEST_F(LlvmLibcLog10fTest##suffix, FTZDAZMode) {                             \
+    test_ftzdaz(&func, uses_fpu);                                              \
+  }
+#else // !LIBC_TEST_FTZ_DAZ
+#define LIST_LOG10F_FTZ_DAZ_TESTS(suffix, func, uses_fpu)
+#endif // LIBC_TEST_FTZ_DAZ
+
+#define LIST_LOG10F_TESTS(suffix, func, check_snan_invalid,                    \
+                          check_exception_and_errno, check_errno, uses_fpu)    \
+  using LlvmLibcLog10fTest##suffix = Log10fTest;                               \
+  TEST_F(LlvmLibcLog10fTest##suffix, SpecialNumbers) {                         \
+    test_special_numbers(&func, check_snan_invalid, check_exception_and_errno, \
+                         check_errno);                                         \
+  }                                                                            \
+  LIST_LOG10F_FTZ_DAZ_TESTS(suffix, func, uses_fpu)
+
+LIST_LOG10F_TESTS(Default, LIBC_NAMESPACE::log10f, /*check_snan_invalid=*/true,
+                  /*check_exception_and_errno=*/true, /*check_errno=*/true,
+                  /*uses_fpu=*/true)
+LIST_LOG10F_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::log10f,
+                  /*check_snan_invalid=*/false,
+                  /*check_exception_and_errno=*/true, /*check_errno=*/true,
+                  /*uses_fpu=*/true)
diff --git a/libc/test/src/math/smoke/log1pf_test.cpp b/libc/test/src/math/smoke/log1pf_test.cpp
index 6fbeb62bfa593b..e416363b15446d 100644
--- a/libc/test/src/math/smoke/log1pf_test.cpp
+++ b/libc/test/src/math/smoke/log1pf_test.cpp
@@ -7,51 +7,100 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/math/log1pf_double_eval.h"
 #include "src/math/log1pf.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-using LlvmLibcLog1pfTest = LIBC_NAMESPACE::testing::FPTest<float>;
+class Log1pfTest : public LIBC_NAMESPACE::testing::FPTest<float> {
+public:
+  void test_special_numbers(float (*func)(float),
+                            bool check_snan_invalid = false,
+                            bool check_exception_and_errno = true,
+                            bool check_errno = true) {
+    if (check_snan_invalid) {
+      EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(sNaN), FE_INVALID);
+    } else {
+      EXPECT_FP_EQ(aNaN, func(sNaN));
+    }
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
 
-TEST_F(LlvmLibcLog1pfTest, SpecialNumbers) {
-  EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::log1pf(sNaN), FE_INVALID);
-  EXPECT_MATH_ERRNO(0);
+    EXPECT_FP_EQ_ALL_ROUNDING(aNaN, func(aNaN));
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
 
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::log1pf(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::log1pf(inf));
-  EXPECT_MATH_ERRNO(0);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log1pf(neg_inf), FE_INVALID);
-  EXPECT_MATH_ERRNO(EDOM);
-  EXPECT_FP_EQ(zero, LIBC_NAMESPACE::log1pf(0.0f));
-  EXPECT_FP_EQ(neg_zero, LIBC_NAMESPACE::log1pf(-0.0f));
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log1pf(-1.0f),
-                              FE_DIVBYZERO);
-  EXPECT_MATH_ERRNO(ERANGE);
-}
+    EXPECT_FP_EQ_ALL_ROUNDING(inf, func(inf));
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
 
-#ifdef LIBC_TEST_FTZ_DAZ
-
-using namespace LIBC_NAMESPACE::testing;
+    if (check_exception_and_errno) {
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf), FE_INVALID);
+      EXPECT_MATH_ERRNO(EDOM);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(-1.0f), FE_DIVBYZERO);
+      EXPECT_MATH_ERRNO(ERANGE);
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(-2.0f), FE_INVALID);
+      EXPECT_MATH_ERRNO(EDOM);
+    } else {
+      EXPECT_FP_IS_NAN(func(neg_inf));
+      EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, func(-1.0f));
+      EXPECT_FP_IS_NAN(func(-2.0f));
+    }
 
-TEST_F(LlvmLibcLog1pfTest, FTZMode) {
-  ModifyMXCSR mxcsr(FTZ);
+    EXPECT_FP_EQ(zero, func(0.0f));
+    EXPECT_FP_EQ(neg_zero, func(-0.0f));
+  }
 
-  EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::log1pf(min_denormal));
-}
+#ifdef LIBC_TEST_FTZ_DAZ
+  void test_ftz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? 0.0f : min_denormal, func(d));
+  }
 
-TEST_F(LlvmLibcLog1pfTest, DAZMode) {
-  ModifyMXCSR mxcsr(DAZ);
+  void test_daz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::DAZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? 0.0f : min_denormal, func(d));
+  }
 
-  EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::log1pf(min_denormal));
-}
+  void test_ftzdaz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ |
+                                               LIBC_NAMESPACE::testing::DAZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? 0.0f : min_denormal, func(d));
+  }
+#endif // LIBC_TEST_FTZ_DAZ
+};
 
-TEST_F(LlvmLibcLog1pfTest, FTZDAZMode) {
-  ModifyMXCSR mxcsr(FTZ | DAZ);
+#ifdef LIBC_TEST_FTZ_DAZ
+#define LIST_LOG1PF_FTZ_DAZ_TESTS(suffix, func, uses_fpu)                      \
+  TEST_F(LlvmLibcLog1pfTest##suffix, FTZMode) { test_ftz(&func, uses_fpu); }   \
+  TEST_F(LlvmLibcLog1pfTest##suffix, DAZMode) { test_daz(&func, uses_fpu); }   \
+  TEST_F(LlvmLibcLog1pfTest##suffix, FTZDAZMode) {                             \
+    test_ftzdaz(&func, uses_fpu);                                              \
+  }
+#else // !LIBC_TEST_FTZ_DAZ
+#define LIST_LOG1PF_FTZ_DAZ_TESTS(suffix, func, uses_fpu)
+#endif // LIBC_TEST_FTZ_DAZ
 
-  EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::log1pf(min_denormal));
-}
+#define LIST_LOG1PF_TESTS(suffix, func, check_snan_invalid,                    \
+                          check_exception_and_errno, check_errno, uses_fpu)    \
+  using LlvmLibcLog1pfTest##suffix = Log1pfTest;                               \
+  TEST_F(LlvmLibcLog1pfTest##suffix, SpecialNumbers) {                         \
+    test_special_numbers(&func, check_snan_invalid, check_exception_and_errno, \
+                         check_errno);                                         \
+  }                                                                            \
+  LIST_LOG1PF_FTZ_DAZ_TESTS(suffix, func, uses_fpu)
 
-#endif
+LIST_LOG1PF_TESTS(Default, LIBC_NAMESPACE::log1pf, /*check_snan_invalid=*/true,
+                  /*check_exception_and_errno=*/true, /*check_errno=*/true,
+                  /*uses_fpu=*/true)
+LIST_LOG1PF_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::log1pf,
+                  /*check_snan_invalid=*/false,
+                  /*check_exception_and_errno=*/true, /*check_errno=*/true,
+                  /*uses_fpu=*/true)
diff --git a/libc/test/src/math/smoke/log2f_test.cpp b/libc/test/src/math/smoke/log2f_test.cpp
index 56a46a5ad9a3c1..4de696f7d35983 100644
--- a/libc/test/src/math/smoke/log2f_test.cpp
+++ b/libc/test/src/math/smoke/log2f_test.cpp
@@ -7,56 +7,104 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/math/log2f_double_eval.h"
 #include "src/math/log2f.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-using LlvmLibcLog2fTest = LIBC_NAMESPACE::testing::FPTest<float>;
-
-TEST_F(LlvmLibcLog2fTest, SpecialNumbers) {
-  EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::log2f(sNaN), FE_INVALID);
-  EXPECT_MATH_ERRNO(0);
-
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::log2f(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::log2f(inf));
-  EXPECT_MATH_ERRNO(0);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log2f(neg_inf), FE_INVALID);
-  EXPECT_MATH_ERRNO(EDOM);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log2f(0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_MATH_ERRNO(ERANGE);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::log2f(-0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_MATH_ERRNO(ERANGE);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::log2f(-1.0f), FE_INVALID);
-  EXPECT_MATH_ERRNO(EDOM);
-  EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::log2f(1.0f));
-}
-#ifdef LIBC_TEST_FTZ_DAZ
+class Log2fTest : public LIBC_NAMESPACE::testing::FPTest<float> {
+public:
+  void test_special_numbers(float (*func)(float),
+                            bool check_snan_invalid = false,
+                            bool check_exception_and_errno = true,
+                            bool check_errno = true) {
+    if (check_snan_invalid) {
+      EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(sNaN), FE_INVALID);
+    } else {
+      EXPECT_FP_EQ(aNaN, func(sNaN));
+    }
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(aNaN, func(aNaN));
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
 
-using namespace LIBC_NAMESPACE::testing;
+    EXPECT_FP_EQ_ALL_ROUNDING(inf, func(inf));
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
 
-TEST_F(LlvmLibcLog2fTest, FTZMode) {
-  ModifyMXCSR mxcsr(FTZ);
+    if (check_exception_and_errno) {
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf), FE_INVALID);
+      EXPECT_MATH_ERRNO(EDOM);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(0.0f), FE_DIVBYZERO);
+      EXPECT_MATH_ERRNO(ERANGE);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(-0.0f), FE_DIVBYZERO);
+      EXPECT_MATH_ERRNO(ERANGE);
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(-1.0f), FE_INVALID);
+      EXPECT_MATH_ERRNO(EDOM);
+    } else {
+      EXPECT_FP_IS_NAN(func(neg_inf));
+      EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, func(0.0f));
+      EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, func(-0.0f));
+      EXPECT_FP_IS_NAN(func(-1.0f));
+    }
 
-  EXPECT_FP_EQ(-149.0f, LIBC_NAMESPACE::log2f(min_denormal));
-}
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, func(1.0f));
+    EXPECT_FP_EQ_ALL_ROUNDING(1.0f, func(2.0f));
+    EXPECT_FP_EQ_ALL_ROUNDING(-1.0f, func(0.5f));
+  }
 
-TEST_F(LlvmLibcLog2fTest, DAZMode) {
-  ModifyMXCSR mxcsr(DAZ);
+#ifdef LIBC_TEST_FTZ_DAZ
+  void test_ftz(float (*func)(float)) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(-149.0f, func(d));
+  }
 
-  EXPECT_FP_EQ(FPBits::inf(Sign::NEG).get_val(),
-               LIBC_NAMESPACE::log2f(min_denormal));
-}
+  void test_daz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::DAZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? neg_inf : -149.0f, func(d));
+  }
 
-TEST_F(LlvmLibcLog2fTest, FTZDAZMode) {
-  ModifyMXCSR mxcsr(FTZ | DAZ);
+  void test_ftzdaz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ |
+                                               LIBC_NAMESPACE::testing::DAZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? neg_inf : -149.0f, func(d));
+  }
+#endif // LIBC_TEST_FTZ_DAZ
+};
+
+#ifdef LIBC_TEST_FTZ_DAZ
+#define LIST_LOG2F_FTZ_DAZ_TESTS(suffix, func, uses_fpu)                       \
+  TEST_F(LlvmLibcLog2fTest##suffix, FTZMode) { test_ftz(&func); }              \
+  TEST_F(LlvmLibcLog2fTest##suffix, DAZMode) { test_daz(&func, uses_fpu); }    \
+  TEST_F(LlvmLibcLog2fTest##suffix, FTZDAZMode) {                              \
+    test_ftzdaz(&func, uses_fpu);                                              \
+  }
+#else // !LIBC_TEST_FTZ_DAZ
+#define LIST_LOG2F_FTZ_DAZ_TESTS(suffix, func, uses_fpu)
+#endif // LIBC_TEST_FTZ_DAZ
 
-  EXPECT_FP_EQ(FPBits::inf(Sign::NEG).get_val(),
-               LIBC_NAMESPACE::log2f(min_denormal));
-}
+#define LIST_LOG2F_TESTS(suffix, func, check_snan_invalid,                     \
+                         check_exception_and_errno, check_errno, uses_fpu)     \
+  using LlvmLibcLog2fTest##suffix = Log2fTest;                                 \
+  TEST_F(LlvmLibcLog2fTest##suffix, SpecialNumbers) {                          \
+    test_special_numbers(&func, check_snan_invalid, check_exception_and_errno, \
+                         check_errno);                                         \
+  }                                                                            \
+  LIST_LOG2F_FTZ_DAZ_TESTS(suffix, func, uses_fpu)
 
-#endif
+LIST_LOG2F_TESTS(Default, LIBC_NAMESPACE::log2f, /*check_snan_invalid=*/true,
+                 /*check_exception_and_errno=*/true, /*check_errno=*/true,
+                 /*uses_fpu=*/true)
+LIST_LOG2F_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::log2f,
+                 /*check_snan_invalid=*/false,
+                 /*check_exception_and_errno=*/true, /*check_errno=*/true,
+                 /*uses_fpu=*/true)
diff --git a/libc/test/src/math/smoke/logf_test.cpp b/libc/test/src/math/smoke/logf_test.cpp
index 893d89da9d4482..78c0ca8d293b69 100644
--- a/libc/test/src/math/smoke/logf_test.cpp
+++ b/libc/test/src/math/smoke/logf_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for logf-----------------------------------------------===//
+//===-- Unittests for logf ------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,56 +7,100 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/math/logf_double_eval.h"
 #include "src/math/logf.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-using LlvmLibcLogfTest = LIBC_NAMESPACE::testing::FPTest<float>;
-
-TEST_F(LlvmLibcLogfTest, SpecialNumbers) {
-  EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::logf(sNaN), FE_INVALID);
-  EXPECT_MATH_ERRNO(0);
-
-  EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::logf(aNaN));
-  EXPECT_FP_EQ(inf, LIBC_NAMESPACE::logf(inf));
-  EXPECT_MATH_ERRNO(0);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::logf(neg_inf), FE_INVALID);
-  EXPECT_MATH_ERRNO(EDOM);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::logf(0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_MATH_ERRNO(ERANGE);
-  EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::logf(-0.0f),
-                              FE_DIVBYZERO);
-  EXPECT_MATH_ERRNO(ERANGE);
-  EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::logf(-1.0f), FE_INVALID);
-  EXPECT_MATH_ERRNO(EDOM);
-  EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::logf(1.0f));
-}
-#ifdef LIBC_TEST_FTZ_DAZ
+class LogfTest : public LIBC_NAMESPACE::testing::FPTest<float> {
+public:
+  void test_special_numbers(float (*func)(float),
+                            bool check_snan_invalid = false,
+                            bool check_exception_and_errno = true,
+                            bool check_errno = true) {
+    if (check_snan_invalid) {
+      EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(sNaN), FE_INVALID);
+    } else {
+      EXPECT_FP_EQ(aNaN, func(sNaN));
+    }
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(aNaN, func(aNaN));
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
 
-using namespace LIBC_NAMESPACE::testing;
+    EXPECT_FP_EQ_ALL_ROUNDING(inf, func(inf));
+    if (check_errno)
+      EXPECT_MATH_ERRNO(0);
 
-TEST_F(LlvmLibcLogfTest, FTZMode) {
-  ModifyMXCSR mxcsr(FTZ);
+    if (check_exception_and_errno) {
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(neg_inf), FE_INVALID);
+      EXPECT_MATH_ERRNO(EDOM);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(0.0f), FE_DIVBYZERO);
+      EXPECT_MATH_ERRNO(ERANGE);
+      EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, func(-0.0f), FE_DIVBYZERO);
+      EXPECT_MATH_ERRNO(ERANGE);
+      EXPECT_FP_IS_NAN_WITH_EXCEPTION(func(-1.0f), FE_INVALID);
+      EXPECT_MATH_ERRNO(EDOM);
+    } else {
+      EXPECT_FP_IS_NAN(func(neg_inf));
+      EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, func(0.0f));
+      EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, func(-0.0f));
+      EXPECT_FP_IS_NAN(func(-1.0f));
+    }
 
-  EXPECT_FP_EQ(-0x1.9d1d9fccf477p6f, LIBC_NAMESPACE::logf(min_denormal));
-}
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, func(1.0f));
+  }
 
-TEST_F(LlvmLibcLogfTest, DAZMode) {
-  ModifyMXCSR mxcsr(DAZ);
+#ifdef LIBC_TEST_FTZ_DAZ
+  void test_ftz(float (*func)(float)) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(-0x1.9d1d9fccf477p6f, func(d));
+  }
 
-  EXPECT_FP_EQ(FPBits::inf(Sign::NEG).get_val(),
-               LIBC_NAMESPACE::logf(min_denormal));
-}
+  void test_daz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::DAZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? neg_inf : -0x1.9d1d9fccf477p6f, func(d));
+  }
 
-TEST_F(LlvmLibcLogfTest, FTZDAZMode) {
-  ModifyMXCSR mxcsr(FTZ | DAZ);
+  void test_ftzdaz(float (*func)(float), bool uses_fpu) {
+    LIBC_NAMESPACE::testing::ModifyMXCSR mxcsr(LIBC_NAMESPACE::testing::FTZ |
+                                               LIBC_NAMESPACE::testing::DAZ);
+    volatile float d = min_denormal;
+    EXPECT_FP_EQ(uses_fpu ? neg_inf : -0x1.9d1d9fccf477p6f, func(d));
+  }
+#endif // LIBC_TEST_FTZ_DAZ
+};
+
+#ifdef LIBC_TEST_FTZ_DAZ
+#define LIST_LOGF_FTZ_DAZ_TESTS(suffix, func, uses_fpu)                        \
+  TEST_F(LlvmLibcLogfTest##suffix, FTZMode) { test_ftz(&func); }               \
+  TEST_F(LlvmLibcLogfTest##suffix, DAZMode) { test_daz(&func, uses_fpu); }     \
+  TEST_F(LlvmLibcLogfTest##suffix, FTZDAZMode) { test_ftzdaz(&func, uses_fpu); }
+#else // !LIBC_TEST_FTZ_DAZ
+#define LIST_LOGF_FTZ_DAZ_TESTS(suffix, func, uses_fpu)
+#endif // LIBC_TEST_FTZ_DAZ
 
-  EXPECT_FP_EQ(FPBits::inf(Sign::NEG).get_val(),
-               LIBC_NAMESPACE::logf(min_denormal));
-}
+#define LIST_LOGF_TESTS(suffix, func, check_snan_invalid,                      \
+                        check_exception_and_errno, check_errno, uses_fpu)      \
+  using LlvmLibcLogfTest##suffix = LogfTest;                                   \
+  TEST_F(LlvmLibcLogfTest##suffix, SpecialNumbers) {                           \
+    test_special_numbers(&func, check_snan_invalid, check_exception_and_errno, \
+                         check_errno);                                         \
+  }                                                                            \
+  LIST_LOGF_FTZ_DAZ_TESTS(suffix, func, uses_fpu)
 
-#endif
+LIST_LOGF_TESTS(Default, LIBC_NAMESPACE::logf, /*check_snan_invalid=*/true,
+                /*check_exception_and_errno=*/true, /*check_errno=*/true,
+                /*uses_fpu=*/true)
+LIST_LOGF_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::logf,
+                /*check_snan_invalid=*/false,
+                /*check_exception_and_errno=*/true, /*check_errno=*/true,
+                /*uses_fpu=*/true)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 6455190b39f67e..5aad5be3e8ac5a 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -11118,8 +11118,8 @@ libc_support_library(
 )
 
 libc_support_library(
-    name = "__support_math_log1pf",
-    hdrs = ["src/__support/math/log1pf.h"],
+    name = "__support_math_log1pf_double_eval",
+    hdrs = ["src/__support/math/log1pf_double_eval.h"],
     deps = [
         ":__support_common",
         ":__support_fputil_except_value_utils",
@@ -11137,6 +11137,16 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_log1pf",
+    hdrs = ["src/__support/math/log1pf.h"],
+    deps = [
+        ":__support_common",
+        ":__support_macros_config",
+        ":__support_math_log1pf_double_eval",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_log2",
     hdrs = ["src/__support/math/log2.h"],
@@ -11212,8 +11222,8 @@ libc_support_library(
 )
 
 libc_support_library(
-    name = "__support_math_log10f",
-    hdrs = ["src/__support/math/log10f.h"],
+    name = "__support_math_log10f_double_eval",
+    hdrs = ["src/__support/math/log10f_double_eval.h"],
     deps = [
         ":__support_common",
         ":__support_fputil_except_value_utils",
@@ -11230,6 +11240,16 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_log10f",
+    hdrs = ["src/__support/math/log10f.h"],
+    deps = [
+        ":__support_common",
+        ":__support_macros_config",
+        ":__support_math_log10f_double_eval",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_log2f16",
     hdrs = ["src/__support/math/log2f16.h"],
@@ -11273,22 +11293,32 @@ libc_support_library(
 )
 
 libc_support_library(
-    name = "__support_math_log2f",
-    hdrs = ["src/__support/math/log2f.h"],
+    name = "__support_math_log2f_double_eval",
+    hdrs = ["src/__support/math/log2f_double_eval.h"],
     deps = [
         ":__support_common",
         ":__support_fputil_except_value_utils",
         ":__support_fputil_fenv_impl",
-        ":__support_fputil_fma",
         ":__support_fputil_fp_bits",
         ":__support_fputil_multiply_add",
         ":__support_fputil_polyeval",
         ":__support_macros_config",
         ":__support_macros_optimization",
+        ":__support_macros_properties_cpu_features",
         ":__support_math_common_constants",
     ],
 )
 
+libc_support_library(
+    name = "__support_math_log2f",
+    hdrs = ["src/__support/math/log2f.h"],
+    deps = [
+        ":__support_common",
+        ":__support_macros_config",
+        ":__support_math_log2f_double_eval",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_logbbf16",
     hdrs = ["src/__support/math/logbbf16.h"],
@@ -11333,8 +11363,8 @@ libc_support_library(
 )
 
 libc_support_library(
-    name = "__support_math_logf",
-    hdrs = ["src/__support/math/logf.h"],
+    name = "__support_math_logf_double_eval",
+    hdrs = ["src/__support/math/logf_double_eval.h"],
     deps = [
         ":__support_common",
         ":__support_fputil_except_value_utils",
@@ -11349,6 +11379,16 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_logf",
+    hdrs = ["src/__support/math/logf.h"],
+    deps = [
+        ":__support_common",
+        ":__support_macros_config",
+        ":__support_math_logf_double_eval",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_pow",
     hdrs = [
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 8a15664f1ab33a..0f5e3a7043b9d0 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
@@ -781,19 +781,39 @@ math_mpfr_test(
     ],
 )
 
-math_mpfr_test(name = "logf")
+math_mpfr_test(
+    name = "logf",
+    deps = [
+        "//libc:__support_math_logf_double_eval",
+    ],
+)
 
 math_mpfr_test(name = "log10")
 
-math_mpfr_test(name = "log10f")
+math_mpfr_test(
+    name = "log10f",
+    deps = [
+        "//libc:__support_math_log10f_double_eval",
+    ],
+)
 
 math_mpfr_test(name = "log1p")
 
-math_mpfr_test(name = "log1pf")
+math_mpfr_test(
+    name = "log1pf",
+    deps = [
+        "//libc:__support_math_log1pf_double_eval",
+    ],
+)
 
 math_mpfr_test(name = "log2")
 
-math_mpfr_test(name = "log2f")
+math_mpfr_test(
+    name = "log2f",
+    deps = [
+        "//libc:__support_math_log2f_double_eval",
+    ],
+)
 
 math_mpfr_test(
     name = "lrint",
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index 2d4aa158ef13f3..b9941945f70242 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -1724,19 +1724,39 @@ math_test(
     ],
 )
 
-math_test(name = "logf")
+math_test(
+    name = "logf",
+    deps = [
+        "//libc:__support_math_logf_double_eval",
+    ],
+)
 
 math_test(name = "log10")
 
-math_test(name = "log10f")
+math_test(
+    name = "log10f",
+    deps = [
+        "//libc:__support_math_log10f_double_eval",
+    ],
+)
 
 math_test(name = "log1p")
 
-math_test(name = "log1pf")
+math_test(
+    name = "log1pf",
+    deps = [
+        "//libc:__support_math_log1pf_double_eval",
+    ],
+)
 
 math_test(name = "log2")
 
-math_test(name = "log2f")
+math_test(
+    name = "log2f",
+    deps = [
+        "//libc:__support_math_log2f_double_eval",
+    ],
+)
 
 math_test(
     name = "logb",



More information about the libc-commits mailing list