1 | //===-- Unittests for e^x - 1 ---------------------------------------------===// |
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/expm1.h" |
13 | #include "test/UnitTest/FPMatcher.h" |
14 | #include "test/UnitTest/Test.h" |
15 | |
16 | #include <errno.h> |
17 | #include <stdint.h> |
18 | |
19 | using LlvmLibcExpm1Test = LIBC_NAMESPACE::testing::FPTest<double>; |
20 | |
21 | TEST_F(LlvmLibcExpm1Test, SpecialNumbers) { |
22 | EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::expm1(aNaN)); |
23 | EXPECT_FP_EQ(inf, LIBC_NAMESPACE::expm1(inf)); |
24 | EXPECT_FP_EQ_ALL_ROUNDING(-1.0, LIBC_NAMESPACE::expm1(neg_inf)); |
25 | EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::expm1(0x1.0p20), |
26 | FE_OVERFLOW); |
27 | EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::expm1(zero)); |
28 | EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::expm1(neg_zero)); |
29 | // |x| < 2^-53, expm1(x) = x |
30 | EXPECT_FP_EQ(-0x1.23456789abcdep-55, |
31 | LIBC_NAMESPACE::expm1(-0x1.23456789abcdep-55)); |
32 | EXPECT_FP_EQ(0x1.23456789abcdep-55, |
33 | LIBC_NAMESPACE::expm1(0x1.23456789abcdep-55)); |
34 | // log(2^-54) |
35 | EXPECT_FP_EQ(-1.0, LIBC_NAMESPACE::expm1(-0x1.2b708872320e2p5)); |
36 | } |
37 | |