1 //===-- Exhaustive test for coshf -----------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "exhaustive_test.h"
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/math/coshf.h"
12 #include "test/UnitTest/FPMatcher.h"
13 #include "utils/MPFRWrapper/MPFRUtils.h"
17 using FPBits
= __llvm_libc::fputil::FPBits
<float>;
19 namespace mpfr
= __llvm_libc::testing::mpfr
;
21 struct LlvmLibcCoshfExhaustiveTest
: public LlvmLibcExhaustiveTest
<uint32_t> {
22 bool check(uint32_t start
, uint32_t stop
,
23 mpfr::RoundingMode rounding
) override
{
24 mpfr::ForceRoundingMode
r(rounding
);
25 uint32_t bits
= start
;
29 float x
= float(xbits
);
30 result
&= EXPECT_MPFR_MATCH(mpfr::Operation::Cosh
, x
,
31 __llvm_libc::coshf(x
), 0.5, rounding
);
32 } while (bits
++ < stop
);
38 static constexpr uint32_t POS_START
= 0x0000'0000U
;
39 static constexpr uint32_t POS_STOP
= 0x42b4'0000U
;
41 TEST_F(LlvmLibcCoshfExhaustiveTest
, PostiveRangeRoundNearestTieToEven
) {
42 test_full_range(POS_START
, POS_STOP
, mpfr::RoundingMode::Nearest
);
45 TEST_F(LlvmLibcCoshfExhaustiveTest
, PostiveRangeRoundUp
) {
46 test_full_range(POS_START
, POS_STOP
, mpfr::RoundingMode::Upward
);
49 TEST_F(LlvmLibcCoshfExhaustiveTest
, PostiveRangeRoundDown
) {
50 test_full_range(POS_START
, POS_STOP
, mpfr::RoundingMode::Downward
);
53 TEST_F(LlvmLibcCoshfExhaustiveTest
, PostiveRangeRoundTowardZero
) {
54 test_full_range(POS_START
, POS_STOP
, mpfr::RoundingMode::TowardZero
);