| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //===-- Utility class to test fabs[f|l] -------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "utils/FPUtil/TestHelpers.h" | ||
| #include "utils/MPFRWrapper/MPFRUtils.h" | ||
| #include "utils/UnitTest/Test.h" | ||
|
|
||
| #include <math.h> | ||
|
|
||
| namespace mpfr = __llvm_libc::testing::mpfr; | ||
|
|
||
| template <typename T> class FAbsTest : public __llvm_libc::testing::Test { | ||
|
|
||
| DECLARE_SPECIAL_CONSTANTS(T) | ||
|
|
||
| public: | ||
| typedef T (*FabsFunc)(T); | ||
|
|
||
| void testSpecialNumbers(FabsFunc func) { | ||
| EXPECT_FP_EQ(aNaN, func(aNaN)); | ||
|
|
||
| EXPECT_FP_EQ(inf, func(inf)); | ||
| EXPECT_FP_EQ(inf, func(negInf)); | ||
|
|
||
| EXPECT_FP_EQ(zero, func(zero)); | ||
| EXPECT_FP_EQ(zero, func(negZero)); | ||
| } | ||
|
|
||
| void testRange(FabsFunc func) { | ||
| constexpr UIntType count = 10000000; | ||
| constexpr UIntType step = UIntType(-1) / count; | ||
| for (UIntType i = 0, v = 0; i <= count; ++i, v += step) { | ||
| T x = T(FPBits(v)); | ||
| if (isnan(x) || isinf(x)) | ||
| continue; | ||
| ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, func(x), 0.0); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_FABS_TESTS(T, func) \ | ||
| using LlvmLibcFAbsTest = FAbsTest<T>; \ | ||
| TEST_F(LlvmLibcFAbsTest, SpecialNumbers) { testSpecialNumbers(&func); } \ | ||
| TEST_F(LlvmLibcFAbsTest, Range) { testRange(&func); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| //===-- Utility class to test fmin[f|l] -------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "utils/FPUtil/TestHelpers.h" | ||
| #include "utils/MPFRWrapper/MPFRUtils.h" | ||
| #include "utils/UnitTest/Test.h" | ||
|
|
||
| #include <math.h> | ||
|
|
||
| namespace mpfr = __llvm_libc::testing::mpfr; | ||
|
|
||
| template <typename T> class FMaxTest : public __llvm_libc::testing::Test { | ||
|
|
||
| DECLARE_SPECIAL_CONSTANTS(T) | ||
|
|
||
| public: | ||
| typedef T (*FMaxFunc)(T, T); | ||
|
|
||
| void testNaN(FMaxFunc func) { | ||
| EXPECT_FP_EQ(inf, func(aNaN, inf)); | ||
| EXPECT_FP_EQ(negInf, func(negInf, aNaN)); | ||
| EXPECT_FP_EQ(0.0, func(aNaN, 0.0)); | ||
| EXPECT_FP_EQ(-0.0, func(-0.0, aNaN)); | ||
| EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345))); | ||
| EXPECT_FP_EQ(T(1.2345), func(T(1.2345), aNaN)); | ||
| EXPECT_FP_EQ(aNaN, func(aNaN, aNaN)); | ||
| } | ||
|
|
||
| void testInfArg(FMaxFunc func) { | ||
| EXPECT_FP_EQ(inf, func(negInf, inf)); | ||
| EXPECT_FP_EQ(inf, func(inf, 0.0)); | ||
| EXPECT_FP_EQ(inf, func(-0.0, inf)); | ||
| EXPECT_FP_EQ(inf, func(inf, T(1.2345))); | ||
| EXPECT_FP_EQ(inf, func(T(-1.2345), inf)); | ||
| } | ||
|
|
||
| void testNegInfArg(FMaxFunc func) { | ||
| EXPECT_FP_EQ(inf, func(inf, negInf)); | ||
| EXPECT_FP_EQ(0.0, func(negInf, 0.0)); | ||
| EXPECT_FP_EQ(-0.0, func(-0.0, negInf)); | ||
| EXPECT_FP_EQ(T(-1.2345), func(negInf, T(-1.2345))); | ||
| EXPECT_FP_EQ(T(1.2345), func(T(1.2345), negInf)); | ||
| } | ||
|
|
||
| void testBothZero(FMaxFunc func) { | ||
| EXPECT_FP_EQ(0.0, func(0.0, 0.0)); | ||
| EXPECT_FP_EQ(0.0, func(-0.0, 0.0)); | ||
| EXPECT_FP_EQ(0.0, func(0.0, -0.0)); | ||
| EXPECT_FP_EQ(-0.0, func(-0.0, -0.0)); | ||
| } | ||
|
|
||
| void testRange(FMaxFunc func) { | ||
| constexpr UIntType count = 10000001; | ||
| constexpr UIntType step = UIntType(-1) / count; | ||
| for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count; | ||
| ++i, v += step, w -= step) { | ||
| T x = T(FPBits(v)), y = T(FPBits(w)); | ||
| if (isnan(x) || isinf(x)) | ||
| continue; | ||
| if (isnan(y) || isinf(y)) | ||
| continue; | ||
| if ((x == 0) && (y == 0)) | ||
| continue; | ||
|
|
||
| if (x > y) { | ||
| EXPECT_FP_EQ(x, func(x, y)); | ||
| } else { | ||
| EXPECT_FP_EQ(y, func(x, y)); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_FMAX_TESTS(T, func) \ | ||
| using LlvmLibcFMaxTest = FMaxTest<T>; \ | ||
| TEST_F(LlvmLibcFMaxTest, NaN) { testNaN(&func); } \ | ||
| TEST_F(LlvmLibcFMaxTest, InfArg) { testInfArg(&func); } \ | ||
| TEST_F(LlvmLibcFMaxTest, NegInfArg) { testNegInfArg(&func); } \ | ||
| TEST_F(LlvmLibcFMaxTest, BothZero) { testBothZero(&func); } \ | ||
| TEST_F(LlvmLibcFMaxTest, Range) { testRange(&func); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| //===-- Utility class to test fmin[f|l] -------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "utils/FPUtil/TestHelpers.h" | ||
| #include "utils/MPFRWrapper/MPFRUtils.h" | ||
| #include "utils/UnitTest/Test.h" | ||
|
|
||
| #include <math.h> | ||
|
|
||
| namespace mpfr = __llvm_libc::testing::mpfr; | ||
|
|
||
| template <typename T> class FMinTest : public __llvm_libc::testing::Test { | ||
|
|
||
| DECLARE_SPECIAL_CONSTANTS(T) | ||
|
|
||
| public: | ||
| typedef T (*FMinFunc)(T, T); | ||
|
|
||
| void testNaN(FMinFunc func) { | ||
| EXPECT_FP_EQ(inf, func(aNaN, inf)); | ||
| EXPECT_FP_EQ(negInf, func(negInf, aNaN)); | ||
| EXPECT_FP_EQ(0.0, func(aNaN, 0.0)); | ||
| EXPECT_FP_EQ(-0.0, func(-0.0, aNaN)); | ||
| EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345))); | ||
| EXPECT_FP_EQ(T(1.2345), func(T(1.2345), aNaN)); | ||
| EXPECT_FP_EQ(aNaN, func(aNaN, aNaN)); | ||
| } | ||
|
|
||
| void testInfArg(FMinFunc func) { | ||
| EXPECT_FP_EQ(negInf, func(negInf, inf)); | ||
| EXPECT_FP_EQ(0.0, func(inf, 0.0)); | ||
| EXPECT_FP_EQ(-0.0, func(-0.0, inf)); | ||
| EXPECT_FP_EQ(T(1.2345), func(inf, T(1.2345))); | ||
| EXPECT_FP_EQ(T(-1.2345), func(T(-1.2345), inf)); | ||
| } | ||
|
|
||
| void testNegInfArg(FMinFunc func) { | ||
| EXPECT_FP_EQ(negInf, func(inf, negInf)); | ||
| EXPECT_FP_EQ(negInf, func(negInf, 0.0)); | ||
| EXPECT_FP_EQ(negInf, func(-0.0, negInf)); | ||
| EXPECT_FP_EQ(negInf, func(negInf, T(-1.2345))); | ||
| EXPECT_FP_EQ(negInf, func(T(1.2345), negInf)); | ||
| } | ||
|
|
||
| void testBothZero(FMinFunc func) { | ||
| EXPECT_FP_EQ(0.0, func(0.0, 0.0)); | ||
| EXPECT_FP_EQ(-0.0, func(-0.0, 0.0)); | ||
| EXPECT_FP_EQ(-0.0, func(0.0, -0.0)); | ||
| EXPECT_FP_EQ(-0.0, func(-0.0, -0.0)); | ||
| } | ||
|
|
||
| void testRange(FMinFunc func) { | ||
| constexpr UIntType count = 10000001; | ||
| constexpr UIntType step = UIntType(-1) / count; | ||
| for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count; | ||
| ++i, v += step, w -= step) { | ||
| T x = T(FPBits(v)), y = T(FPBits(w)); | ||
| if (isnan(x) || isinf(x)) | ||
| continue; | ||
| if (isnan(y) || isinf(y)) | ||
| continue; | ||
| if ((x == 0) && (y == 0)) | ||
| continue; | ||
|
|
||
| if (x > y) { | ||
| EXPECT_FP_EQ(y, func(x, y)); | ||
| } else { | ||
| EXPECT_FP_EQ(x, func(x, y)); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_FMIN_TESTS(T, func) \ | ||
| using LlvmLibcFMinTest = FMinTest<T>; \ | ||
| TEST_F(LlvmLibcFMinTest, NaN) { testNaN(&func); } \ | ||
| TEST_F(LlvmLibcFMinTest, InfArg) { testInfArg(&func); } \ | ||
| TEST_F(LlvmLibcFMinTest, NegInfArg) { testNegInfArg(&func); } \ | ||
| TEST_F(LlvmLibcFMinTest, BothZero) { testBothZero(&func); } \ | ||
| TEST_F(LlvmLibcFMinTest, Range) { testRange(&func); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| //===-- Utility class to test floor[f|l] ------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "utils/FPUtil/TestHelpers.h" | ||
| #include "utils/MPFRWrapper/MPFRUtils.h" | ||
| #include "utils/UnitTest/Test.h" | ||
|
|
||
| #include <math.h> | ||
|
|
||
| namespace mpfr = __llvm_libc::testing::mpfr; | ||
|
|
||
| template <typename T> class FloorTest : public __llvm_libc::testing::Test { | ||
|
|
||
| DECLARE_SPECIAL_CONSTANTS(T) | ||
|
|
||
| public: | ||
| typedef T (*FloorFunc)(T); | ||
|
|
||
| void testSpecialNumbers(FloorFunc func) { | ||
| EXPECT_FP_EQ(zero, func(zero)); | ||
| EXPECT_FP_EQ(negZero, func(negZero)); | ||
|
|
||
| EXPECT_FP_EQ(inf, func(inf)); | ||
| EXPECT_FP_EQ(negInf, func(negInf)); | ||
|
|
||
| EXPECT_FP_EQ(aNaN, func(aNaN)); | ||
| } | ||
|
|
||
| void testRoundedNumbers(FloorFunc func) { | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.0))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-1.0))); | ||
| EXPECT_FP_EQ(T(10.0), func(T(10.0))); | ||
| EXPECT_FP_EQ(T(-10.0), func(T(-10.0))); | ||
| EXPECT_FP_EQ(T(1234.0), func(T(1234.0))); | ||
| EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0))); | ||
| } | ||
|
|
||
| void testFractions(FloorFunc func) { | ||
| EXPECT_FP_EQ(T(0.0), func(T(0.5))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-0.5))); | ||
| EXPECT_FP_EQ(T(0.0), func(T(0.115))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-0.115))); | ||
| EXPECT_FP_EQ(T(0.0), func(T(0.715))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-0.715))); | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.3))); | ||
| EXPECT_FP_EQ(T(-2.0), func(T(-1.3))); | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.5))); | ||
| EXPECT_FP_EQ(T(-2.0), func(T(-1.5))); | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.75))); | ||
| EXPECT_FP_EQ(T(-2.0), func(T(-1.75))); | ||
| EXPECT_FP_EQ(T(10.0), func(T(10.32))); | ||
| EXPECT_FP_EQ(T(-11.0), func(T(-10.32))); | ||
| EXPECT_FP_EQ(T(10.0), func(T(10.65))); | ||
| EXPECT_FP_EQ(T(-11.0), func(T(-10.65))); | ||
| EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); | ||
| EXPECT_FP_EQ(T(-1235.0), func(T(-1234.38))); | ||
| EXPECT_FP_EQ(T(1234.0), func(T(1234.96))); | ||
| EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96))); | ||
| } | ||
|
|
||
| void testRange(FloorFunc func) { | ||
| constexpr UIntType count = 10000000; | ||
| constexpr UIntType step = UIntType(-1) / count; | ||
| for (UIntType i = 0, v = 0; i <= count; ++i, v += step) { | ||
| T x = T(FPBits(v)); | ||
| if (isnan(x) || isinf(x)) | ||
| continue; | ||
|
|
||
| ASSERT_MPFR_MATCH(mpfr::Operation::Floor, x, func(x), 0.0); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_FLOOR_TESTS(T, func) \ | ||
| using LlvmLibcFloorTest = FloorTest<T>; \ | ||
| TEST_F(LlvmLibcFloorTest, SpecialNumbers) { testSpecialNumbers(&func); } \ | ||
| TEST_F(LlvmLibcFloorTest, RoundedNubmers) { testRoundedNumbers(&func); } \ | ||
| TEST_F(LlvmLibcFloorTest, Fractions) { testFractions(&func); } \ | ||
| TEST_F(LlvmLibcFloorTest, Range) { testRange(&func); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| //===-- Utility class to test round[f|l] ------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "utils/FPUtil/TestHelpers.h" | ||
| #include "utils/MPFRWrapper/MPFRUtils.h" | ||
| #include "utils/UnitTest/Test.h" | ||
|
|
||
| #include <math.h> | ||
|
|
||
| namespace mpfr = __llvm_libc::testing::mpfr; | ||
|
|
||
| template <typename T> class RoundTest : public __llvm_libc::testing::Test { | ||
|
|
||
| DECLARE_SPECIAL_CONSTANTS(T) | ||
|
|
||
| public: | ||
| typedef T (*RoundFunc)(T); | ||
|
|
||
| void testSpecialNumbers(RoundFunc func) { | ||
| EXPECT_FP_EQ(zero, func(zero)); | ||
| EXPECT_FP_EQ(negZero, func(negZero)); | ||
|
|
||
| EXPECT_FP_EQ(inf, func(inf)); | ||
| EXPECT_FP_EQ(negInf, func(negInf)); | ||
|
|
||
| EXPECT_FP_EQ(aNaN, func(aNaN)); | ||
| } | ||
|
|
||
| void testRoundedNumbers(RoundFunc func) { | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.0))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-1.0))); | ||
| EXPECT_FP_EQ(T(10.0), func(T(10.0))); | ||
| EXPECT_FP_EQ(T(-10.0), func(T(-10.0))); | ||
| EXPECT_FP_EQ(T(1234.0), func(T(1234.0))); | ||
| EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0))); | ||
| } | ||
|
|
||
| void testFractions(RoundFunc func) { | ||
| EXPECT_FP_EQ(T(1.0), func(T(0.5))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-0.5))); | ||
| EXPECT_FP_EQ(T(0.0), func(T(0.115))); | ||
| EXPECT_FP_EQ(T(-0.0), func(T(-0.115))); | ||
| EXPECT_FP_EQ(T(1.0), func(T(0.715))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-0.715))); | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.3))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-1.3))); | ||
| EXPECT_FP_EQ(T(2.0), func(T(1.5))); | ||
| EXPECT_FP_EQ(T(-2.0), func(T(-1.5))); | ||
| EXPECT_FP_EQ(T(2.0), func(T(1.75))); | ||
| EXPECT_FP_EQ(T(-2.0), func(T(-1.75))); | ||
| EXPECT_FP_EQ(T(10.0), func(T(10.32))); | ||
| EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); | ||
| EXPECT_FP_EQ(T(11.0), func(T(10.65))); | ||
| EXPECT_FP_EQ(T(-11.0), func(T(-10.65))); | ||
| EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); | ||
| EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); | ||
| EXPECT_FP_EQ(T(1235.0), func(T(1234.96))); | ||
| EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96))); | ||
| } | ||
|
|
||
| void testRange(RoundFunc func) { | ||
| constexpr UIntType count = 10000000; | ||
| constexpr UIntType step = UIntType(-1) / count; | ||
| for (UIntType i = 0, v = 0; i <= count; ++i, v += step) { | ||
| T x = T(FPBits(v)); | ||
| if (isnan(x) || isinf(x)) | ||
| continue; | ||
|
|
||
| ASSERT_MPFR_MATCH(mpfr::Operation::Round, x, func(x), 0.0); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_ROUND_TESTS(T, func) \ | ||
| using LlvmLibcRoundTest = RoundTest<T>; \ | ||
| TEST_F(LlvmLibcRoundTest, SpecialNumbers) { testSpecialNumbers(&func); } \ | ||
| TEST_F(LlvmLibcRoundTest, RoundedNubmers) { testRoundedNumbers(&func); } \ | ||
| TEST_F(LlvmLibcRoundTest, Fractions) { testFractions(&func); } \ | ||
| TEST_F(LlvmLibcRoundTest, Range) { testRange(&func); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| //===-- Utility class to test trunc[f|l] ------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "utils/FPUtil/TestHelpers.h" | ||
| #include "utils/MPFRWrapper/MPFRUtils.h" | ||
| #include "utils/UnitTest/Test.h" | ||
|
|
||
| #include <math.h> | ||
|
|
||
| namespace mpfr = __llvm_libc::testing::mpfr; | ||
|
|
||
| template <typename T> class TruncTest : public __llvm_libc::testing::Test { | ||
|
|
||
| DECLARE_SPECIAL_CONSTANTS(T) | ||
|
|
||
| public: | ||
| typedef T (*TruncFunc)(T); | ||
|
|
||
| void testSpecialNumbers(TruncFunc func) { | ||
| EXPECT_FP_EQ(zero, func(zero)); | ||
| EXPECT_FP_EQ(negZero, func(negZero)); | ||
|
|
||
| EXPECT_FP_EQ(inf, func(inf)); | ||
| EXPECT_FP_EQ(negInf, func(negInf)); | ||
|
|
||
| EXPECT_FP_EQ(aNaN, func(aNaN)); | ||
| } | ||
|
|
||
| void testRoundedNumbers(TruncFunc func) { | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.0))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-1.0))); | ||
| EXPECT_FP_EQ(T(10.0), func(T(10.0))); | ||
| EXPECT_FP_EQ(T(-10.0), func(T(-10.0))); | ||
| EXPECT_FP_EQ(T(1234.0), func(T(1234.0))); | ||
| EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0))); | ||
| } | ||
|
|
||
| void testFractions(TruncFunc func) { | ||
| EXPECT_FP_EQ(T(0.0), func(T(0.5))); | ||
| EXPECT_FP_EQ(T(-0.0), func(T(-0.5))); | ||
| EXPECT_FP_EQ(T(0.0), func(T(0.115))); | ||
| EXPECT_FP_EQ(T(-0.0), func(T(-0.115))); | ||
| EXPECT_FP_EQ(T(0.0), func(T(0.715))); | ||
| EXPECT_FP_EQ(T(-0.0), func(T(-0.715))); | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.3))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-1.3))); | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.5))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-1.5))); | ||
| EXPECT_FP_EQ(T(1.0), func(T(1.75))); | ||
| EXPECT_FP_EQ(T(-1.0), func(T(-1.75))); | ||
| EXPECT_FP_EQ(T(10.0), func(T(10.32))); | ||
| EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); | ||
| EXPECT_FP_EQ(T(10.0), func(T(10.65))); | ||
| EXPECT_FP_EQ(T(-10.0), func(T(-10.65))); | ||
| EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); | ||
| EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); | ||
| EXPECT_FP_EQ(T(1234.0), func(T(1234.96))); | ||
| EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96))); | ||
| } | ||
|
|
||
| void testRange(TruncFunc func) { | ||
| constexpr UIntType count = 10000000; | ||
| constexpr UIntType step = UIntType(-1) / count; | ||
| for (UIntType i = 0, v = 0; i <= count; ++i, v += step) { | ||
| T x = T(FPBits(v)); | ||
| if (isnan(x) || isinf(x)) | ||
| continue; | ||
|
|
||
| ASSERT_MPFR_MATCH(mpfr::Operation::Trunc, x, func(x), 0.0); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #define LIST_TRUNC_TESTS(T, func) \ | ||
| using LlvmLibcTruncTest = TruncTest<T>; \ | ||
| TEST_F(LlvmLibcTruncTest, SpecialNumbers) { testSpecialNumbers(&func); } \ | ||
| TEST_F(LlvmLibcTruncTest, RoundedNubmers) { testRoundedNumbers(&func); } \ | ||
| TEST_F(LlvmLibcTruncTest, Fractions) { testFractions(&func); } \ | ||
| TEST_F(LlvmLibcTruncTest, Range) { testRange(&func); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,13 @@ | ||
| //===-- Unittests for fminf -----------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "FMinTest.h" | ||
|
|
||
| #include "src/math/fminf.h" | ||
|
|
||
| LIST_FMIN_TESTS(float, __llvm_libc::fminf) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,72 +1,13 @@ | ||
| //===-- Unittests for fminl -----------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "FMinTest.h" | ||
|
|
||
| #include "src/math/fminl.h" | ||
|
|
||
| LIST_FMIN_TESTS(long double, __llvm_libc::fminl) |