brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 16b20d7 Raw
72 lines · cpp
1//===-- Unittests for exp2m1f ---------------------------------------------===//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 "hdr/math_macros.h"10#include "hdr/stdint_proxy.h"11#include "src/__support/CPP/array.h"12#include "src/__support/FPUtil/FPBits.h"13#include "src/__support/libc_errno.h"14#include "src/__support/macros/optimization.h"15#include "src/math/exp2m1f.h"16#include "test/UnitTest/FPMatcher.h"17#include "test/UnitTest/Test.h"18#include "utils/MPFRWrapper/MPFRUtils.h"19 20#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS21#define TOLERANCE 122#else23#define TOLERANCE 024#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS25 26using LlvmLibcExp2m1fTest = LIBC_NAMESPACE::testing::FPTest<float>;27 28namespace mpfr = LIBC_NAMESPACE::testing::mpfr;29 30TEST_F(LlvmLibcExp2m1fTest, TrickyInputs) {31  constexpr LIBC_NAMESPACE::cpp::array<float, 10> INPUTS = {32      // EXP2M1F_EXCEPTS_LO33      0x1.36dc8ep-36,34      0x1.224936p-19,35      0x1.d16d2p-20,36      0x1.17949ep-14,37      -0x1.9c3e1ep-38,38      -0x1.4d89b4p-32,39      -0x1.a6eac4p-10,40      -0x1.e7526ep-6,41      // EXP2M1F_EXCEPTS_HI42      0x1.16a972p-1,43      -0x1.9f12acp-5,44  };45 46  for (float x : INPUTS) {47    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2m1, x,48                                   LIBC_NAMESPACE::exp2m1f(x), TOLERANCE + 0.5);49  }50}51 52TEST_F(LlvmLibcExp2m1fTest, InFloatRange) {53  constexpr uint32_t COUNT = 100'000;54  constexpr uint32_t STEP = UINT32_MAX / COUNT;55  for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {56    float x = FPBits(v).get_val();57    if (FPBits(v).is_nan() || FPBits(v).is_inf())58      continue;59    libc_errno = 0;60    float result = LIBC_NAMESPACE::exp2m1f(x);61 62    // If the computation resulted in an error or did not produce valid result63    // in the single-precision floating point range, then ignore comparing with64    // MPFR result as MPFR can still produce valid results because of its65    // wider precision.66    if (FPBits(result).is_nan() || FPBits(result).is_inf() || libc_errno != 0)67      continue;68    ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2m1, x,69                                   LIBC_NAMESPACE::exp2m1f(x), 0.5);70  }71}72