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 /** | 5 /** |
6 * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. | 6 * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. |
7 * Arithmetic operations may overflow in order to maintain this range. | 7 * Arithmetic operations may overflow in order to maintain this range. |
8 */ | 8 */ |
9 class int64 implements intx { | 9 class int64 implements intx { |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 "-8000000000000000" // base 16 | 56 "-8000000000000000" // base 16 |
57 ]; | 57 ]; |
58 | 58 |
59 // The remainder of the last divide operation. | 59 // The remainder of the last divide operation. |
60 static int64 _remainder; | 60 static int64 _remainder; |
61 | 61 |
62 /** | 62 /** |
63 * The maximum positive value attainable by an [int64], namely | 63 * The maximum positive value attainable by an [int64], namely |
64 * 9,223,372,036,854,775,807. | 64 * 9,223,372,036,854,775,807. |
65 */ | 65 */ |
66 static int64 get MAX_VALUE() { | 66 static int64 get MAX_VALUE { |
67 if (_MAX_VALUE == null) { | 67 if (_MAX_VALUE == null) { |
68 _MAX_VALUE = new int64._bits(_MASK, _MASK, _MASK_2 >> 1); | 68 _MAX_VALUE = new int64._bits(_MASK, _MASK, _MASK_2 >> 1); |
69 } | 69 } |
70 return _MAX_VALUE; | 70 return _MAX_VALUE; |
71 } | 71 } |
72 | 72 |
73 /** | 73 /** |
74 * The minimum positive value attainable by an [int64], namely | 74 * The minimum positive value attainable by an [int64], namely |
75 * -9,223,372,036,854,775,808. | 75 * -9,223,372,036,854,775,808. |
76 */ | 76 */ |
77 static int64 get MIN_VALUE() { | 77 static int64 get MIN_VALUE { |
78 if (_MIN_VALUE == null) { | 78 if (_MIN_VALUE == null) { |
79 _MIN_VALUE = new int64._bits(0, 0, _SIGN_BIT_VALUE); | 79 _MIN_VALUE = new int64._bits(0, 0, _SIGN_BIT_VALUE); |
80 } | 80 } |
81 return _MIN_VALUE; | 81 return _MIN_VALUE; |
82 } | 82 } |
83 | 83 |
84 /** | 84 /** |
85 * An [int64] constant equal to 0. | 85 * An [int64] constant equal to 0. |
86 */ | 86 */ |
87 static int64 get ZERO() { | 87 static int64 get ZERO { |
88 if (_ZERO == null) { | 88 if (_ZERO == null) { |
89 _ZERO = new int64(); | 89 _ZERO = new int64(); |
90 } | 90 } |
91 return _ZERO; | 91 return _ZERO; |
92 } | 92 } |
93 | 93 |
94 /** | 94 /** |
95 * An [int64] constant equal to 1. | 95 * An [int64] constant equal to 1. |
96 */ | 96 */ |
97 static int64 get ONE() { | 97 static int64 get ONE { |
98 if (_ONE == null) { | 98 if (_ONE == null) { |
99 _ONE = new int64._bits(1, 0, 0); | 99 _ONE = new int64._bits(1, 0, 0); |
100 } | 100 } |
101 return _ONE; | 101 return _ONE; |
102 } | 102 } |
103 | 103 |
104 /** | 104 /** |
105 * An [int64] constant equal to 2. | 105 * An [int64] constant equal to 2. |
106 */ | 106 */ |
107 static int64 get TWO() { | 107 static int64 get TWO { |
108 if (_TWO == null) { | 108 if (_TWO == null) { |
109 _TWO = new int64._bits(2, 0, 0); | 109 _TWO = new int64._bits(2, 0, 0); |
110 } | 110 } |
111 return _TWO; | 111 return _TWO; |
112 } | 112 } |
113 | 113 |
114 /** | 114 /** |
115 * Parses a [String] in a given [radix] between 2 and 16 and returns an | 115 * Parses a [String] in a given [radix] between 2 and 16 and returns an |
116 * [int64]. | 116 * [int64]. |
117 */ | 117 */ |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 int64._copy(int64 other) { | 758 int64._copy(int64 other) { |
759 _l = other._l; | 759 _l = other._l; |
760 _m = other._m; | 760 _m = other._m; |
761 _h = other._h; | 761 _h = other._h; |
762 } | 762 } |
763 | 763 |
764 // Determine whether the platform supports ints greater than 2^53 | 764 // Determine whether the platform supports ints greater than 2^53 |
765 // without loss of precision. | 765 // without loss of precision. |
766 static bool _haveBigIntsCached = null; | 766 static bool _haveBigIntsCached = null; |
767 | 767 |
768 static bool get _haveBigInts() { | 768 static bool get _haveBigInts { |
769 if (_haveBigIntsCached == null) { | 769 if (_haveBigIntsCached == null) { |
770 var x = 9007199254740992; | 770 var x = 9007199254740992; |
771 // Defeat compile-time constant folding. | 771 // Defeat compile-time constant folding. |
772 if (2 + 2 != 4) { | 772 if (2 + 2 != 4) { |
773 x = 0; | 773 x = 0; |
774 } | 774 } |
775 var y = x + 1; | 775 var y = x + 1; |
776 var same = y == x; | 776 var same = y == x; |
777 _haveBigIntsCached = !same; | 777 _haveBigIntsCached = !same; |
778 } | 778 } |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 } | 1086 } |
1087 } | 1087 } |
1088 return ZERO; | 1088 return ZERO; |
1089 } | 1089 } |
1090 | 1090 |
1091 // Generate the quotient using bit-at-a-time long division. | 1091 // Generate the quotient using bit-at-a-time long division. |
1092 return _divModHelper(aIsCopy ? a : new int64._copy(a), b, negative, | 1092 return _divModHelper(aIsCopy ? a : new int64._copy(a), b, negative, |
1093 aIsNegative, aIsMinValue, computeRemainder); | 1093 aIsNegative, aIsMinValue, computeRemainder); |
1094 } | 1094 } |
1095 } | 1095 } |
OLD | NEW |