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 dart.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * An arbitrarily large integer. | 8 * An arbitrarily large integer. |
9 * | 9 * |
10 * **Note:** When compiling to JavaScript, integers are | 10 * **Note:** When compiling to JavaScript, integers are |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 /** | 81 /** |
82 * Shift the bits of this integer to the left by [shiftAmount]. | 82 * Shift the bits of this integer to the left by [shiftAmount]. |
83 * | 83 * |
84 * Shifting to the left makes the number larger, effectively multiplying | 84 * Shifting to the left makes the number larger, effectively multiplying |
85 * the number by `pow(2, shiftIndex)`. | 85 * the number by `pow(2, shiftIndex)`. |
86 * | 86 * |
87 * There is no limit on the size of the result. It may be relevant to | 87 * There is no limit on the size of the result. It may be relevant to |
88 * limit intermediate values by using the "and" operator with a suitable | 88 * limit intermediate values by using the "and" operator with a suitable |
89 * mask. | 89 * mask. |
90 * | 90 * |
91 * It is an error of [shiftAmount] is negative. | 91 * It is an error if [shiftAmount] is negative. |
92 */ | 92 */ |
93 int operator <<(int shiftAmount); | 93 int operator <<(int shiftAmount); |
94 | 94 |
95 /** | 95 /** |
96 * Shift the bits of this integer to the right by [shiftAmount]. | 96 * Shift the bits of this integer to the right by [shiftAmount]. |
97 * | 97 * |
98 * Shifting to the right makes the number smaller and drops the least | 98 * Shifting to the right makes the number smaller and drops the least |
99 * significant bits, effectively doing an integer division by | 99 * significant bits, effectively doing an integer division by |
100 *`pow(2, shiftIndex)`. | 100 *`pow(2, shiftIndex)`. |
101 * | 101 * |
102 * It is an error of [shiftAmount] is negative. | 102 * It is an error if [shiftAmount] is negative. |
103 */ | 103 */ |
104 int operator >>(int shiftAmount); | 104 int operator >>(int shiftAmount); |
105 | 105 |
106 /** | 106 /** |
107 * Returns this integer to the power of [exponent] modulo [modulus]. | 107 * Returns this integer to the power of [exponent] modulo [modulus]. |
108 * | 108 * |
109 * The [exponent] must be non-negative and [modulus] must be | 109 * The [exponent] must be non-negative and [modulus] must be |
110 * positive. | 110 * positive. |
111 */ | 111 */ |
112 int modPow(int exponent, int modulus); | 112 int modPow(int exponent, int modulus); |
113 | 113 |
114 /** | 114 /** |
115 * Returns the modular multiplicative inverse of this integer | 115 * Returns the modular multiplicative inverse of this integer |
116 * modulo [modulus]. | 116 * modulo [modulus]. |
117 * | 117 * |
118 * The [modulus] must be positive. | 118 * The [modulus] must be positive. |
119 * Throws if no modular inverse exists. | 119 * |
| 120 * It is an error if no modular inverse exists. |
120 */ | 121 */ |
121 int modInverse(int modulus); | 122 int modInverse(int modulus); |
122 | 123 |
123 /** | 124 /** |
124 * Returns the greatest common divisor of the absolute value of | 125 * Returns the greatest common divisor of the absolute value of |
125 * this integer and the absolute value of [other]. | 126 * this integer and the absolute value of [other]. |
126 * | 127 * |
127 * Both this and [other] must be non-zero. | 128 * Both this and [other] must be non-zero. |
128 */ | 129 */ |
129 int gcd(int other); | 130 int gcd(int other); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 * The returned string is parsable by [parse]. | 260 * The returned string is parsable by [parse]. |
260 * For any `int` [:i:], it is guaranteed that | 261 * For any `int` [:i:], it is guaranteed that |
261 * [:i == int.parse(i.toString()):]. | 262 * [:i == int.parse(i.toString()):]. |
262 */ | 263 */ |
263 String toString(); | 264 String toString(); |
264 | 265 |
265 /** | 266 /** |
266 * Converts [this] to a string representation in the given [radix]. | 267 * Converts [this] to a string representation in the given [radix]. |
267 * | 268 * |
268 * In the string representation, lower-case letters are used for digits above | 269 * In the string representation, lower-case letters are used for digits above |
269 * '9'. | 270 * '9', with 'a' being 10 an 'z' being 35. |
270 * | 271 * |
271 * The [radix] argument must be an integer in the range 2 to 36. | 272 * The [radix] argument must be an integer in the range 2 to 36. |
272 */ | 273 */ |
273 String toRadixString(int radix); | 274 String toRadixString(int radix); |
274 | 275 |
275 /** | 276 /** |
276 * Parse [source] as an integer literal and return its value. | 277 * Parse [source] as a, possibly signed, integer literal and return its value. |
277 * | |
278 * The [radix] must be in the range 2..36. The digits used are | |
279 * first the decimal digits 0..9, and then the letters 'a'..'z'. | |
280 * Accepts capital letters as well. | |
281 * | |
282 * If no [radix] is given then it defaults to 10, unless the string starts | |
283 * with "0x", "-0x" or "+0x", in which case the radix is set to 16 and the | |
284 * "0x" is ignored. | |
285 * | 278 * |
286 * The [source] must be a non-empty sequence of base-[radix] digits, | 279 * The [source] must be a non-empty sequence of base-[radix] digits, |
287 * optionally prefixed with a minus or plus sign ('-' or '+'). | 280 * optionally prefixed with a minus or plus sign ('-' or '+'). |
288 * | 281 * |
289 * It must always be the case for an int [:n:] and radix [:r:] that | 282 * The [radix] must be in the range 2..36. The digits used are |
| 283 * first the decimal digits 0..9, and then the letters 'a'..'z' with |
| 284 * values 10 through 35. Also accepts upper-case letters with the same |
| 285 * values as the lower-case ones. |
| 286 * |
| 287 * If no [radix] is given then it defaults to 10. In this case, the [source] |
| 288 * digits may also start with `0x`, in which case the number is interpreted |
| 289 * as a hexadecimal literal, which effectively means that the `0x` is ignored |
| 290 * and the radix is instead set to 16. |
| 291 * |
| 292 * For any int [:n:] and radix [:r:], it is guaranteed that |
290 * [:n == int.parse(n.toRadixString(r), radix: r):]. | 293 * [:n == int.parse(n.toRadixString(r), radix: r):]. |
291 * | 294 * |
292 * If the [source] is not a valid integer literal, optionally prefixed by a | 295 * If the [source] is not a valid integer literal, optionally prefixed by a |
293 * sign, the [onError] is called with the [source] as argument, and its return | 296 * sign, the [onError] is called with the [source] as argument, and its return |
294 * value is used instead. If no [onError] is provided, a [FormatException] | 297 * value is used instead. If no [onError] is provided, a [FormatException] |
295 * is thrown. | 298 * is thrown. |
296 * | 299 * |
297 * The [onError] handler can be chosen to return `null`. This is preferable | 300 * The [onError] handler can be chosen to return `null`. This is preferable |
298 * to to throwing and then immediately catching the [FormatException]. | 301 * to to throwing and then immediately catching the [FormatException]. |
299 * Example: | 302 * Example: |
300 * | 303 * |
301 * var value = int.parse(text, onError: (source) => null); | 304 * var value = int.parse(text, onError: (source) => null); |
302 * if (value == null) ... handle the problem | 305 * if (value == null) ... handle the problem |
303 * | 306 * |
304 * The [onError] function is only invoked if [source] is a [String]. It is | 307 * The [onError] function is only invoked if [source] is a [String]. It is |
305 * not invoked if the [source] is, for example, `null`. | 308 * not invoked if the [source] is, for example, `null`. |
306 */ | 309 */ |
307 external static int parse(String source, | 310 external static int parse(String source, |
308 { int radix, | 311 { int radix, |
309 int onError(String source) }); | 312 int onError(String source) }); |
310 } | 313 } |
OLD | NEW |