81 changes: 0 additions & 81 deletions libc/src/math/generic/expxf.h

This file was deleted.

2 changes: 1 addition & 1 deletion libc/src/math/generic/sinhf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/math/sinhf.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/math/generic/expxf.h"
#include "src/math/generic/explogxf.h"

namespace __llvm_libc {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/tanhf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "src/math/tanhf.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/math/generic/expxf.h"
#include "src/math/generic/explogxf.h"

namespace __llvm_libc {

Expand Down
8 changes: 5 additions & 3 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1319,14 +1319,16 @@ add_fp_unittest(
)

add_fp_unittest(
expxf_test
explogxf_test
NEED_MPFR
SUITE
libc_math_unittests
HDRS
in_float_range_test_helper.h
SRCS
expxf_test.cpp
explogxf_test.cpp
DEPENDS
libc.src.math.generic.common_constants
libc.src.math.generic.explogxf
libc.src.__support.FPUtil.fputil
)

Expand Down
55 changes: 55 additions & 0 deletions libc/test/src/math/explogxf_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===-- Unittests for explogxf --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "in_float_range_test_helper.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/math/generic/explogxf.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/FPMatcher.h"
#include "utils/UnitTest/Test.h"
#include <math.h>

namespace mpfr = __llvm_libc::testing::mpfr;

DECLARE_SPECIAL_CONSTANTS(float)

constexpr int def_count = 100003;
constexpr float def_prec = 0.500001f;

TEST(LlvmLibcExpxfTest, InFloatRange) {
auto fx = [](float x) -> float {
auto result = __llvm_libc::exp_eval<-1>(x);
return static_cast<float>(2 * result.mult_exp * result.r +
2 * result.mult_exp);
};
auto f_check = [](float x) -> bool {
return !(
(isnan(x) || isinf(x) || x < -70 || x > 70 || fabsf(x) < 0x1.0p-10));
};
CHECK_DATA(0.0f, neg_inf, mpfr::Operation::Exp, fx, f_check, def_count,
def_prec);
}

TEST(LlvmLibcExp2xfTest, InFloatRange) {
auto f_check = [](float x) -> bool {
return !(
(isnan(x) || isinf(x) || x < -130 || x > 130 || fabsf(x) < 0x1.0p-10));
};
CHECK_DATA(0.0f, neg_inf, mpfr::Operation::Exp2, __llvm_libc::exp2_eval,
f_check, def_count, def_prec);
}

TEST(LlvmLibcLog2xfTest, InFloatRange) {
CHECK_DATA(0.0f, inf, mpfr::Operation::Log2, __llvm_libc::log2_eval, isnormal,
def_count, def_prec);
}

TEST(LlvmLibcLogxfTest, InFloatRange) {
CHECK_DATA(0.0f, inf, mpfr::Operation::Log, __llvm_libc::log_eval, isnormal,
def_count, def_prec);
}
38 changes: 0 additions & 38 deletions libc/test/src/math/expxf_test.cpp

This file was deleted.

26 changes: 26 additions & 0 deletions libc/test/src/math/in_float_range_test_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Created by kirill on 8/30/22.
//

#ifndef LLVM_IN_FLOAT_RANGE_TEST_HELPER_H
#define LLVM_IN_FLOAT_RANGE_TEST_HELPER_H

#include <stdint.h>

#define CHECK_DATA(start, stop, mfp_op, f, f_check, count, prec) \
{ \
uint64_t ustart = FPBits(start).uintval(); \
uint64_t ustop = FPBits(stop).uintval(); \
for (uint64_t i = 0;; ++i) { \
uint64_t v = ustart + (ustop - ustart) * i / count; \
if (v > ustop) \
break; \
float x = FPBits(uint32_t(v)).get_val(); \
if ((f_check)(x)) { \
EXPECT_MPFR_MATCH_ALL_ROUNDING(mfp_op, x, static_cast<float>((f)(x)), \
(prec)); \
} \
} \
}

#endif // LLVM_IN_FLOAT_RANGE_TEST_HELPER_H