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 integer or floating-point number. | 8 * An integer or floating-point number. |
9 * | 9 * |
10 * It is a compile-time error for any type other than [int] or [double] | 10 * It is a compile-time error for any type other than [int] or [double] |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 * extended to work with doubles. In that case `r` may have a non-integer | 99 * extended to work with doubles. In that case `r` may have a non-integer |
100 * value, but it still verifies `0 <= r < |b|`. | 100 * value, but it still verifies `0 <= r < |b|`. |
101 * | 101 * |
102 * The sign of the returned value `r` is always positive. | 102 * The sign of the returned value `r` is always positive. |
103 * | 103 * |
104 * See [remainder] for the remainder of the truncating division. | 104 * See [remainder] for the remainder of the truncating division. |
105 */ | 105 */ |
106 num operator %(num other); | 106 num operator %(num other); |
107 | 107 |
108 /** Division operator. */ | 108 /** Division operator. */ |
109 double operator /(num other); | 109 num operator /(num other); |
110 | 110 |
111 /** | 111 /** |
112 * Truncating division operator. | 112 * Truncating division operator. |
113 * | 113 * |
114 * If either operand is a [double] then the result of the truncating division | 114 * If either operand is a [double] then the result of the truncating division |
115 * `a ~/ b` is equivalent to `(a / b).truncate().toInt()`. | 115 * `a ~/ b` is equivalent to `(a / b).truncate().toInt()`. |
116 * | 116 * |
117 * If both operands are [int]s then `a ~/ b` performs the truncating | 117 * If both operands are [int]s then `a ~/ b` performs the truncating |
118 * integer division. | 118 * integer division. |
119 */ | 119 */ |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 /** | 305 /** |
306 * Return this [num] as a [double]. | 306 * Return this [num] as a [double]. |
307 * | 307 * |
308 * If the number is not representable as a [double], an | 308 * If the number is not representable as a [double], an |
309 * approximation is returned. For numerically large integers, the | 309 * approximation is returned. For numerically large integers, the |
310 * approximation may be infinite. | 310 * approximation may be infinite. |
311 */ | 311 */ |
312 double toDouble(); | 312 double toDouble(); |
313 | 313 |
| 314 /** Return this [num] as a [fraction]. */ |
| 315 fraction toFraction(); |
| 316 |
| 317 /** Return this [num] as a [fraction] with 100 as the |
| 318 * denominator. Precision loss may occur. Infinite and NaN |
| 319 * are not supported. */ |
| 320 fraction toPercent(); |
| 321 |
314 /** | 322 /** |
315 * Returns a decimal-point string-representation of `this`. | 323 * Returns a decimal-point string-representation of `this`. |
316 * | 324 * |
317 * Converts `this` to a [double] before computing the string representation. | 325 * Converts `this` to a [double] before computing the string representation. |
318 * | 326 * |
319 * If the absolute value of `this` is greater or equal to `10^21` then this | 327 * If the absolute value of `this` is greater or equal to `10^21` then this |
320 * methods returns an exponential representation computed by | 328 * methods returns an exponential representation computed by |
321 * `this.toStringAsExponential()`. Otherwise the result | 329 * `this.toStringAsExponential()`. Otherwise the result |
322 * is the closest string representation with exactly [fractionDigits] digits | 330 * is the closest string representation with exactly [fractionDigits] digits |
323 * after the decimal point. If [fractionDigits] equals 0 then the decimal | 331 * after the decimal point. If [fractionDigits] equals 0 then the decimal |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 result = double.parse(source, _returnDoubleNull); | 452 result = double.parse(source, _returnDoubleNull); |
445 if (result != null) return result; | 453 if (result != null) return result; |
446 if (onError == null) throw new FormatException(input); | 454 if (onError == null) throw new FormatException(input); |
447 return onError(input); | 455 return onError(input); |
448 } | 456 } |
449 | 457 |
450 /** Helper functions for [parse]. */ | 458 /** Helper functions for [parse]. */ |
451 static int _returnIntNull(String _) => null; | 459 static int _returnIntNull(String _) => null; |
452 static double _returnDoubleNull(String _) => null; | 460 static double _returnDoubleNull(String _) => null; |
453 } | 461 } |
OLD | NEW |