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//===----------------------------------------------------------------------===//
8
9#include "hdr/math_macros.h"
10#include "in_float_range_test_helper.h"
11#include "src/__support/FPUtil/FPBits.h"
12#include "src/math/fabs.h"
13#include "src/math/fabsf.h"
14#include "src/math/generic/explogxf.h"
15#include "test/UnitTest/FPMatcher.h"
16#include "test/UnitTest/Test.h"
17#include "utils/MPFRWrapper/MPFRUtils.h"
18
19using LlvmLibcExplogfTest = LIBC_NAMESPACE::testing::FPTest<float>;
20
21namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
22
23constexpr int def_count = 100003;
24constexpr float def_prec = 0.500001f;
25
26auto f_normal = [](float x) -> bool {
27 return !(isnan(x: x) || isinf(x: x) || LIBC_NAMESPACE::fabs(x) < 2E-38);
28};
29
30TEST_F(LlvmLibcExplogfTest, ExpInFloatRange) {
31 auto fx = [](float x) -> float {
32 auto result = LIBC_NAMESPACE::exp_b_range_reduc<LIBC_NAMESPACE::ExpBase>(x);
33 double r = LIBC_NAMESPACE::ExpBase::powb_lo(dx: result.lo);
34 return static_cast<float>(result.mh * r);
35 };
36 auto f_check = [](float x) -> bool {
37 return !((isnan(x: x) || isinf(x: x) || x < -70 || x > 70 ||
38 LIBC_NAMESPACE::fabsf(x) < 0x1.0p-10));
39 };
40 CHECK_DATA(0.0f, neg_inf, mpfr::Operation::Exp, fx, f_check, def_count,
41 def_prec);
42}
43
44TEST_F(LlvmLibcExplogfTest, Log2InFloatRange) {
45 CHECK_DATA(0.0f, inf, mpfr::Operation::Log2, LIBC_NAMESPACE::log2_eval,
46 f_normal, def_count, def_prec);
47}
48
49TEST_F(LlvmLibcExplogfTest, LogInFloatRange) {
50 CHECK_DATA(0.0f, inf, mpfr::Operation::Log, LIBC_NAMESPACE::log_eval,
51 f_normal, def_count, def_prec);
52}
53

source code of libc/test/src/math/explogxf_test.cpp