diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -29,6 +29,9 @@ libc.src.math.floor libc.src.math.floorf libc.src.math.floorl + libc.src.math.fmin + libc.src.math.fminf + libc.src.math.fminl libc.src.math.frexp libc.src.math.frexpf libc.src.math.frexpl diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td --- a/libc/config/linux/api.td +++ b/libc/config/linux/api.td @@ -163,6 +163,9 @@ "floor", "floorf", "floorl", + "fmin", + "fminf", + "fminl", "frexp", "frexpf", "frexpl", diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -62,6 +62,9 @@ libc.src.math.floor libc.src.math.floorf libc.src.math.floorl + libc.src.math.fmin + libc.src.math.fminf + libc.src.math.fminl libc.src.math.frexp libc.src.math.frexpf libc.src.math.frexpl diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -205,6 +205,10 @@ FunctionSpec<"floorf", RetValSpec, [ArgSpec]>, FunctionSpec<"floorl", RetValSpec, [ArgSpec]>, + FunctionSpec<"fmin", RetValSpec, [ArgSpec, ArgSpec]>, + FunctionSpec<"fminf", RetValSpec, [ArgSpec, ArgSpec]>, + FunctionSpec<"fminl", RetValSpec, [ArgSpec, ArgSpec]>, + FunctionSpec<"frexp", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"frexpf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"frexpl", RetValSpec, [ArgSpec, ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -413,3 +413,39 @@ COMPILE_OPTIONS -O2 ) + +add_entrypoint_object( + fmin + SRCS + fmin.cpp + HDRS + fmin.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + fminf + SRCS + fminf.cpp + HDRS + fminf.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + fminl + SRCS + fminl.cpp + HDRS + fminl.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) diff --git a/libc/src/math/fmin.h b/libc/src/math/fmin.h new file mode 100644 --- /dev/null +++ b/libc/src/math/fmin.h @@ -0,0 +1,18 @@ +//===-- Implementation header for fmin --------------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_FMIN_H +#define LLVM_LIBC_SRC_MATH_FMIN_H + +namespace __llvm_libc { + +double fmin(double x, double y); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_FMIN_H diff --git a/libc/src/math/fmin.cpp b/libc/src/math/fmin.cpp new file mode 100644 --- /dev/null +++ b/libc/src/math/fmin.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of fmin function -----------------------------------===// +// +// 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 "src/__support/common.h" +#include "utils/FPUtil/BasicOperations.h" + +namespace __llvm_libc { + +double LLVM_LIBC_ENTRYPOINT(fmin)(double x, double y) { + return fputil::fmin(x, y); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/fminf.h b/libc/src/math/fminf.h new file mode 100644 --- /dev/null +++ b/libc/src/math/fminf.h @@ -0,0 +1,18 @@ +//===-- Implementation header for fminf -------------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_FMINF_H +#define LLVM_LIBC_SRC_MATH_FMINF_H + +namespace __llvm_libc { + +float fminf(float x, float y); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_FMINF_H diff --git a/libc/src/math/fminf.cpp b/libc/src/math/fminf.cpp new file mode 100644 --- /dev/null +++ b/libc/src/math/fminf.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of fminf function ----------------------------------===// +// +// 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 "src/__support/common.h" +#include "utils/FPUtil/BasicOperations.h" + +namespace __llvm_libc { + +float LLVM_LIBC_ENTRYPOINT(fminf)(float x, float y) { + return fputil::fmin(x, y); +} + +} // namespace __llvm_libc \ No newline at end of file diff --git a/libc/src/math/fminl.h b/libc/src/math/fminl.h new file mode 100644 --- /dev/null +++ b/libc/src/math/fminl.h @@ -0,0 +1,18 @@ +//===-- Implementation header for fminl -------------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_FMINL_H +#define LLVM_LIBC_SRC_MATH_FMINL_H + +namespace __llvm_libc { + +long double fminl(long double x, long double y); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_FMINL_H diff --git a/libc/src/math/fminl.cpp b/libc/src/math/fminl.cpp new file mode 100644 --- /dev/null +++ b/libc/src/math/fminl.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of fminl function ----------------------------------===// +// +// 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 "src/__support/common.h" +#include "utils/FPUtil/BasicOperations.h" + +namespace __llvm_libc { + +long double LLVM_LIBC_ENTRYPOINT(fminl)(long double x, long double y) { + return fputil::fmin(x, y); +} + +} // namespace __llvm_libc diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -437,3 +437,42 @@ libc.src.math.modfl libc.utils.FPUtil.fputil ) + +add_math_unittest( + fminf_test + NEED_MPFR + SUITE + libc_math_unittests + SRCS + fminf_test.cpp + DEPENDS + libc.include.math + libc.src.math.fminf + libc.utils.FPUtil.fputil +) + +add_math_unittest( + fmin_test + NEED_MPFR + SUITE + libc_math_unittests + SRCS + fmin_test.cpp + DEPENDS + libc.include.math + libc.src.math.fmin + libc.utils.FPUtil.fputil +) + +add_math_unittest( + fminl_test + NEED_MPFR + SUITE + libc_math_unittests + SRCS + fminl_test.cpp + DEPENDS + libc.include.math + libc.src.math.fminl + libc.utils.FPUtil.fputil +) diff --git a/libc/test/src/math/fmin_test.cpp b/libc/test/src/math/fmin_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/fmin_test.cpp @@ -0,0 +1,69 @@ +//===-- Unittests for fmin -----------------------------------------------===// +// +// 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 + +#include "include/math.h" +#include "src/math/fmin.h" +#include "utils/FPUtil/FPBits.h" +#include "utils/MPFRWrapper/MPFRUtils.h" +#include "utils/UnitTest/Test.h" + +using FPBits = __llvm_libc::fputil::FPBits; + +namespace mpfr = __llvm_libc::testing::mpfr; + +// Zero tolerance; As in, exact match with MPFR result. +static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::doublePrecision, 0, + 0}; + +#define EXPECT_FP_EQ(LHS, RHS) \ + EXPECT_EQ(FPBits(LHS).bitsAsUInt(), FPBits(RHS).bitsAsUInt()) + +TEST(FminTest, SpecialNumbers) { + std::vector orderedValues; + + orderedValues.push_back(double(FPBits::negInf())); + orderedValues.push_back(-1.2345); + orderedValues.push_back(double(FPBits::negZero())); + orderedValues.push_back(0.0); + orderedValues.push_back(1.2345); + orderedValues.push_back(double(FPBits::inf())); + + for (size_t i = 0; i < orderedValues.size(); ++i) { + for (size_t j = 0; j < orderedValues.size(); ++j) { + EXPECT_FP_EQ(orderedValues[(i < j ? i : j)], + __llvm_libc::fmin(orderedValues[i], orderedValues[j])); + } + } + + double nan = FPBits::buildNaN(1); + + EXPECT_FP_EQ(orderedValues[0], __llvm_libc::fmin(nan, orderedValues[0])); + + EXPECT_FP_EQ(orderedValues[0], __llvm_libc::fmin(orderedValues[0], nan)); + + EXPECT_NE(isnan(__llvm_libc::fmin(nan, nan)), 0); +} + +TEST(FminTest, InDoubleRange) { + using UIntType = FPBits::UIntType; + constexpr UIntType count = 10000000; + constexpr UIntType step = UIntType(-1) / count; + for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count; + ++i, v += step, w -= step) { + double x = FPBits(v), y = FPBits(w); + if (isnan(x) || isinf(x) || x == 0) + continue; + if (isnan(y) || isinf(y) || y == 0) + continue; + + ASSERT_MPFR_MATCH_BINOP(mpfr::BinaryOperation::Fmin, x, y, + __llvm_libc::fmin(x, y), tolerance); + } +} diff --git a/libc/test/src/math/fminf_test.cpp b/libc/test/src/math/fminf_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/fminf_test.cpp @@ -0,0 +1,69 @@ +//===-- 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 + +#include "include/math.h" +#include "src/math/fminf.h" +#include "utils/FPUtil/FPBits.h" +#include "utils/MPFRWrapper/MPFRUtils.h" +#include "utils/UnitTest/Test.h" + +using FPBits = __llvm_libc::fputil::FPBits; + +namespace mpfr = __llvm_libc::testing::mpfr; + +// Zero tolerance; As in, exact match with MPFR result. +static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::floatPrecision, 0, + 0}; + +#define EXPECT_FP_EQ(LHS, RHS) \ + EXPECT_EQ(FPBits(LHS).bitsAsUInt(), FPBits(RHS).bitsAsUInt()) + +TEST(FminfTest, SpecialNumbers) { + std::vector orderedValues; + + orderedValues.push_back(float(FPBits::negInf())); + orderedValues.push_back(-1.2345f); + orderedValues.push_back(float(FPBits::negZero())); + orderedValues.push_back(0.0f); + orderedValues.push_back(1.2345f); + orderedValues.push_back(float(FPBits::inf())); + + for (size_t i = 0; i < orderedValues.size(); ++i) { + for (size_t j = 0; j < orderedValues.size(); ++j) { + EXPECT_FP_EQ(orderedValues[(i < j ? i : j)], + __llvm_libc::fminf(orderedValues[i], orderedValues[j])); + } + } + + float nan = static_cast(FPBits::buildNaN(1)); + + EXPECT_FP_EQ(orderedValues[0], __llvm_libc::fminf(nan, orderedValues[0])); + + EXPECT_FP_EQ(orderedValues[0], __llvm_libc::fminf(orderedValues[0], nan)); + + EXPECT_NE(isnan(__llvm_libc::fminf(nan, nan)), 0); +} + +TEST(FminfTest, InFloatRange) { + using UIntType = FPBits::UIntType; + constexpr UIntType count = 10000000; + constexpr UIntType step = UIntType(-1) / count; + for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count; + ++i, v += step, w -= step) { + float x = FPBits(v), y = FPBits(w); + if (isnan(x) || isinf(x) || x == 0) + continue; + if (isnan(y) || isinf(y) || y == 0) + continue; + + ASSERT_MPFR_MATCH_BINOP(mpfr::BinaryOperation::Fmin, x, y, + __llvm_libc::fminf(x, y), tolerance); + } +} diff --git a/libc/test/src/math/fminl_test.cpp b/libc/test/src/math/fminl_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/fminl_test.cpp @@ -0,0 +1,71 @@ +//===-- Unittests for fmin -----------------------------------------------===// +// +// 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 + +#include "include/math.h" +#include "src/math/fminl.h" +#include "utils/FPUtil/FPBits.h" +#include "utils/MPFRWrapper/MPFRUtils.h" +#include "utils/UnitTest/Test.h" + +using FPBits = __llvm_libc::fputil::FPBits; + +namespace mpfr = __llvm_libc::testing::mpfr; + +// Zero tolerance; As in, exact match with MPFR result. +static constexpr mpfr::Tolerance tolerance{mpfr::Tolerance::doublePrecision, 0, + 0}; + +#define GET_BITS(LD_VALUE) \ + static_cast(FPBits(LD_VALUE).bitsAsUInt()) + +#define EXPECT_FP_EQ(LHS, RHS) EXPECT_EQ(GET_BITS(LHS), GET_BITS(RHS)) + +TEST(FminlTest, SpecialNumbers) { + std::vector orderedValues; + + orderedValues.push_back(static_cast(FPBits::negInf())); + orderedValues.push_back(-1.2345l); + orderedValues.push_back(static_cast(FPBits::negZero())); + orderedValues.push_back(0.0l); + orderedValues.push_back(1.2345l); + orderedValues.push_back(static_cast(FPBits::inf())); + + for (size_t i = 0; i < orderedValues.size(); ++i) { + for (size_t j = 0; j < orderedValues.size(); ++j) { + EXPECT_FP_EQ(orderedValues[(i < j ? i : j)], + __llvm_libc::fminl(orderedValues[i], orderedValues[j])); + } + } + + long double nan = static_cast(FPBits::buildNaN(1)); + + EXPECT_FP_EQ(orderedValues[0], __llvm_libc::fminl(nan, orderedValues[0])); + + EXPECT_FP_EQ(orderedValues[0], __llvm_libc::fminl(orderedValues[0], nan)); + + EXPECT_NE(isnan(__llvm_libc::fminl(nan, nan)), 0); +} + +TEST(FminlTest, InLongDoubleRange) { + using UIntType = FPBits::UIntType; + constexpr UIntType count = 10000000; + constexpr UIntType step = UIntType(-1) / count; + for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count; + ++i, v += step, w -= step) { + long double x = FPBits(v), y = FPBits(w); + if (isnan(x) || isinf(x) || x == 0) + continue; + if (isnan(y) || isinf(y) || y == 0) + continue; + + ASSERT_MPFR_MATCH_BINOP(mpfr::BinaryOperation::Fmin, x, y, + __llvm_libc::fminl(x, y), tolerance); + } +} diff --git a/libc/utils/FPUtil/BasicOperations.h b/libc/utils/FPUtil/BasicOperations.h --- a/libc/utils/FPUtil/BasicOperations.h +++ b/libc/utils/FPUtil/BasicOperations.h @@ -24,6 +24,25 @@ return T(bits); } +template ::Value, int> = 0> +static inline T fmin(T x, T y) { + FPBits bitx(x), bity(y); + + if (bitx.isNaN()) { + return y; + } else if (bity.isNaN()) { + return x; + } else if (bitx.sign != bity.sign) { + // To make sure that fmin(+0, -0) == -0 == fmin(-0, +0), whenever x and + // y has different signs and both are not NaNs, we return the number + // with negative sign. + return (bitx.sign ? x : y); + } else { + return (x < y ? x : y); + } +} + } // namespace fputil } // namespace __llvm_libc diff --git a/libc/utils/FPUtil/CMakeLists.txt b/libc/utils/FPUtil/CMakeLists.txt --- a/libc/utils/FPUtil/CMakeLists.txt +++ b/libc/utils/FPUtil/CMakeLists.txt @@ -12,6 +12,7 @@ FloatOperations.h FloatProperties.h FPBits.h + BasicOperations.h ManipulationFunctions.h DEPENDS libc.utils.CPP.standalone_cpp diff --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h --- a/libc/utils/MPFRWrapper/MPFRUtils.h +++ b/libc/utils/MPFRWrapper/MPFRUtils.h @@ -51,27 +51,45 @@ Trunc }; +enum class BinaryOperation : int { Fmin }; + namespace internal { template bool compare(Operation op, T input, T libcOutput, const Tolerance &t); +template +bool compare(BinaryOperation op, T input1, T input2, T libcOutput, + const Tolerance &t); + template class MPFRMatcher : public testing::Matcher { static_assert(__llvm_libc::cpp::IsFloatingPointType::Value, "MPFRMatcher can only be used with floating point values."); Operation operation; - T input; + BinaryOperation binaryOperation; + T input, secondInput; Tolerance tolerance; T matchValue; + int numberOfInputs; public: MPFRMatcher(Operation op, T testInput, Tolerance &t) - : operation(op), input(testInput), tolerance(t) {} + : operation(op), input(testInput), tolerance(t), numberOfInputs(1) {} + + MPFRMatcher(BinaryOperation op, T testInput1, T testInput2, Tolerance &t) + : binaryOperation(op), input(testInput1), secondInput(testInput2), + tolerance(t), numberOfInputs(2) {} bool match(T libcResult) { matchValue = libcResult; - return internal::compare(operation, input, libcResult, tolerance); + if (numberOfInputs == 1) { + return internal::compare(operation, input, libcResult, tolerance); + } else { + // numberOfInputs == 2 + return internal::compare(binaryOperation, input, secondInput, libcResult, + tolerance); + } } void explainError(testutils::StreamWrapper &OS) override; @@ -88,6 +106,15 @@ return internal::MPFRMatcher(op, input, t); } +template +__attribute__((no_sanitize("address"))) internal::MPFRMatcher +getMPFRMatcher(BinaryOperation op, T input1, T input2, Tolerance t) { + static_assert( + __llvm_libc::cpp::IsFloatingPointType::Value, + "getMPFRMatcher can only be used to match floating point results."); + return internal::MPFRMatcher(op, input1, input2, t); +} + } // namespace mpfr } // namespace testing } // namespace __llvm_libc @@ -100,4 +127,12 @@ ASSERT_THAT(matchValue, __llvm_libc::testing::mpfr::getMPFRMatcher( \ op, input, tolerance)) +#define EXPECT_MPFR_MATCH_BINOP(op, input1, input2, matchValue, tolerance) \ + EXPECT_THAT(matchValue, __llvm_libc::testing::mpfr::getMPFRMatcher( \ + op, input1, input2, tolerance)) + +#define ASSERT_MPFR_MATCH_BINOP(op, input1, input2, matchValue, tolerance) \ + ASSERT_THAT(matchValue, __llvm_libc::testing::mpfr::getMPFRMatcher( \ + op, input1, input2, tolerance)) + #endif // LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp --- a/libc/utils/MPFRWrapper/MPFRUtils.cpp +++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp @@ -125,6 +125,18 @@ } } + template ::Value, int> = 0> + MPFRNumber(BinaryOperation op, XType rawValue1, XType rawValue2) { + mpfr_init2(value, mpfrPrecision); + MPFRNumber mpfrInput1(rawValue1), mpfrInput2(rawValue2); + switch (op) { + case BinaryOperation::Fmin: + mpfr_min(value, mpfrInput1.value, mpfrInput2.value, MPFR_RNDN); + break; + } + } + MPFRNumber(const MPFRNumber &other) { mpfr_set(value, other.value, MPFR_RNDN); } @@ -164,7 +176,9 @@ template void MPFRMatcher::explainError(testutils::StreamWrapper &OS) { - MPFRNumber mpfrResult(operation, input); + MPFRNumber mpfrResult = + (numberOfInputs == 1 ? MPFRNumber(operation, input) + : MPFRNumber(binaryOperation, input, secondInput)); MPFRNumber mpfrInput(input); MPFRNumber mpfrMatchValue(matchValue); MPFRNumber mpfrToleranceValue(matchValue, tolerance); @@ -175,8 +189,16 @@ // llvm::utohexstr to handle __uint128_t values correctly. OS << "Match value not within tolerance value of MPFR result:\n" << " Input decimal: " << mpfrInput.str() << '\n' - << " Input bits: 0x" << llvm::utohexstr(inputBits.bitsAsUInt()) << '\n' - << " Match decimal: " << mpfrMatchValue.str() << '\n' + << " Input bits: 0x" << llvm::utohexstr(inputBits.bitsAsUInt()) + << '\n'; + if (numberOfInputs == 2) { + MPFRNumber mpfrSecondInput(secondInput); + FPBits secondInputBits(secondInput); + OS << " Second Input decimal: " << mpfrSecondInput.str() << '\n' + << " Second input bits: 0x" + << llvm::utohexstr(secondInputBits.bitsAsUInt()) << '\n'; + } + OS << " Match decimal: " << mpfrMatchValue.str() << '\n' << " Match bits: 0x" << llvm::utohexstr(matchBits.bitsAsUInt()) << '\n' << " MPFR result: " << mpfrResult.str() << '\n' << "Tolerance value: " << mpfrToleranceValue.str() << '\n'; @@ -201,6 +223,23 @@ template bool compare(Operation, long double, long double, const Tolerance &); +template +bool compare(BinaryOperation binop, T input1, T input2, T libcResult, + const Tolerance &t) { + MPFRNumber mpfrResult(binop, input1, input2); + MPFRNumber mpfrLibcResult(libcResult); + MPFRNumber mpfrToleranceValue(libcResult, t); + + return mpfrResult.isEqual(mpfrLibcResult, mpfrToleranceValue); +}; + +template bool compare(BinaryOperation, float, float, float, + const Tolerance &); +template bool compare(BinaryOperation, double, double, double, + const Tolerance &); +template bool compare(BinaryOperation, long double, long double, + long double, const Tolerance &); + } // namespace internal } // namespace mpfr