1//===-- Unittests for sinhf -----------------------------------------------===//
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/sinhf.h"
14#include "test/UnitTest/FPMatcher.h"
15#include "test/UnitTest/Test.h"
16
17#include <errno.h>
18#include <stdint.h>
19
20using LlvmLibcSinhfTest = LIBC_NAMESPACE::testing::FPTest<float>;
21
22TEST_F(LlvmLibcSinhfTest, SpecialNumbers) {
23 LIBC_NAMESPACE::libc_errno = 0;
24
25 EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::sinhf(aNaN));
26 EXPECT_MATH_ERRNO(0);
27
28 EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::sinhf(0.0f));
29 EXPECT_MATH_ERRNO(0);
30
31 EXPECT_FP_EQ(-0.0f, LIBC_NAMESPACE::sinhf(-0.0f));
32 EXPECT_MATH_ERRNO(0);
33
34 EXPECT_FP_EQ(inf, LIBC_NAMESPACE::sinhf(inf));
35 EXPECT_MATH_ERRNO(0);
36
37 EXPECT_FP_EQ(neg_inf, LIBC_NAMESPACE::sinhf(neg_inf));
38 EXPECT_MATH_ERRNO(0);
39}
40
41// For small values, sinh(x) is x.
42TEST_F(LlvmLibcSinhfTest, SmallValues) {
43 float x = FPBits(uint32_t(0x17800000)).get_val();
44 float result = LIBC_NAMESPACE::sinhf(x);
45 EXPECT_FP_EQ(x, result);
46
47 x = FPBits(uint32_t(0x00400000)).get_val();
48 result = LIBC_NAMESPACE::sinhf(x);
49 EXPECT_FP_EQ(x, result);
50}
51
52TEST_F(LlvmLibcSinhfTest, Overflow) {
53 LIBC_NAMESPACE::libc_errno = 0;
54 EXPECT_FP_EQ_WITH_EXCEPTION(
55 inf, LIBC_NAMESPACE::sinhf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
56 EXPECT_MATH_ERRNO(ERANGE);
57
58 EXPECT_FP_EQ_WITH_EXCEPTION(
59 inf, LIBC_NAMESPACE::sinhf(FPBits(0x42cffff8U).get_val()), FE_OVERFLOW);
60 EXPECT_MATH_ERRNO(ERANGE);
61
62 EXPECT_FP_EQ_WITH_EXCEPTION(
63 inf, LIBC_NAMESPACE::sinhf(FPBits(0x42d00008U).get_val()), FE_OVERFLOW);
64 EXPECT_MATH_ERRNO(ERANGE);
65}
66

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