[libc-commits] [libc] [libc][math] Implement fast pass for double precision pow function with up to 1ULP error. (PR #101926)
via libc-commits
libc-commits at lists.llvm.org
Mon Aug 5 05:05:09 PDT 2024
================
@@ -0,0 +1,114 @@
+//===-- Unittests for pow ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/math_macros.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/math/pow.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcPowTest = LIBC_NAMESPACE::testing::FPTest<double>;
+using LIBC_NAMESPACE::testing::tlog;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+TEST_F(LlvmLibcPowTest, TrickyInputs) {
+ constexpr mpfr::BinaryInput<double> INPUTS[] = {
+ {0x1.0853408534085p-2, 0x1.0D148E03BCBA8p-1},
+ {0x1.65FBD65FBD657p-1, 0x1.F10D148E03BB6p+1},
+ };
+
+ for (auto input : INPUTS) {
+ double x = input.x;
+ double y = input.y;
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Pow, input,
+ LIBC_NAMESPACE::pow(x, y), 0.5);
+ }
+}
+
+TEST_F(LlvmLibcPowTest, InFloatRange) {
+ constexpr uint64_t X_COUNT = 123;
+ constexpr uint64_t X_START = FPBits(0.25).uintval();
+ constexpr uint64_t X_STOP = FPBits(4.0).uintval();
+ constexpr uint64_t X_STEP = (X_STOP - X_START) / X_COUNT;
+
+ constexpr uint64_t Y_COUNT = 137;
+ constexpr uint64_t Y_START = FPBits(0.25).uintval();
+ constexpr uint64_t Y_STOP = FPBits(4.0).uintval();
+ constexpr uint64_t Y_STEP = (Y_STOP - Y_START) / Y_COUNT;
+
+ auto test = [&](mpfr::RoundingMode rounding_mode) {
+ mpfr::ForceRoundingMode __r(rounding_mode);
+ if (!__r.success)
+ return;
+
+ uint64_t fails = 0;
+ uint64_t count = 0;
+ uint64_t cc = 0;
+ double mx, my, mr = 0.0;
----------------
overmighty wrote:
This only initializes `mr` to 0.0.
https://github.com/llvm/llvm-project/pull/101926
More information about the libc-commits
mailing list