| //===-- Utility class to test different flavors of rint ---------*- C++ -*-===// | |
| // | |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |
| // See https://llvm.org/LICENSE.txt for license information. | |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| // | |
| //===----------------------------------------------------------------------===// | |
| #ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_RINTTEST_H | |
| #define LLVM_LIBC_TEST_SRC_MATH_SMOKE_RINTTEST_H | |
| #include "hdr/fenv_macros.h" | |
| #include "hdr/math_macros.h" | |
| #include "src/__support/FPUtil/FEnvImpl.h" | |
| #include "src/__support/FPUtil/FPBits.h" | |
| #include "test/UnitTest/FEnvSafeTest.h" | |
| #include "test/UnitTest/FPMatcher.h" | |
| #include "test/UnitTest/Test.h" | |
| using LIBC_NAMESPACE::Sign; | |
| template <typename T> | |
| class RIntTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { | |
| public: | |
| typedef T (*RIntFunc)(T); | |
| private: | |
| using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>; | |
| using StorageType = typename FPBits::StorageType; | |
| const T inf = FPBits::inf(Sign::POS).get_val(); | |
| const T neg_inf = FPBits::inf(Sign::NEG).get_val(); | |
| const T zero = FPBits::zero(Sign::POS).get_val(); | |
| const T neg_zero = FPBits::zero(Sign::NEG).get_val(); | |
| const T nan = FPBits::quiet_nan().get_val(); | |
| public: | |
| void testSpecialNumbers(RIntFunc func) { | |
| ASSERT_FP_EQ_ALL_ROUNDING(inf, func(inf)); | |
| ASSERT_FP_EQ_ALL_ROUNDING(neg_inf, func(neg_inf)); | |
| ASSERT_FP_EQ_ALL_ROUNDING(nan, func(nan)); | |
| ASSERT_FP_EQ_ALL_ROUNDING(zero, func(zero)); | |
| ASSERT_FP_EQ_ALL_ROUNDING(neg_zero, func(neg_zero)); | |
| } | |
| }; | |
| #define LIST_RINT_TESTS(F, func) \ | |
| using LlvmLibcRIntTest = RIntTestTemplate<F>; \ | |
| TEST_F(LlvmLibcRIntTest, specialNumbers) { testSpecialNumbers(&func); } | |
| #endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_RINTTEST_H |