xref: /aosp_15_r20/external/llvm-libc/test/src/math/smoke/cospif16_test.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- Unittests for cospif16 --------------------------------------------===//
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/cospif16.h"
11 #include "test/UnitTest/FPMatcher.h"
12 #include "test/UnitTest/Test.h"
13 
14 using LlvmLibcCospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
15 
TEST_F(LlvmLibcCospif16Test,SpecialNumbers)16 TEST_F(LlvmLibcCospif16Test, SpecialNumbers) {
17   LIBC_NAMESPACE::libc_errno = 0;
18 
19   EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cospif16(aNaN));
20   EXPECT_MATH_ERRNO(0);
21 
22   EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cospif16(zero));
23   EXPECT_MATH_ERRNO(0);
24 
25   EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cospif16(neg_zero));
26   EXPECT_MATH_ERRNO(0);
27 
28   EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cospif16(inf));
29   EXPECT_MATH_ERRNO(EDOM);
30 
31   EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cospif16(neg_inf));
32   EXPECT_MATH_ERRNO(EDOM);
33 }
34 
TEST_F(LlvmLibcCospif16Test,Integers)35 TEST_F(LlvmLibcCospif16Test, Integers) {
36   EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cospif16(-0x420));
37   EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cospif16(-0x1.4p+14));
38   EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::cospif16(0x421));
39   EXPECT_FP_EQ(-1.0f, LIBC_NAMESPACE::cospif16(0x333));
40   EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(-0x1.28p4));
41   EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(-0x1.ffcp9));
42   EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(0x1.01p7));
43   EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(0x1.f6cp9));
44 }
45