1 | //===-- Unittests for coshf -----------------------------------------------===// |
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-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "hdr/math_macros.h" |
10 | #include "src/__support/CPP/array.h" |
11 | #include "src/__support/FPUtil/FPBits.h" |
12 | #include "src/errno/libc_errno.h" |
13 | #include "src/math/coshf.h" |
14 | #include "test/UnitTest/FPMatcher.h" |
15 | #include "test/UnitTest/Test.h" |
16 | |
17 | #include <errno.h> |
18 | #include <stdint.h> |
19 | |
20 | using LlvmLibcCoshfTest = LIBC_NAMESPACE::testing::FPTest<float>; |
21 | |
22 | TEST_F(LlvmLibcCoshfTest, SpecialNumbers) { |
23 | LIBC_NAMESPACE::libc_errno = 0; |
24 | |
25 | EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::coshf(aNaN)); |
26 | EXPECT_MATH_ERRNO(0); |
27 | |
28 | EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::coshf(inf)); |
29 | EXPECT_MATH_ERRNO(0); |
30 | |
31 | EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::coshf(neg_inf)); |
32 | EXPECT_MATH_ERRNO(0); |
33 | |
34 | EXPECT_FP_EQ_ALL_ROUNDING(1.0f, LIBC_NAMESPACE::coshf(0.0f)); |
35 | EXPECT_MATH_ERRNO(0); |
36 | |
37 | EXPECT_FP_EQ_ALL_ROUNDING(1.0f, LIBC_NAMESPACE::coshf(-0.0f)); |
38 | EXPECT_MATH_ERRNO(0); |
39 | } |
40 | |
41 | TEST_F(LlvmLibcCoshfTest, Overflow) { |
42 | LIBC_NAMESPACE::libc_errno = 0; |
43 | EXPECT_FP_EQ_WITH_EXCEPTION( |
44 | inf, LIBC_NAMESPACE::coshf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW); |
45 | EXPECT_MATH_ERRNO(ERANGE); |
46 | |
47 | EXPECT_FP_EQ_WITH_EXCEPTION( |
48 | inf, LIBC_NAMESPACE::coshf(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW); |
49 | EXPECT_MATH_ERRNO(ERANGE); |
50 | |
51 | EXPECT_FP_EQ_WITH_EXCEPTION( |
52 | inf, LIBC_NAMESPACE::coshf(FPBits(0x42d00008U).get_val()), FE_OVERFLOW); |
53 | EXPECT_MATH_ERRNO(ERANGE); |
54 | } |
55 | |