104 lines · cpp
1//===-- Unittests for exp10m1f --------------------------------------------===//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/libc_errno.h"13#include "src/__support/macros/optimization.h"14#include "src/math/exp10m1f.h"15#include "test/UnitTest/FPMatcher.h"16#include "test/UnitTest/Test.h"17#include "utils/MPFRWrapper/MPFRUtils.h"18 19#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS20#define TOLERANCE 121#else22#define TOLERANCE 023#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS24 25using LlvmLibcExp10m1fTest = LIBC_NAMESPACE::testing::FPTest<float>;26 27namespace mpfr = LIBC_NAMESPACE::testing::mpfr;28 29TEST_F(LlvmLibcExp10m1fTest, TrickyInputs) {30 constexpr LIBC_NAMESPACE::cpp::array<float, 39> INPUTS = {31 // EXP10M1F_EXCEPTS_LO32 0x1.0fe54ep-11f,33 0x1.80e6eap-11f,34 -0x1.2a33bcp-51f,35 -0x0p+0f,36 -0x1.b59e08p-31f,37 -0x1.bf342p-12f,38 -0x1.6207fp-11f,39 -0x1.bd0c66p-11f,40 -0x1.ffd84cp-10f,41 -0x1.a74172p-9f,42 -0x1.cb694cp-9f,43 // EXP10M1F_EXCEPTS_HI44 0x1.8d31eep-8f,45 0x1.915fcep-8f,46 0x1.bcf982p-8f,47 0x1.99ff0ap-7f,48 0x1.75ea14p-6f,49 0x1.f81b64p-6f,50 0x1.fafecp+3f,51 -0x1.3bf094p-8f,52 -0x1.4558bcp-8f,53 -0x1.4bb43p-8f,54 -0x1.776cc8p-8f,55 -0x1.f024cp-8f,56 -0x1.f510eep-8f,57 -0x1.0b43c4p-7f,58 -0x1.245ee4p-7f,59 -0x1.f9f2dap-7f,60 -0x1.08e42p-6f,61 -0x1.0cdc44p-5f,62 -0x1.ca4322p-5f,63 // Exceptional integers.64 8.0f,65 9.0f,66 10.0f,67 // Overflow boundaries.68 0x1.344134p+5f,69 0x1.344136p+5f,70 0x1.344138p+5f,71 // Underflow boundaries.72 -0x1.e1a5e0p+2f,73 -0x1.e1a5e2p+2f,74 -0x1.e1a5e4p+2f,75 };76 77 for (float x : INPUTS) {78 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10m1, x,79 LIBC_NAMESPACE::exp10m1f(x),80 TOLERANCE + 0.5);81 }82}83 84TEST_F(LlvmLibcExp10m1fTest, InFloatRange) {85 constexpr uint32_t COUNT = 100'000;86 constexpr uint32_t STEP = UINT32_MAX / COUNT;87 for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {88 float x = FPBits(v).get_val();89 if (FPBits(v).is_inf_or_nan())90 continue;91 libc_errno = 0;92 float result = LIBC_NAMESPACE::exp10m1f(x);93 94 // If the computation resulted in an error or did not produce valid result95 // in the single-precision floating point range, then ignore comparing with96 // MPFR result as MPFR can still produce valid results because of its97 // wider precision.98 if (FPBits(result).is_inf_or_nan() || libc_errno != 0)99 continue;100 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10m1, x,101 LIBC_NAMESPACE::exp10m1f(x), 0.5);102 }103}104