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
13template <typename OutType, typename InType>
14class 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
24public:
25 typedef OutType (*SqrtFunc)(InType);
26
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 static_assert(true, "Require semicolon.")
44
45#define LIST_NARROWING_SQRT_TESTS(OutType, InType, func) \
46 using LlvmLibcSqrtTest = SqrtTest<OutType, InType>; \
47 TEST_F(LlvmLibcSqrtTest, SpecialNumbers) { test_special_numbers(&func); }
48

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of libc/test/src/math/smoke/SqrtTest.h