mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-07-21 13:23:49 +00:00
Fix rational_adaptor division bug.
Fixes https://github.com/boostorg/multiprecision/issues/540
This commit is contained in:
@@ -1099,6 +1099,7 @@ void eval_divide(rational_adaptor<Backend>& result, const rational_adaptor<Backe
|
||||
{
|
||||
if (&result != &a)
|
||||
result = a;
|
||||
result.denom() = arg;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1132,7 +1133,7 @@ void eval_divide(rational_adaptor<Backend>& result, const rational_adaptor<Backe
|
||||
}
|
||||
}
|
||||
template <class Backend>
|
||||
void eval_divide(rational_adaptor<Backend>& result, Backend arg)
|
||||
void eval_divide(rational_adaptor<Backend>& result, const Backend& arg)
|
||||
{
|
||||
eval_divide(result, result, arg);
|
||||
}
|
||||
|
||||
@@ -1230,6 +1230,7 @@ test-suite misc :
|
||||
[ run git_issue_506.cpp ]
|
||||
[ run git_issue_509.cpp : : : [ requires cpp_lib_bit_cast ] ]
|
||||
[ run git_issue_526.cpp ]
|
||||
[ run git_issue_540.cpp ]
|
||||
[ compile git_issue_98.cpp :
|
||||
[ check-target-builds ../config//has_float128 : <define>TEST_FLOAT128 <source>quadmath : ]
|
||||
[ check-target-builds ../config//has_gmp : <define>TEST_GMP <source>gmp : ]
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2023 John Maddock. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <iostream>
|
||||
#include "test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
using Integer = boost::multiprecision::cpp_int;
|
||||
using Rational = boost::multiprecision::cpp_rational;
|
||||
|
||||
Integer one = 1;
|
||||
Integer tenThousand = 10000;
|
||||
Integer threeFourFiveSix = 3456;
|
||||
Rational oneInTenThousand = Rational(one) / tenThousand;
|
||||
Rational oneInThreeFourFiveSix = Rational(one) / threeFourFiveSix;
|
||||
|
||||
Rational result_1(1, 10000);
|
||||
Rational result_2(1, 3456);
|
||||
|
||||
BOOST_CHECK_EQUAL(oneInTenThousand, result_1);
|
||||
BOOST_CHECK_EQUAL(oneInThreeFourFiveSix, result_2);
|
||||
}
|
||||
Reference in New Issue
Block a user