Skip to content

Commit 3a28687

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
Define big-int operators for signed long
Trying to use numeric_cast_v<signed long> resulted in ambiguous overload errors. At the moment, we are in a few places wrongly using `numeric_cast_v<std::size_t>` when it should be `numeric_cast_v<std::ptrdiff_t>`. On non-Windows platforms, `std::ptrdiff_t` is `signed long`. To enable the use of the correct `numeric_cast_v`, we need to support the comparison operators.
1 parent 7671a1f commit 3a28687

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/big-int/bigint.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ public:
221221

222222
// Eliminate need for explicit casts when comparing.
223223

224+
int compare(long n) const
225+
{
226+
return compare(static_cast<llong_t>(n));
227+
}
224228
int compare (unsigned long n) const { return compare (static_cast<ullong_t>(n)); }
225229
int compare (int n) const { return compare (static_cast<llong_t> (n)); }
226230
int compare (unsigned n) const { return compare (static_cast<ullong_t>(n)); }
@@ -257,6 +261,7 @@ public:
257261
BigInt &operator/=(FROM x) { return operator/=(static_cast<TO>(x)); } \
258262
BigInt &operator%=(FROM x) { return operator%=(static_cast<TO>(x)); }
259263

264+
OVERLOAD_IN_PLACE_OPERATOR(long, llong_t)
260265
OVERLOAD_IN_PLACE_OPERATOR(unsigned long, ullong_t)
261266
OVERLOAD_IN_PLACE_OPERATOR(int, llong_t)
262267
OVERLOAD_IN_PLACE_OPERATOR(unsigned, ullong_t)
@@ -317,6 +322,7 @@ inline BigInt operator% (const BigInt &lhs, const BigInt &rhs) { return BigInt(l
317322

318323
BINARY_ARITHMETIC_OPERATORS(BigInt::llong_t)
319324
BINARY_ARITHMETIC_OPERATORS(BigInt::ullong_t)
325+
BINARY_ARITHMETIC_OPERATORS(long)
320326
BINARY_ARITHMETIC_OPERATORS(unsigned long)
321327
BINARY_ARITHMETIC_OPERATORS(int)
322328
BINARY_ARITHMETIC_OPERATORS(unsigned)
@@ -350,6 +356,7 @@ inline bool operator!= (const BigInt &lhs, const BigInt &rhs) { return lhs.compa
350356

351357
COMPARISON_OPERATORS(BigInt::llong_t)
352358
COMPARISON_OPERATORS(BigInt::ullong_t)
359+
COMPARISON_OPERATORS(long)
353360
COMPARISON_OPERATORS(unsigned long)
354361
COMPARISON_OPERATORS(int)
355362
COMPARISON_OPERATORS(unsigned)

0 commit comments

Comments
 (0)