Skip to content

Commit 1bcb9a5

Browse files
committed
fix bigint overflow bug
1 parent a828eb1 commit 1bcb9a5

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

source/mir/bignum/decimal.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,8 @@ struct Decimal(size_t maxSize64)
981981
ref opOpAssign(string op, size_t rhsMaxSize64)(ref const Decimal!rhsMaxSize64 rhs) @safe pure return
982982
if (op == "+" || op == "-")
983983
{
984-
BigInt!rhsMaxSize64 rhsCopy;
984+
import mir.utility: max;
985+
BigInt!(max(rhsMaxSize64, maxSize64, 256u)) rhsCopy = void;
985986
BigIntView!(const size_t) rhsView;
986987
auto expDiff = exponent - rhs.exponent;
987988
if (expDiff >= 0)

source/mir/math/sum.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ unittest
3838
assert(ar.sum!"kbn" == 0.7000000000000455);
3939
assert(ar.sum!"kb2" == 0.7000000000000455);
4040
assert(ar.sum!"precise" == 0.7000000000000455);
41+
42+
assert([1e-20, 1].sum!"decimal" == 1);
4143
}
4244

4345
///

0 commit comments

Comments
 (0)