OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of fixnum; | 5 part of fixnum; |
6 | 6 |
7 /** | 7 /** |
8 * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. | 8 * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. |
9 * Arithmetic operations may overflow in order to maintain this range. | 9 * Arithmetic operations may overflow in order to maintain this range. |
10 */ | 10 */ |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 o = new Int64(other); | 462 o = new Int64(other); |
463 } else if (other is Int32) { | 463 } else if (other is Int32) { |
464 o = other.toInt64(); | 464 o = other.toInt64(); |
465 } | 465 } |
466 if (o != null) { | 466 if (o != null) { |
467 return _l == o._l && _m == o._m && _h == o._h; | 467 return _l == o._l && _m == o._m && _h == o._h; |
468 } | 468 } |
469 return false; | 469 return false; |
470 } | 470 } |
471 | 471 |
472 int compareTo(Comparable other) { | 472 int compareTo(IntX other) =>_compareTo(other); |
| 473 |
| 474 int _compareTo(other) { |
473 Int64 o = _promote(other); | 475 Int64 o = _promote(other); |
474 int signa = _h >> (_BITS2 - 1); | 476 int signa = _h >> (_BITS2 - 1); |
475 int signb = o._h >> (_BITS2 - 1); | 477 int signb = o._h >> (_BITS2 - 1); |
476 if (signa != signb) { | 478 if (signa != signb) { |
477 return signa == 0 ? 1 : -1; | 479 return signa == 0 ? 1 : -1; |
478 } | 480 } |
479 if (_h > o._h) { | 481 if (_h > o._h) { |
480 return 1; | 482 return 1; |
481 } else if (_h < o._h) { | 483 } else if (_h < o._h) { |
482 return -1; | 484 return -1; |
483 } | 485 } |
484 if (_m > o._m) { | 486 if (_m > o._m) { |
485 return 1; | 487 return 1; |
486 } else if (_m < o._m) { | 488 } else if (_m < o._m) { |
487 return -1; | 489 return -1; |
488 } | 490 } |
489 if (_l > o._l) { | 491 if (_l > o._l) { |
490 return 1; | 492 return 1; |
491 } else if (_l < o._l) { | 493 } else if (_l < o._l) { |
492 return -1; | 494 return -1; |
493 } | 495 } |
494 return 0; | 496 return 0; |
495 } | 497 } |
496 | 498 |
497 bool operator <(other) { | 499 bool operator <(other) => _compareTo(other) < 0; |
498 return this.compareTo(other) < 0; | 500 bool operator <=(other) => _compareTo(other) <= 0; |
499 } | 501 bool operator >(other) => this._compareTo(other) > 0; |
500 | 502 bool operator >=(other) => _compareTo(other) >= 0; |
501 bool operator <=(other) { | |
502 return this.compareTo(other) <= 0; | |
503 } | |
504 | |
505 bool operator >(other) { | |
506 return this.compareTo(other) > 0; | |
507 } | |
508 | |
509 bool operator >=(other) { | |
510 return this.compareTo(other) >= 0; | |
511 } | |
512 | 503 |
513 bool get isEven => (_l & 0x1) == 0; | 504 bool get isEven => (_l & 0x1) == 0; |
514 bool get isMaxValue => (_h == _MASK2 >> 1) && _m == _MASK && _l == _MASK; | 505 bool get isMaxValue => (_h == _MASK2 >> 1) && _m == _MASK && _l == _MASK; |
515 bool get isMinValue => _h == _SIGN_BIT_MASK && _m == 0 && _l == 0; | 506 bool get isMinValue => _h == _SIGN_BIT_MASK && _m == 0 && _l == 0; |
516 bool get isNegative => (_h & _SIGN_BIT_MASK) != 0; | 507 bool get isNegative => (_h & _SIGN_BIT_MASK) != 0; |
517 bool get isOdd => (_l & 0x1) == 1; | 508 bool get isOdd => (_l & 0x1) == 1; |
518 bool get isZero => _h == 0 && _m == 0 && _l == 0; | 509 bool get isZero => _h == 0 && _m == 0 && _l == 0; |
519 | 510 |
520 int get bitLength { | 511 int get bitLength { |
521 if (isZero) return 0; | 512 if (isZero) return 0; |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 if (r0 == 0 && r1 == 0 && r2 == 0) { | 1035 if (r0 == 0 && r1 == 0 && r2 == 0) { |
1045 return ZERO; | 1036 return ZERO; |
1046 } else { | 1037 } else { |
1047 return _sub(b0, b1, b2, r0, r1, r2); | 1038 return _sub(b0, b1, b2, r0, r1, r2); |
1048 } | 1039 } |
1049 } else { | 1040 } else { |
1050 return _negate(r0, r1, r2); | 1041 return _negate(r0, r1, r2); |
1051 } | 1042 } |
1052 } | 1043 } |
1053 } | 1044 } |
OLD | NEW |