brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 4e36384 Raw
93 lines · cpp
1//===-- Unittests for asin ------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/macros/optimization.h"10#include "src/math/asin.h"11#include "test/UnitTest/FPMatcher.h"12#include "test/UnitTest/Test.h"13#include "utils/MPFRWrapper/MPFRUtils.h"14 15#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS16#define TOLERANCE 617#else18#define TOLERANCE 019#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS20 21using LlvmLibcAsinTest = LIBC_NAMESPACE::testing::FPTest<double>;22 23namespace mpfr = LIBC_NAMESPACE::testing::mpfr;24 25using LIBC_NAMESPACE::testing::tlog;26 27TEST_F(LlvmLibcAsinTest, InDoubleRange) {28  constexpr uint64_t COUNT = 123'451;29  uint64_t START = FPBits(0x1.0p-60).uintval();30  uint64_t STOP = FPBits(1.0).uintval();31  uint64_t STEP = (STOP - START) / COUNT;32 33  auto test = [&](mpfr::RoundingMode rounding_mode) {34    mpfr::ForceRoundingMode __r(rounding_mode);35    if (!__r.success)36      return;37 38    uint64_t fails = 0;39    uint64_t count = 0;40    uint64_t cc = 0;41    double mx = 0.0, mr = 0.0;42    double tol = 0.5;43 44    for (uint64_t i = 0, v = START; i <= COUNT; ++i, v += STEP) {45      double x = FPBits(v).get_val();46      if (FPBits(v).is_nan() || FPBits(v).is_inf())47        continue;48      libc_errno = 0;49      double result = LIBC_NAMESPACE::asin(x);50      ++cc;51      if (FPBits(result).is_nan() || FPBits(result).is_inf())52        continue;53 54      ++count;55 56      if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Asin, x, result,57                                             TOLERANCE + 0.5, rounding_mode)) {58        ++fails;59        while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Asin, x,60                                                  result, tol, rounding_mode)) {61          mx = x;62          mr = result;63 64          if (tol > 1000.0)65            break;66 67          tol *= 2.0;68        }69      }70    }71    if (fails) {72      tlog << " Asin failed: " << fails << "/" << count << "/" << cc73           << " tests.\n";74      tlog << "   Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n";75      EXPECT_MPFR_MATCH(mpfr::Operation::Asin, mx, mr, 0.5, rounding_mode);76    }77  };78 79  tlog << " Test Rounding To Nearest...\n";80  test(mpfr::RoundingMode::Nearest);81 82#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS83  tlog << " Test Rounding Downward...\n";84  test(mpfr::RoundingMode::Downward);85 86  tlog << " Test Rounding Upward...\n";87  test(mpfr::RoundingMode::Upward);88 89  tlog << " Test Rounding Toward Zero...\n";90  test(mpfr::RoundingMode::TowardZero);91#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS92}93