@@ -221,8 +221,9 @@ public:
221
221
222
222
// Eliminate need for explicit casts when comparing.
223
223
224
- int compare (int n) const { return compare (llong_t (n)); }
225
- int compare (unsigned n) const { return compare (ullong_t (n)); }
224
+ int compare (unsigned long n) const { return compare (static_cast <ullong_t >(n)); }
225
+ int compare (int n) const { return compare (static_cast <llong_t > (n)); }
226
+ int compare (unsigned n) const { return compare (static_cast <ullong_t >(n)); }
226
227
227
228
// Tests. These are faster than comparing with 0 or of course %2.
228
229
@@ -330,4 +331,28 @@ inline bool operator>= (const BigInt &lhs, const BigInt &rhs) { return lhs.compa
330
331
inline bool operator == (const BigInt &lhs, const BigInt &rhs) { return lhs.compare (rhs) == 0 ; }
331
332
inline bool operator != (const BigInt &lhs, const BigInt &rhs) { return lhs.compare (rhs) != 0 ; }
332
333
334
+
335
+ // These operators are all associative, so we can define them all for
336
+ // primitives on the LHS and RHS.
337
+ #define COMPARISON_OPERATORS (OTHER ) \
338
+ inline bool operator < (const BigInt &lhs, OTHER rhs) { return lhs.compare (rhs) < 0 ; } \
339
+ inline bool operator > (const BigInt &lhs, OTHER rhs) { return lhs.compare (rhs) > 0 ; } \
340
+ inline bool operator <= (const BigInt &lhs, OTHER rhs) { return lhs.compare (rhs) <= 0 ; } \
341
+ inline bool operator >= (const BigInt &lhs, OTHER rhs) { return lhs.compare (rhs) >= 0 ; } \
342
+ inline bool operator == (const BigInt &lhs, OTHER rhs) { return lhs.compare (rhs) == 0 ; } \
343
+ inline bool operator != (const BigInt &lhs, OTHER rhs) { return lhs.compare (rhs) != 0 ; } \
344
+ inline bool operator < (OTHER lhs, const BigInt &rhs) { return -rhs.compare (lhs) < 0 ; } \
345
+ inline bool operator > (OTHER lhs, const BigInt &rhs) { return -rhs.compare (lhs) > 0 ; } \
346
+ inline bool operator <= (OTHER lhs, const BigInt &rhs) { return -rhs.compare (lhs) <= 0 ; } \
347
+ inline bool operator >= (OTHER lhs, const BigInt &rhs) { return -rhs.compare (lhs) >= 0 ; } \
348
+ inline bool operator == (OTHER lhs, const BigInt &rhs) { return -rhs.compare (lhs) == 0 ; } \
349
+ inline bool operator != (OTHER lhs, const BigInt &rhs) { return -rhs.compare (lhs) != 0 ; }
350
+
351
+ COMPARISON_OPERATORS (BigInt::llong_t )
352
+ COMPARISON_OPERATORS(BigInt::ullong_t )
353
+ COMPARISON_OPERATORS(unsigned long )
354
+ COMPARISON_OPERATORS(int )
355
+ COMPARISON_OPERATORS(unsigned )
356
+ #undef COMPARISON_OPERATORS
357
+
333
358
#endif // ndef BIGINT_HH
0 commit comments