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 "src/__support/CPP/bit.h" 10 #include "test/UnitTest/FEnvSafeTest.h" 11 #include "test/UnitTest/FPMatcher.h" 12 #include "test/UnitTest/Test.h" 13 14 #include "hdr/math_macros.h" 15 16 template <typename T> 17 class SqrtTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { 18 19 DECLARE_SPECIAL_CONSTANTS(T) 20 21 static constexpr StorageType HIDDEN_BIT = 22 StorageType(1) << LIBC_NAMESPACE::fputil::FPBits<T>::FRACTION_LEN; 23 24 public: 25 typedef T (*SqrtFunc)(T); 26 test_special_numbers(SqrtFunc func)27 void test_special_numbers(SqrtFunc func) { 28 ASSERT_FP_EQ(aNaN, func(aNaN)); 29 ASSERT_FP_EQ(inf, func(inf)); 30 ASSERT_FP_EQ(aNaN, func(neg_inf)); 31 ASSERT_FP_EQ(0.0, func(0.0)); 32 ASSERT_FP_EQ(-0.0, func(-0.0)); 33 ASSERT_FP_EQ(aNaN, func(T(-1.0))); 34 ASSERT_FP_EQ(T(1.0), func(T(1.0))); 35 ASSERT_FP_EQ(T(2.0), func(T(4.0))); 36 ASSERT_FP_EQ(T(3.0), func(T(9.0))); 37 } 38 }; 39 40 #define LIST_SQRT_TESTS(T, func) \ 41 using LlvmLibcSqrtTest = SqrtTest<T>; \ 42 TEST_F(LlvmLibcSqrtTest, SpecialNumbers) { test_special_numbers(&func); } 43