Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: pkg/fixnum/lib/src/int64.dart

Issue 21155004: Clean up exceptions thrown in pkg/fixnum. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to pick up fixnum class renames. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/fixnum/lib/src/int32.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return _TWO; 113 return _TWO;
114 } 114 }
115 115
116 /** 116 /**
117 * Parses a [String] in a given [radix] between 2 and 16 and returns an 117 * Parses a [String] in a given [radix] between 2 and 16 and returns an
118 * [Int64]. 118 * [Int64].
119 */ 119 */
120 // TODO(rice) - make this faster by converting several digits at once. 120 // TODO(rice) - make this faster by converting several digits at once.
121 static Int64 parseRadix(String s, int radix) { 121 static Int64 parseRadix(String s, int radix) {
122 if ((radix <= 1) || (radix > 16)) { 122 if ((radix <= 1) || (radix > 16)) {
123 throw "Bad radix: $radix"; 123 throw new ArgumentError("Bad radix: $radix");
124 } 124 }
125 Int64 x = ZERO; 125 Int64 x = ZERO;
126 int i = 0; 126 int i = 0;
127 bool negative = false; 127 bool negative = false;
128 if (s[0] == '-') { 128 if (s[0] == '-') {
129 negative = true; 129 negative = true;
130 i++; 130 i++;
131 } 131 }
132 for (; i < s.length; i++) { 132 for (; i < s.length; i++) {
133 int c = s.codeUnitAt(i); 133 int c = s.codeUnitAt(i);
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return new Int64._bits(a0, a1, a2); 414 return new Int64._bits(a0, a1, a2);
415 } 415 }
416 416
417 Int64 operator ~() { 417 Int64 operator ~() {
418 var result = new Int64._bits((~_l) & _MASK, (~_m) & _MASK, (~_h) & _MASK_2); 418 var result = new Int64._bits((~_l) & _MASK, (~_m) & _MASK, (~_h) & _MASK_2);
419 return result; 419 return result;
420 } 420 }
421 421
422 Int64 operator <<(int n) { 422 Int64 operator <<(int n) {
423 if (n < 0) { 423 if (n < 0) {
424 throw new ArgumentError("$n"); 424 throw new ArgumentError(n);
425 } 425 }
426 n &= 63; 426 n &= 63;
427 427
428 int res0, res1, res2; 428 int res0, res1, res2;
429 if (n < _BITS) { 429 if (n < _BITS) {
430 res0 = _l << n; 430 res0 = _l << n;
431 res1 = (_m << n) | (_l >> (_BITS - n)); 431 res1 = (_m << n) | (_l >> (_BITS - n));
432 res2 = (_h << n) | (_m >> (_BITS - n)); 432 res2 = (_h << n) | (_m >> (_BITS - n));
433 } else if (n < _BITS01) { 433 } else if (n < _BITS01) {
434 res0 = 0; 434 res0 = 0;
435 res1 = _l << (n - _BITS); 435 res1 = _l << (n - _BITS);
436 res2 = (_m << (n - _BITS)) | (_l >> (_BITS01 - n)); 436 res2 = (_m << (n - _BITS)) | (_l >> (_BITS01 - n));
437 } else { 437 } else {
438 res0 = 0; 438 res0 = 0;
439 res1 = 0; 439 res1 = 0;
440 res2 = _l << (n - _BITS01); 440 res2 = _l << (n - _BITS01);
441 } 441 }
442 442
443 return new Int64._bits(res0 & _MASK, res1 & _MASK, res2 & _MASK_2); 443 return new Int64._bits(res0 & _MASK, res1 & _MASK, res2 & _MASK_2);
444 } 444 }
445 445
446 Int64 operator >>(int n) { 446 Int64 operator >>(int n) {
447 if (n < 0) { 447 if (n < 0) {
448 throw new ArgumentError("$n"); 448 throw new ArgumentError(n);
449 } 449 }
450 n &= 63; 450 n &= 63;
451 451
452 int res0, res1, res2; 452 int res0, res1, res2;
453 453
454 // Sign extend h(a). 454 // Sign extend h(a).
455 int a2 = _h; 455 int a2 = _h;
456 bool negative = (a2 & _SIGN_BIT_VALUE) != 0; 456 bool negative = (a2 & _SIGN_BIT_VALUE) != 0;
457 if (negative) { 457 if (negative) {
458 a2 += 0x3 << _BITS2; // add extra one bits on the left 458 a2 += 0x3 << _BITS2; // add extra one bits on the left
(...skipping 20 matching lines...) Expand all
479 if (negative) { 479 if (negative) {
480 res0 |= _MASK & ~(_MASK >> (n - _BITS01)); 480 res0 |= _MASK & ~(_MASK >> (n - _BITS01));
481 } 481 }
482 } 482 }
483 483
484 return new Int64._bits(res0 & _MASK, res1 & _MASK, res2 & _MASK_2); 484 return new Int64._bits(res0 & _MASK, res1 & _MASK, res2 & _MASK_2);
485 } 485 }
486 486
487 Int64 shiftRightUnsigned(int n) { 487 Int64 shiftRightUnsigned(int n) {
488 if (n < 0) { 488 if (n < 0) {
489 throw new ArgumentError("$n"); 489 throw new ArgumentError(n);
490 } 490 }
491 n &= 63; 491 n &= 63;
492 492
493 int res0, res1, res2; 493 int res0, res1, res2;
494 int a2 = _h & _MASK_2; // Ensure a2 is positive. 494 int a2 = _h & _MASK_2; // Ensure a2 is positive.
495 if (n < _BITS) { 495 if (n < _BITS) {
496 res2 = a2 >> n; 496 res2 = a2 >> n;
497 res1 = (_m >> n) | (a2 << (_BITS - n)); 497 res1 = (_m >> n) | (a2 << (_BITS - n));
498 res0 = (_l >> n) | (_m << (_BITS - n)); 498 res0 = (_l >> n) | (_m << (_BITS - n));
499 } else if (n < _BITS01) { 499 } else if (n < _BITS01) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 while (!x.isZero) { 718 while (!x.isZero) {
719 int digit = x._l & 0xf; 719 int digit = x._l & 0xf;
720 hexStr = "${_hexDigit(digit)}$hexStr"; 720 hexStr = "${_hexDigit(digit)}$hexStr";
721 x = x.shiftRightUnsigned(4); 721 x = x.shiftRightUnsigned(4);
722 } 722 }
723 return hexStr; 723 return hexStr;
724 } 724 }
725 725
726 String toRadixString(int radix) { 726 String toRadixString(int radix) {
727 if ((radix <= 1) || (radix > 16)) { 727 if ((radix <= 1) || (radix > 16)) {
728 throw "Bad radix: $radix"; 728 throw new ArgumentError("Bad radix: $radix");
729 } 729 }
730 Int64 a = this; 730 Int64 a = this;
731 if (a.isZero) { 731 if (a.isZero) {
732 return "0"; 732 return "0";
733 } 733 }
734 if (a.isMinValue) { 734 if (a.isMinValue) {
735 return _minValues[radix]; 735 return _minValues[radix];
736 } 736 }
737 737
738 String result = ""; 738 String result = "";
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 } 1094 }
1095 } 1095 }
1096 return ZERO; 1096 return ZERO;
1097 } 1097 }
1098 1098
1099 // Generate the quotient using bit-at-a-time long division. 1099 // Generate the quotient using bit-at-a-time long division.
1100 return _divModHelper(aIsCopy ? a : new Int64._copy(a), b, negative, 1100 return _divModHelper(aIsCopy ? a : new Int64._copy(a), b, negative,
1101 aIsNegative, aIsMinValue, computeRemainder); 1101 aIsNegative, aIsMinValue, computeRemainder);
1102 } 1102 }
1103 } 1103 }
OLDNEW
« no previous file with comments | « pkg/fixnum/lib/src/int32.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698