• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/__support/FPUtil/cast.h"
10 #include "src/errno/libc_errno.h"
11 #include "src/math/cospif16.h"
12 #include "test/UnitTest/FPMatcher.h"
13 #include "test/UnitTest/Test.h"
14 
15 using LlvmLibcCospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
16 
TEST_F(LlvmLibcCospif16Test,SpecialNumbers)17 TEST_F(LlvmLibcCospif16Test, SpecialNumbers) {
18   LIBC_NAMESPACE::libc_errno = 0;
19 
20   EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cospif16(aNaN));
21   EXPECT_MATH_ERRNO(0);
22 
23   EXPECT_FP_EQ(FPBits::one().get_val(), LIBC_NAMESPACE::cospif16(zero));
24   EXPECT_MATH_ERRNO(0);
25 
26   EXPECT_FP_EQ(FPBits::one().get_val(), LIBC_NAMESPACE::cospif16(neg_zero));
27   EXPECT_MATH_ERRNO(0);
28 
29   EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cospif16(inf));
30   EXPECT_MATH_ERRNO(EDOM);
31 
32   EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cospif16(neg_inf));
33   EXPECT_MATH_ERRNO(EDOM);
34 }
35 
TEST_F(LlvmLibcCospif16Test,Integers)36 TEST_F(LlvmLibcCospif16Test, Integers) {
37   EXPECT_FP_EQ(FPBits::one().get_val(),
38                LIBC_NAMESPACE::cospif16(
39                    LIBC_NAMESPACE::fputil::cast<float16>(-0x420.0p0)));
40   EXPECT_FP_EQ(FPBits::one().get_val(),
41                LIBC_NAMESPACE::cospif16(
42                    LIBC_NAMESPACE::fputil::cast<float16>(-0x1.4p+14)));
43   EXPECT_FP_EQ(FPBits::one(Sign::NEG).get_val(),
44                LIBC_NAMESPACE::cospif16(
45                    LIBC_NAMESPACE::fputil::cast<float16>(0x421.0p0)));
46   EXPECT_FP_EQ(FPBits::one(Sign::NEG).get_val(),
47                LIBC_NAMESPACE::cospif16(
48                    LIBC_NAMESPACE::fputil::cast<float16>(0x333.0p0)));
49   EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(
50                          LIBC_NAMESPACE::fputil::cast<float16>(-0x1.28p4)));
51   EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(
52                          LIBC_NAMESPACE::fputil::cast<float16>(-0x1.ffcp9)));
53   EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(
54                          LIBC_NAMESPACE::fputil::cast<float16>(0x1.01p7)));
55   EXPECT_FP_EQ(zero, LIBC_NAMESPACE::cospif16(
56                          LIBC_NAMESPACE::fputil::cast<float16>(0x1.f6cp9)));
57 }
58