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

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