45 lines · c
1//===-- Utility class to test different flavors of nextdown -----*- C++ -*-===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTDOWNTEST_H10#define LLVM_LIBC_TEST_SRC_MATH_NEXTDOWNTEST_H11 12#include "test/UnitTest/FEnvSafeTest.h"13#include "test/UnitTest/FPMatcher.h"14#include "test/UnitTest/Test.h"15 16template <typename T>17class NextDownTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {18 19 DECLARE_SPECIAL_CONSTANTS(T)20 21public:22 typedef T (*NextDownFunc)(T);23 24 void testNaN(NextDownFunc func) { ASSERT_FP_EQ(func(aNaN), aNaN); }25 26 void testBoundaries(NextDownFunc func) {27 ASSERT_FP_EQ(zero, func(min_denormal));28 29 ASSERT_FP_EQ(neg_min_denormal, func(zero));30 ASSERT_FP_EQ(neg_min_denormal, func(neg_zero));31 32 ASSERT_FP_EQ(neg_max_normal, func(neg_max_normal));33 ASSERT_FP_EQ(neg_inf, func(neg_inf));34 35 ASSERT_FP_EQ(max_normal, func(inf));36 }37};38 39#define LIST_NEXTDOWN_TESTS(T, func) \40 using LlvmLibcNextDownTest = NextDownTestTemplate<T>; \41 TEST_F(LlvmLibcNextDownTest, TestNaN) { testNaN(&func); } \42 TEST_F(LlvmLibcNextDownTest, TestBoundaries) { testBoundaries(&func); }43 44#endif // LLVM_LIBC_TEST_SRC_MATH_NEXTDOWNTEST_H45