Correct eval_increment corner case.

Fixes https://github.com/boostorg/multiprecision/issues/277.
This commit is contained in:
jzmaddock
2020-12-26 16:14:40 +00:00
parent 4700c04795
commit 10fd5267e9
3 changed files with 42 additions and 1 deletions
+1 -1
View File
@@ -263,7 +263,7 @@ eval_increment(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocato
else if (result.sign() && result.limbs()[0])
{
--result.limbs()[0];
if (!result.limbs()[0])
if (!result.limbs()[0] && (result.size() == 1))
result.sign(false);
}
else
+1
View File
@@ -1024,6 +1024,7 @@ test-suite misc :
[ run git_issue_175.cpp ]
[ run git_issue_248.cpp ]
[ run git_issue_265.cpp : : : [ check-target-builds ../config//has_mpfr : <source>gmp <source>mpfr : <build>no ] ]
[ run git_issue_277.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 : ]
+40
View File
@@ -0,0 +1,40 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2019 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 "test.hpp"
template <class I>
void test()
{
I val(1);
val <<= 512;
I t(val);
++t;
BOOST_CHECK_EQUAL(t - val, 1);
--t;
BOOST_CHECK_EQUAL(t, val);
--t;
BOOST_CHECK_EQUAL(val - t, 1);
val = -val;
t = val;
--t;
BOOST_CHECK_EQUAL(t - val, -1);
++t;
BOOST_CHECK_EQUAL(t, val);
++t;
BOOST_CHECK_EQUAL(val - t, -1);
}
int main()
{
test<boost::multiprecision::cpp_int>();
test<boost::multiprecision::int1024_t>();
test<boost::multiprecision::checked_int1024_t>();
return boost::report_errors();
}