79 lines · c
1//===-- Utility class to test different flavors of creal --------*- 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_COMPLEX_CREALTEST_H10#define LLVM_LIBC_TEST_SRC_COMPLEX_CREALTEST_H11 12#include "test/UnitTest/FEnvSafeTest.h"13#include "test/UnitTest/FPMatcher.h"14#include "test/UnitTest/Test.h"15 16#include "hdr/math_macros.h"17 18template <typename CFPT, typename FPT>19class CRealTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {20 21 DECLARE_SPECIAL_CONSTANTS(FPT)22 23public:24 typedef FPT (*CRealFunc)(CFPT);25 26 void testSpecialNumbers(CRealFunc func) {27 EXPECT_FP_EQ(func(CFPT(aNaN + 67.123i)), aNaN);28 EXPECT_FP_EQ(func(CFPT(neg_aNaN + 78.319i)), neg_aNaN);29 EXPECT_FP_EQ(func(CFPT(sNaN + 7813.131i)), sNaN);30 EXPECT_FP_EQ(func(CFPT(neg_sNaN + 7824.152i)), neg_sNaN);31 EXPECT_FP_EQ(func(CFPT(inf + 9024.2442i)), inf);32 EXPECT_FP_EQ(func(CFPT(neg_inf + 8923.124i)), neg_inf);33 EXPECT_FP_EQ(func(CFPT(min_normal + 782.124i)), min_normal);34 EXPECT_FP_EQ(func(CFPT(max_normal + 2141.2352i)), max_normal);35 EXPECT_FP_EQ(func(CFPT(neg_max_normal + 341.134i)), neg_max_normal);36 EXPECT_FP_EQ(func(CFPT(min_denormal + 781.142i)), min_denormal);37 EXPECT_FP_EQ(func(CFPT(neg_min_denormal + 781.134i)), neg_min_denormal);38 EXPECT_FP_EQ(func(CFPT(max_denormal + 1241.112i)), max_denormal);39 EXPECT_FP_EQ(func(CFPT(zero + 121.121i)), zero);40 EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), zero);41 EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), zero);42 EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), zero);43 EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), neg_zero);44 EXPECT_FP_EQ(func(CFPT(0.0)), zero);45 EXPECT_FP_EQ(func(CFPT(-0.0)), neg_zero);46 EXPECT_FP_EQ(func(CFPT(0.0i)), zero);47 EXPECT_FP_EQ(func(CFPT(-0.0i)), neg_zero);48 }49 50 void testRoundedNumbers(CRealFunc func) {51 EXPECT_FP_EQ(func((CFPT)(4523.1413 + 12413.1414i)), (FPT)(4523.1413));52 EXPECT_FP_EQ(func((CFPT)(-4523.1413 + 12413.1414i)), (FPT)(-4523.1413));53 EXPECT_FP_EQ(func((CFPT)(4523.1413 - 12413.1414i)), (FPT)(4523.1413));54 EXPECT_FP_EQ(func((CFPT)(-4523.1413 - 12413.1414i)), (FPT)(-4523.1413));55 56 EXPECT_FP_EQ(func((CFPT)(3210.5678 + 9876.5432i)), (FPT)(3210.5678));57 EXPECT_FP_EQ(func((CFPT)(-3210.5678 + 9876.5432i)), (FPT)(-3210.5678));58 EXPECT_FP_EQ(func((CFPT)(3210.5678 - 9876.5432i)), (FPT)(3210.5678));59 EXPECT_FP_EQ(func((CFPT)(-3210.5678 - 9876.5432i)), (FPT)(-3210.5678));60 61 EXPECT_FP_EQ(func((CFPT)(1234.4321 + 4321.1234i)), (FPT)(1234.4321));62 EXPECT_FP_EQ(func((CFPT)(-1234.4321 + 4321.1234i)), (FPT)(-1234.4321));63 EXPECT_FP_EQ(func((CFPT)(1234.4321 - 4321.1234i)), (FPT)(1234.4321));64 EXPECT_FP_EQ(func((CFPT)(-1234.4321 - 4321.1234i)), (FPT)(-1234.4321));65 66 EXPECT_FP_EQ(func((CFPT)(6789.1234 + 8765.6789i)), (FPT)(6789.1234));67 EXPECT_FP_EQ(func((CFPT)(-6789.1234 + 8765.6789i)), (FPT)(-6789.1234));68 EXPECT_FP_EQ(func((CFPT)(6789.1234 - 8765.6789i)), (FPT)(6789.1234));69 EXPECT_FP_EQ(func((CFPT)(-6789.1234 - 8765.6789i)), (FPT)(-6789.1234));70 }71};72 73#define LIST_CREAL_TESTS(U, T, func) \74 using LlvmLibcCRealTest = CRealTest<U, T>; \75 TEST_F(LlvmLibcCRealTest, SpecialNumbers) { testSpecialNumbers(&func); } \76 TEST_F(LlvmLibcCRealTest, RoundedNumbers) { testRoundedNumbers(&func); }77 78#endif // LLVM_LIBC_TEST_SRC_COMPLEX_CREALTEST_H79