Files
clang-p2996/libc/test/src/math/atanf_test.cpp
Kirill Okhotnikov 77e1d9beed [libc][math] Added atanf function.
Performance by core-math (core-math/glibc 2.31/current llvm-14):
28.879/20.843/20.15

Differential Revision: https://reviews.llvm.org/D132842
2022-08-30 22:39:54 +02:00

66 lines
2.1 KiB
C++

//===-- Unittests for atanf -----------------------------------------------===//
//
// 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 "src/__support/FPUtil/FPBits.h"
#include "src/math/atanf.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/FPMatcher.h"
#include "utils/UnitTest/Test.h"
#include <math.h>
#include <errno.h>
#include <stdint.h>
#include <initializer_list>
using FPBits = __llvm_libc::fputil::FPBits<float>;
namespace mpfr = __llvm_libc::testing::mpfr;
DECLARE_SPECIAL_CONSTANTS(float)
TEST(LlvmLibcAtanfTest, SpecialNumbers) {
errno = 0;
__llvm_libc::fputil::clear_except(FE_ALL_EXCEPT);
EXPECT_FP_EQ(aNaN, __llvm_libc::atanf(aNaN));
EXPECT_FP_EXCEPTION(FE_INVALID);
EXPECT_MATH_ERRNO(0);
__llvm_libc::fputil::clear_except(FE_ALL_EXCEPT);
EXPECT_FP_EQ(0.0f, __llvm_libc::atanf(0.0f));
EXPECT_FP_EXCEPTION(0);
EXPECT_MATH_ERRNO(0);
__llvm_libc::fputil::clear_except(FE_ALL_EXCEPT);
EXPECT_FP_EQ(-0.0f, __llvm_libc::atanf(-0.0f));
EXPECT_FP_EXCEPTION(0);
EXPECT_MATH_ERRNO(0);
}
TEST(LlvmLibcAtanfTest, InFloatRange) {
constexpr uint32_t COUNT = 1000000;
const uint32_t STEP = FPBits(inf).uintval() / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,
__llvm_libc::atanf(x), 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, -x,
__llvm_libc::atanf(-x), 0.5);
}
}
// For small values, tanh(x) is x.
TEST(LlvmLibcAtanfTest, SpecialValues) {
for (uint32_t v : {0x3d8d6b23U, 0x3feefcfbU, 0xbd8d6b23U, 0xbfeefcfbU,
0x7F800000U, 0xFF800000U}) {
float x = float(FPBits(v));
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,
__llvm_libc::atanf(x), 0.5);
}
}