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