1 //===-- Utility class to test sqrt[f|l] -------------------------*- 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "test/UnitTest/FEnvSafeTest.h" 10 #include "test/UnitTest/FPMatcher.h" 11 #include "test/UnitTest/Test.h" 12 13 template <typename OutType, typename InType> 14 class SqrtTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { 15 16 DECLARE_SPECIAL_CONSTANTS(OutType) 17 18 struct InConstants { 19 DECLARE_SPECIAL_CONSTANTS(InType) 20 }; 21 22 InConstants in; 23 24 public: 25 typedef OutType (*SqrtFunc)(InType); 26 test_special_numbers(SqrtFunc func)27 void test_special_numbers(SqrtFunc func) { 28 ASSERT_FP_EQ(aNaN, func(in.aNaN)); 29 ASSERT_FP_EQ(inf, func(in.inf)); 30 ASSERT_FP_EQ(aNaN, func(in.neg_inf)); 31 ASSERT_FP_EQ(zero, func(in.zero)); 32 ASSERT_FP_EQ(neg_zero, func(in.neg_zero)); 33 ASSERT_FP_EQ(aNaN, func(InType(-1.0))); 34 ASSERT_FP_EQ(OutType(1.0), func(InType(1.0))); 35 ASSERT_FP_EQ(OutType(2.0), func(InType(4.0))); 36 ASSERT_FP_EQ(OutType(3.0), func(InType(9.0))); 37 } 38 }; 39 40 #define LIST_SQRT_TESTS(T, func) \ 41 using LlvmLibcSqrtTest = SqrtTest<T, T>; \ 42 TEST_F(LlvmLibcSqrtTest, SpecialNumbers) { test_special_numbers(&func); } 43 44 #define LIST_NARROWING_SQRT_TESTS(OutType, InType, func) \ 45 using LlvmLibcSqrtTest = SqrtTest<OutType, InType>; \ 46 TEST_F(LlvmLibcSqrtTest, SpecialNumbers) { test_special_numbers(&func); } 47