1//===-- Unittests for exp2m1f ---------------------------------------------===//
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 "src/errno/libc_errno.h"
10#include "src/math/exp2m1f.h"
11#include "test/UnitTest/FPMatcher.h"
12#include "test/UnitTest/Test.h"
13
14using LlvmLibcExp2m1fTest = LIBC_NAMESPACE::testing::FPTest<float>;
15using LIBC_NAMESPACE::fputil::testing::ForceRoundingMode;
16using LIBC_NAMESPACE::fputil::testing::RoundingMode;
17
18TEST_F(LlvmLibcExp2m1fTest, SpecialNumbers) {
19 LIBC_NAMESPACE::libc_errno = 0;
20
21 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::exp2m1f(aNaN));
22 EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::exp2m1f(inf));
23 EXPECT_FP_EQ_ALL_ROUNDING(-1.0f, LIBC_NAMESPACE::exp2m1f(neg_inf));
24 EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::exp2m1f(0.0f));
25 EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, LIBC_NAMESPACE::exp2m1f(-0.0f));
26
27 EXPECT_FP_EQ_ALL_ROUNDING(1.0f, LIBC_NAMESPACE::exp2m1f(1.0f));
28 EXPECT_FP_EQ_ALL_ROUNDING(-0.5f, LIBC_NAMESPACE::exp2m1f(-1.0f));
29 EXPECT_FP_EQ_ALL_ROUNDING(3.0f, LIBC_NAMESPACE::exp2m1f(2.0f));
30 EXPECT_FP_EQ_ALL_ROUNDING(-0.75f, LIBC_NAMESPACE::exp2m1f(-2.0f));
31}
32
33TEST_F(LlvmLibcExp2m1fTest, Overflow) {
34 LIBC_NAMESPACE::libc_errno = 0;
35
36 EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::exp2m1f(0x1.fffffep+127),
37 FE_OVERFLOW);
38 EXPECT_MATH_ERRNO(ERANGE);
39
40 EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::exp2m1f(128.0f),
41 FE_OVERFLOW);
42 EXPECT_MATH_ERRNO(ERANGE);
43
44 EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::exp2m1f(0x1.000002p+7),
45 FE_OVERFLOW);
46 EXPECT_MATH_ERRNO(ERANGE);
47}
48
49TEST_F(LlvmLibcExp2m1fTest, Underflow) {
50 LIBC_NAMESPACE::libc_errno = 0;
51
52 EXPECT_FP_EQ_WITH_EXCEPTION(-1.0f, LIBC_NAMESPACE::exp2m1f(-0x1.fffffep+127),
53 FE_UNDERFLOW);
54 EXPECT_MATH_ERRNO(ERANGE);
55
56 EXPECT_FP_EQ_WITH_EXCEPTION(-1.0f, LIBC_NAMESPACE::exp2m1f(-25.0f),
57 FE_UNDERFLOW);
58 EXPECT_MATH_ERRNO(ERANGE);
59
60 EXPECT_FP_EQ_WITH_EXCEPTION(-1.0f, LIBC_NAMESPACE::exp2m1f(-0x1.900002p4),
61 FE_UNDERFLOW);
62 EXPECT_MATH_ERRNO(ERANGE);
63}
64

source code of libc/test/src/math/smoke/exp2m1f_test.cpp