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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 bool negative = false; | 74 bool negative = false; |
75 if (s[0] == '-') { | 75 if (s[0] == '-') { |
76 negative = true; | 76 negative = true; |
77 i++; | 77 i++; |
78 } | 78 } |
79 int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. | 79 int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components. |
80 for (; i < s.length; i++) { | 80 for (; i < s.length; i++) { |
81 int c = s.codeUnitAt(i); | 81 int c = s.codeUnitAt(i); |
82 int digit = Int32._decodeDigit(c); | 82 int digit = Int32._decodeDigit(c); |
83 if (digit < 0 || digit >= radix) { | 83 if (digit < 0 || digit >= radix) { |
84 throw new Exception("Non-radix char code: $c"); | 84 throw new FormatException("Non-radix char code: $c"); |
85 } | 85 } |
86 | 86 |
87 // [radix] and [digit] are at most 6 bits, component is 22, so we can | 87 // [radix] and [digit] are at most 6 bits, component is 22, so we can |
88 // multiply and add within 30 bit temporary values. | 88 // multiply and add within 30 bit temporary values. |
89 d0 = d0 * radix + digit; | 89 d0 = d0 * radix + digit; |
90 int carry = d0 >> _BITS; | 90 int carry = d0 >> _BITS; |
91 d0 = _MASK & d0; | 91 d0 = _MASK & d0; |
92 | 92 |
93 d1 = d1 * radix + carry; | 93 d1 = d1 * radix + carry; |
94 carry = d1 >> _BITS; | 94 carry = d1 >> _BITS; |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 if (r0 == 0 && r1 == 0 && r2 == 0) { | 1039 if (r0 == 0 && r1 == 0 && r2 == 0) { |
1040 return ZERO; | 1040 return ZERO; |
1041 } else { | 1041 } else { |
1042 return _sub(b0, b1, b2, r0, r1, r2); | 1042 return _sub(b0, b1, b2, r0, r1, r2); |
1043 } | 1043 } |
1044 } else { | 1044 } else { |
1045 return _negate(r0, r1, r2); | 1045 return _negate(r0, r1, r2); |
1046 } | 1046 } |
1047 } | 1047 } |
1048 } | 1048 } |
OLD | NEW |