[libc-commits] [libc] [libc][math] Implement fast pass for double precision atan2 with 1 ULP errors. (PR #100648)
via libc-commits
libc-commits at lists.llvm.org
Thu Jul 25 15:21:53 PDT 2024
================
@@ -0,0 +1,131 @@
+//===-- Unittests for atan2 -----------------------------------------------===//
+//
+// 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/atan2.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcAtan2Test = LIBC_NAMESPACE::testing::FPTest<double>;
+using LIBC_NAMESPACE::testing::tlog;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+TEST_F(LlvmLibcAtan2Test, TrickyInputs) {
+ mpfr::BinaryInput<double> INPUTS[] = {
+ {0x1.0853408534085p-2, 0x1.e7b54166c6126p-2},
+ {FPBits::inf().get_val(), 0x0.0000000000001p-1022},
+ };
+ constexpr int N = sizeof(INPUTS) / sizeof(INPUTS[0]);
+
+ for (int i = 0; i < N; ++i) {
+ double x = INPUTS[i].x;
+ double y = INPUTS[i].y;
+ mpfr::RoundingMode rm = mpfr::RoundingMode::Downward;
+ mpfr::ForceRoundingMode rr(rm);
+ ASSERT_MPFR_MATCH(mpfr::Operation::Atan2, INPUTS[i],
+ LIBC_NAMESPACE::atan2(x, y), 0.5, rm);
+ INPUTS[i].x = -INPUTS[i].x;
+ ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i],
+ LIBC_NAMESPACE::atan2(-x, y), 0.5);
+ INPUTS[i].y = -INPUTS[i].y;
+ ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i],
+ LIBC_NAMESPACE::atan2(-x, -y), 0.5);
+ INPUTS[i].x = -INPUTS[i].x;
+ ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i],
+ LIBC_NAMESPACE::atan2(x, -y), 0.5);
+ }
+}
+
+#ifndef DEBUGDEBUG
+
+TEST_F(LlvmLibcAtan2Test, InDoubleRange) {
+ 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 finite_count = 0;
+ uint64_t total_count = 0;
+ double failed_x, failed_y, failed_r = 0.0;
----------------
lntue wrote:
Initialize the other 2 vars.
https://github.com/llvm/llvm-project/pull/100648
More information about the libc-commits
mailing list