@@ -308,85 +308,28 @@ class base_uint
308
308
return ret;
309
309
}
310
310
311
-
312
- friend inline bool operator <(const base_uint& a, const base_uint& b)
313
- {
314
- for (int i = base_uint::WIDTH-1 ; i >= 0 ; i--)
315
- {
316
- if (a.pn [i] < b.pn [i])
317
- return true ;
318
- else if (a.pn [i] > b.pn [i])
319
- return false ;
320
- }
321
- return false ;
322
- }
323
-
324
- friend inline bool operator <=(const base_uint& a, const base_uint& b)
325
- {
326
- for (int i = base_uint::WIDTH-1 ; i >= 0 ; i--)
327
- {
328
- if (a.pn [i] < b.pn [i])
329
- return true ;
330
- else if (a.pn [i] > b.pn [i])
331
- return false ;
311
+ int CompareTo (const base_uint& b) const {
312
+ for (int i = base_uint::WIDTH-1 ; i >= 0 ; i--) {
313
+ if (pn[i] < b.pn [i])
314
+ return -1 ;
315
+ if (pn[i] > b.pn [i])
316
+ return 1 ;
332
317
}
333
- return true ;
334
- }
335
-
336
- friend inline bool operator >(const base_uint& a, const base_uint& b)
337
- {
338
- for (int i = base_uint::WIDTH-1 ; i >= 0 ; i--)
339
- {
340
- if (a.pn [i] > b.pn [i])
341
- return true ;
342
- else if (a.pn [i] < b.pn [i])
343
- return false ;
344
- }
345
- return false ;
318
+ return 0 ;
346
319
}
347
320
348
- friend inline bool operator >=(const base_uint& a, const base_uint& b)
349
- {
350
- for (int i = base_uint::WIDTH-1 ; i >= 0 ; i--)
351
- {
352
- if (a.pn [i] > b.pn [i])
353
- return true ;
354
- else if (a.pn [i] < b.pn [i])
321
+ bool EqualTo (uint64_t b) const {
322
+ for (int i = base_uint::WIDTH-1 ; i >= 2 ; i--) {
323
+ if (pn[i])
355
324
return false ;
356
325
}
357
- return true ;
358
- }
359
-
360
- friend inline bool operator ==(const base_uint& a, const base_uint& b)
361
- {
362
- for (int i = 0 ; i < base_uint::WIDTH; i++)
363
- if (a.pn [i] != b.pn [i])
364
- return false ;
365
- return true ;
366
- }
367
-
368
- friend inline bool operator ==(const base_uint& a, uint64_t b)
369
- {
370
- if (a.pn [0 ] != (unsigned int )b)
326
+ if (pn[1 ] != (b >> 32 ))
371
327
return false ;
372
- if (a. pn [1 ] != (unsigned int )(b >> 32 ))
328
+ if (pn[0 ] != (b & 0xfffffffful ))
373
329
return false ;
374
- for (int i = 2 ; i < base_uint::WIDTH; i++)
375
- if (a.pn [i] != 0 )
376
- return false ;
377
330
return true ;
378
331
}
379
332
380
- friend inline bool operator !=(const base_uint& a, const base_uint& b)
381
- {
382
- return (!(a == b));
383
- }
384
-
385
- friend inline bool operator !=(const base_uint& a, uint64_t b)
386
- {
387
- return (!(a == b));
388
- }
389
-
390
333
friend inline const base_uint operator +(const base_uint& a, const base_uint& b) { return base_uint (a) += b; }
391
334
friend inline const base_uint operator -(const base_uint& a, const base_uint& b) { return base_uint (a) -= b; }
392
335
friend inline const base_uint operator *(const base_uint& a, const base_uint& b) { return base_uint (a) *= b; }
@@ -397,6 +340,14 @@ class base_uint
397
340
friend inline const base_uint operator >>(const base_uint& a, int shift) { return base_uint (a) >>= shift; }
398
341
friend inline const base_uint operator <<(const base_uint& a, int shift) { return base_uint (a) <<= shift; }
399
342
friend inline const base_uint operator *(const base_uint& a, uint32_t b) { return base_uint (a) *= b; }
343
+ friend inline bool operator ==(const base_uint& a, const base_uint& b) { return a.CompareTo (b) == 0 ; }
344
+ friend inline bool operator !=(const base_uint& a, const base_uint& b) { return a.CompareTo (b) != 0 ; }
345
+ friend inline bool operator >(const base_uint& a, const base_uint& b) { return a.CompareTo (b) > 0 ; }
346
+ friend inline bool operator <(const base_uint& a, const base_uint& b) { return a.CompareTo (b) < 0 ; }
347
+ friend inline bool operator >=(const base_uint& a, const base_uint& b) { return a.CompareTo (b) >= 0 ; }
348
+ friend inline bool operator <=(const base_uint& a, const base_uint& b) { return a.CompareTo (b) <= 0 ; }
349
+ friend inline bool operator ==(const base_uint& a, uint64_t b) { return a.EqualTo (b); }
350
+ friend inline bool operator !=(const base_uint& a, uint64_t b) { return !a.EqualTo (b); }
400
351
401
352
std::string GetHex () const
402
353
{
0 commit comments