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 * All numbers in dart are instances of [num]. | 8 * All numbers in dart are instances of [num]. |
9 */ | 9 */ |
10 abstract class num implements Comparable { | 10 abstract class num implements Comparable { |
11 /** Addition operator. */ | 11 /** Addition operator. */ |
12 num operator +(num other); | 12 num operator +(num other); |
13 | 13 |
14 /** Subtraction operator. */ | 14 /** Subtraction operator. */ |
15 num operator -(num other); | 15 num operator -(num other); |
16 | 16 |
17 /** Multiplication operator. */ | 17 /** Multiplication operator. */ |
18 num operator *(num other); | 18 num operator *(num other); |
19 | 19 |
20 /** Euclidean modulo operator. */ | 20 /** Euclidean modulo operator. */ |
21 num operator %(num other); | 21 num operator %(num other); |
22 | 22 |
23 /** Division operator. */ | 23 /** Division operator. */ |
24 double operator /(num other); | 24 double operator /(num other); |
25 | 25 |
26 /** | 26 /** |
27 * Truncating division operator. | 27 * Truncating division operator. |
28 * | 28 * |
29 * The result of the truncating division [:a ~/ b:] is equivalent to | 29 * The result of the truncating division [:a ~/ b:] is equivalent to |
30 * [:(a / b).truncate():]. | 30 * [:(a / b).truncate().toInt():]. |
31 */ | 31 */ |
32 num operator ~/(num other); | 32 // TODO(floitsch): this is currently not true: bignum1 / bignum2 will return |
| 33 // NaN, whereas bignum1 ~/ bignum2 will give the correct result. |
| 34 int operator ~/(num other); |
33 | 35 |
34 /** Negate operator. */ | 36 /** Negate operator. */ |
35 num operator -(); | 37 num operator -(); |
36 | 38 |
37 /** Return the remainder from dividing this [num] by [other]. */ | 39 /** Return the remainder from dividing this [num] by [other]. */ |
38 num remainder(num other); | 40 num remainder(num other); |
39 | 41 |
40 /** Relational less than operator. */ | 42 /** Relational less than operator. */ |
41 bool operator <(num other); | 43 bool operator <(num other); |
42 | 44 |
(...skipping 28 matching lines...) Expand all Loading... |
71 * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:]. | 73 * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:]. |
72 */ | 74 */ |
73 num round(); | 75 num round(); |
74 | 76 |
75 /** | 77 /** |
76 * Returns the integer value obtained by discarding any fractional | 78 * Returns the integer value obtained by discarding any fractional |
77 * digits from this [num]. | 79 * digits from this [num]. |
78 */ | 80 */ |
79 num truncate(); | 81 num truncate(); |
80 | 82 |
| 83 /** |
| 84 * Clamps [this] to be in the range [lowerLimit]-[upperLimit]. The comparison |
| 85 * is done using [compareTo] and therefore takes [:-0.0:] into account. |
| 86 * It also implies that [double.NaN] is treated as the maximal double value. |
| 87 */ |
| 88 num clamp(num lowerLimit, num upperLimit); |
| 89 |
81 /** Truncates this [num] to an integer and returns the result as an [int]. */ | 90 /** Truncates this [num] to an integer and returns the result as an [int]. */ |
82 int toInt(); | 91 int toInt(); |
83 | 92 |
84 /** | 93 /** |
85 * Return this [num] as a [double]. | 94 * Return this [num] as a [double]. |
86 * | 95 * |
87 * If the number is not representable as a [double], an | 96 * If the number is not representable as a [double], an |
88 * approximation is returned. For numerically large integers, the | 97 * approximation is returned. For numerically large integers, the |
89 * approximation may be infinite. | 98 * approximation may be infinite. |
90 */ | 99 */ |
91 double toDouble(); | 100 double toDouble(); |
92 | 101 |
93 /** | 102 /** |
94 * Converts a [num] to a string representation with [fractionDigits] | 103 * Converts [this] to a string representation with [fractionDigits] digits |
95 * digits after the decimal point. | 104 * after the decimal point. |
| 105 * |
| 106 * The parameter [fractionDigits] must be an integer satisfying: |
| 107 * [:0 <= fractionDigits <= 20:]. |
96 */ | 108 */ |
97 String toStringAsFixed(int fractionDigits); | 109 String toStringAsFixed(int fractionDigits); |
98 | 110 |
99 /** | 111 /** |
100 * Converts a [num] to a string in decimal exponential notation with | 112 * Converts [this] to a string in decimal exponential notation with |
101 * [fractionDigits] digits after the decimal point. | 113 * [fractionDigits] digits after the decimal point. |
| 114 * |
| 115 * If [fractionDigits] is given then it must be an integer satisfying: |
| 116 * [:0 <= fractionDigits <= 20:]. Without the parameter the returned string |
| 117 * uses the shortest number of digits that accurately represent [this]. |
102 */ | 118 */ |
103 String toStringAsExponential(int fractionDigits); | 119 String toStringAsExponential([int fractionDigits]); |
104 | 120 |
105 /** | 121 /** |
106 * Converts a [num] to a string representation with [precision] | 122 * Converts [this] to a string representation with [precision] significant |
107 * significant digits. | 123 * digits. |
| 124 * |
| 125 * The parameter [precision] must be an integer satisfying: |
| 126 * [:1 <= precision <= 21:]. |
108 */ | 127 */ |
109 String toStringAsPrecision(int precision); | 128 String toStringAsPrecision(int precision); |
110 | 129 |
111 /** | 130 |
112 * Converts a [num] to a string representation in the given [radix]. | |
113 * | |
114 * The [num] in converted to an [int] using [toInt]. That [int] is | |
115 * then converted to a string representation with the given | |
116 * [radix]. In the string representation, lower-case letters are | |
117 * used for digits above '9'. | |
118 * | |
119 * The [radix] argument must be an integer between 2 and 36. | |
120 */ | |
121 String toRadixString(int radix); | |
122 } | 131 } |
OLD | NEW |