85 lines · cpp
1//===-- Unittests for atanf -----------------------------------------------===//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/FPUtil/FPBits.h"12#include "src/__support/macros/optimization.h"13#include "src/math/atanf.h"14#include "test/UnitTest/FPMatcher.h"15#include "test/UnitTest/Test.h"16#include "utils/MPFRWrapper/MPFRUtils.h"17 18#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS19#define TOLERANCE 420#else21#define TOLERANCE 022#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS23 24using LlvmLibcAtanfTest = LIBC_NAMESPACE::testing::FPTest<float>;25 26namespace mpfr = LIBC_NAMESPACE::testing::mpfr;27 28// TODO: This test needs to have its checks for exceptions, errno29// tightened30TEST_F(LlvmLibcAtanfTest, SpecialNumbers) {31 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);32 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::atanf(aNaN));33 // TODO: Uncomment these checks later, RoundingMode affects running34 // tests in this way https://github.com/llvm/llvm-project/issues/90653.35 // EXPECT_FP_EXCEPTION(0);36 EXPECT_MATH_ERRNO(0);37 38 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);39 EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::atanf(0.0f));40 // TODO: Uncomment these checks later, RoundingMode affects running41 // tests in this way https://github.com/llvm/llvm-project/issues/90653.42 // EXPECT_FP_EXCEPTION(0);43 EXPECT_MATH_ERRNO(0);44 45 LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);46 EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, LIBC_NAMESPACE::atanf(-0.0f));47 // TODO: Uncomment these checks later, RoundingMode affects running48 // tests in this way https://github.com/llvm/llvm-project/issues/90653.49 // EXPECT_FP_EXCEPTION(0);50 EXPECT_MATH_ERRNO(0);51}52 53TEST_F(LlvmLibcAtanfTest, InFloatRange) {54 constexpr uint32_t COUNT = 100'000;55 const uint32_t STEP = FPBits(inf).uintval() / COUNT;56 for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {57 float x = FPBits(v).get_val();58 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,59 LIBC_NAMESPACE::atanf(x), TOLERANCE + 0.5);60 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, -x,61 LIBC_NAMESPACE::atanf(-x), TOLERANCE + 0.5);62 }63}64 65// For small values, tanh(x) is x.66TEST_F(LlvmLibcAtanfTest, SpecialValues) {67 uint32_t val_arr[] = {68 0x3d8d6b23U, // x = 0x1.1ad646p-4f69 0x3dbb6ac7U, // x = 0x1.76d58ep-4f70 0x3feefcfbU, // x = 0x1.ddf9f6p+0f71 0x3ffe2ec1U, // x = 0x1.fc5d82p+0f72 0xbd8d6b23U, // x = -0x1.1ad646p-4f73 0xbdbb6ac7U, // x = -0x1.76d58ep-4f74 0xbfeefcfbU, // x = -0x1.ddf9f6p+0f75 0xbffe2ec1U, // x = -0x1.fc5d82p+076 0x7F800000U, // x = +Inf77 0xFF800000U, // x = -Inf78 };79 for (uint32_t v : val_arr) {80 float x = FPBits(v).get_val();81 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,82 LIBC_NAMESPACE::atanf(x), TOLERANCE + 0.5);83 }84}85