50 lines · cpp
1//===-- Exhaustive test for acosf16 ---------------------------------------===//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 "src/__support/macros/optimization.h"10#include "src/math/acosf16.h"11#include "test/UnitTest/FPMatcher.h"12#include "test/UnitTest/Test.h"13#include "utils/MPFRWrapper/MPFRUtils.h"14 15#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS16#define TOLERANCE 117#else18#define TOLERANCE 019#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS20 21using LlvmLibcAcosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;22 23namespace mpfr = LIBC_NAMESPACE::testing::mpfr;24 25// Range: [0, Inf]26static constexpr uint16_t POS_START = 0x0000U;27static constexpr uint16_t POS_STOP = 0x7c00U;28 29// Range: [-Inf, 0]30static constexpr uint16_t NEG_START = 0x8000U;31static constexpr uint16_t NEG_STOP = 0xfc00U;32 33TEST_F(LlvmLibcAcosf16Test, PositiveRange) {34 for (uint16_t v = POS_START; v <= POS_STOP; ++v) {35 float16 x = FPBits(v).get_val();36 37 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,38 LIBC_NAMESPACE::acosf16(x), TOLERANCE + 0.5);39 }40}41 42TEST_F(LlvmLibcAcosf16Test, NegativeRange) {43 for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {44 float16 x = FPBits(v).get_val();45 46 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,47 LIBC_NAMESPACE::acosf16(x), TOLERANCE + 0.5);48 }49}50