brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 30d57a4 Raw
55 lines · c
1//===-- Utility class to test different flavors of hypot ------------------===//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_HYPOTTEST_H10#define LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H11 12#include "src/__support/macros/properties/architectures.h"13#include "test/UnitTest/FPMatcher.h"14#include "test/UnitTest/Test.h"15 16template <typename T>17struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {18  using Func = T (*)(T, T);19 20  DECLARE_SPECIAL_CONSTANTS(T)21 22  void test_special_numbers(Func func) {23    constexpr int N = 4;24    // Pythagorean triples.25    constexpr T PYT[N][3] = {{3, 4, 5}, {5, 12, 13}, {8, 15, 17}, {7, 24, 25}};26 27#ifndef LIBC_TARGET_ARCH_IS_NVPTX28    // TODO: Investigate why sNaN tests are failing on nVidia.29    // https://github.com/llvm/llvm-project/issues/99706.30    EXPECT_FP_EQ(func(inf, sNaN), aNaN);31    EXPECT_FP_EQ(func(sNaN, neg_inf), aNaN);32#endif // !LIBC_TARGET_ARCH_IS_NVPTX33 34    EXPECT_FP_EQ(func(inf, aNaN), inf);35    EXPECT_FP_EQ(func(aNaN, neg_inf), inf);36    EXPECT_FP_EQ(func(aNaN, aNaN), aNaN);37    EXPECT_FP_EQ(func(aNaN, zero), aNaN);38    EXPECT_FP_EQ(func(neg_zero, aNaN), aNaN);39 40    for (int i = 0; i < N; ++i) {41      EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], PYT[i][1]));42      EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], PYT[i][1]));43      EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], -PYT[i][1]));44      EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], -PYT[i][1]));45 46      EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], PYT[i][0]));47      EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], PYT[i][0]));48      EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], -PYT[i][0]));49      EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], -PYT[i][0]));50    }51  }52};53 54#endif // LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H55