Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / math / explogxf_test.cpp
blob24f9f3c0f8e45e160e9923db5895dc5e24316eb5
1 //===-- Unittests for supfuncf --------------------------------------------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "in_float_range_test_helper.h"
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/math/generic/explogxf.h"
12 #include "test/UnitTest/FPMatcher.h"
13 #include "test/UnitTest/Test.h"
14 #include "utils/MPFRWrapper/MPFRUtils.h"
15 #include <math.h>
17 using LlvmLibcExplogfTest = LIBC_NAMESPACE::testing::FPTest<float>;
19 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
21 constexpr int def_count = 100003;
22 constexpr float def_prec = 0.500001f;
24 auto f_normal = [](float x) -> bool {
25 return !(isnan(x) || isinf(x) || fabs(x) < 2E-38);
28 TEST_F(LlvmLibcExplogfTest, ExpInFloatRange) {
29 auto fx = [](float x) -> float {
30 auto result = LIBC_NAMESPACE::exp_b_range_reduc<LIBC_NAMESPACE::ExpBase>(x);
31 double r = LIBC_NAMESPACE::ExpBase::powb_lo(result.lo);
32 return static_cast<float>(result.mh * r);
34 auto f_check = [](float x) -> bool {
35 return !(
36 (isnan(x) || isinf(x) || x < -70 || x > 70 || fabsf(x) < 0x1.0p-10));
38 CHECK_DATA(0.0f, neg_inf, mpfr::Operation::Exp, fx, f_check, def_count,
39 def_prec);
42 TEST_F(LlvmLibcExplogfTest, Log2InFloatRange) {
43 CHECK_DATA(0.0f, inf, mpfr::Operation::Log2, LIBC_NAMESPACE::log2_eval,
44 f_normal, def_count, def_prec);
47 TEST_F(LlvmLibcExplogfTest, LogInFloatRange) {
48 CHECK_DATA(0.0f, inf, mpfr::Operation::Log, LIBC_NAMESPACE::log_eval,
49 f_normal, def_count, def_prec);