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():]. |
Lasse Reichstein Nielsen
2013/01/04 10:29:42
So add "if a or b is a double. If both are int, th
| |
31 */ | 31 */ |
32 // TODO(floitsch): this is currently not true: bignum1 / bignum2 will return | 32 // TODO(floitsch): this is currently not true: bignum1 / bignum2 will return |
33 // NaN, whereas bignum1 ~/ bignum2 will give the correct result. | 33 // NaN, whereas bignum1 ~/ bignum2 will give the correct result. |
34 num operator ~/(num other); | 34 int operator ~/(num other); |
35 | 35 |
36 /** Negate operator. */ | 36 /** Negate operator. */ |
37 num operator -(); | 37 num operator -(); |
38 | 38 |
39 /** Return the remainder from dividing this [num] by [other]. */ | 39 /** Return the remainder from dividing this [num] by [other]. */ |
40 num remainder(num other); | 40 num remainder(num other); |
41 | 41 |
42 /** Relational less than operator. */ | 42 /** Relational less than operator. */ |
43 bool operator <(num other); | 43 bool operator <(num other); |
44 | 44 |
45 /** Relational less than or equal operator. */ | 45 /** Relational less than or equal operator. */ |
46 bool operator <=(num other); | 46 bool operator <=(num other); |
47 | 47 |
48 /** Relational greater than operator. */ | 48 /** Relational greater than operator. */ |
49 bool operator >(num other); | 49 bool operator >(num other); |
50 | 50 |
51 /** Relational greater than or equal operator. */ | 51 /** Relational greater than or equal operator. */ |
52 bool operator >=(num other); | 52 bool operator >=(num other); |
53 | 53 |
54 bool get isNaN; | 54 bool get isNaN; |
55 | 55 |
56 bool get isNegative; | 56 bool get isNegative; |
57 | 57 |
58 bool get isInfinite; | 58 bool get isInfinite; |
59 | 59 |
60 /** Returns the absolute value of this [num]. */ | 60 /** Returns the absolute value of this [num]. */ |
61 num abs(); | 61 num abs(); |
62 | 62 |
63 /** Returns the greatest integer value no greater than this [num]. */ | 63 /** |
64 num floor(); | 64 * Returns the greatest integer no greater than [this] Throws a |
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Missing '.'. Two newlines after the '.'.
| |
65 | 65 * [FormatException] if [this] cannot be converted. |
66 /** Returns the least integer value that is no smaller than this [num]. */ | 66 */ |
67 num ceil(); | 67 int floor(); |
68 | 68 |
69 /** | 69 /** |
70 * Returns the integer value closest to this [num]. | 70 * Returns the least integer that is no smaller than [this]. Throws a |
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Two newlines after '.'.
| |
71 * [FormatException] if [this] cannot be converted. | |
72 */ | |
73 int ceil(); | |
74 | |
75 /** | |
76 * Returns the integer closest to [this]. Throws a [FormatException] if | |
77 * [this] cannot be converted. | |
71 * | 78 * |
72 * Rounds away from zero when there is no closest integer: | 79 * Rounds away from zero when there is no closest integer: |
73 * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:]. | 80 * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:]. |
74 */ | 81 */ |
75 num round(); | 82 int round(); |
76 | 83 |
77 /** | 84 /** |
78 * Returns the integer value obtained by discarding any fractional | 85 * Returns the integer obtained by discarding any fractional digits from |
79 * digits from this [num]. | 86 * [this]. Throws a [FormatException] if [this] cannot be converted. |
80 */ | 87 */ |
81 num truncate(); | 88 int truncate(); |
82 | 89 |
83 /** | 90 /** |
84 * Clamps [this] to be in the range [lowerLimit]-[upperLimit]. The comparison | 91 * Clamps [this] to be in the range [lowerLimit]-[upperLimit]. The comparison |
85 * is done using [compareTo] and therefore takes [:-0.0:] into account. | 92 * 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. | 93 * It also implies that [double.NaN] is treated as the maximal double value. |
87 */ | 94 */ |
88 num clamp(num lowerLimit, num upperLimit); | 95 num clamp(num lowerLimit, num upperLimit); |
89 | 96 |
90 /** Truncates this [num] to an integer and returns the result as an [int]. */ | |
91 int toInt(); | |
92 | |
93 /** | 97 /** |
94 * Return this [num] as a [double]. | 98 * Return this [num] as a [double]. |
95 * | 99 * |
96 * If the number is not representable as a [double], an | 100 * If the number is not representable as a [double], an |
97 * approximation is returned. For numerically large integers, the | 101 * approximation is returned. For numerically large integers, the |
98 * approximation may be infinite. | 102 * approximation may be infinite. |
99 */ | 103 */ |
100 double toDouble(); | 104 double toDouble(); |
101 | 105 |
102 /** | 106 /** |
(...skipping 19 matching lines...) Expand all Loading... | |
122 * Converts [this] to a string representation with [precision] significant | 126 * Converts [this] to a string representation with [precision] significant |
123 * digits. | 127 * digits. |
124 * | 128 * |
125 * The parameter [precision] must be an integer satisfying: | 129 * The parameter [precision] must be an integer satisfying: |
126 * [:1 <= precision <= 21:]. | 130 * [:1 <= precision <= 21:]. |
127 */ | 131 */ |
128 String toStringAsPrecision(int precision); | 132 String toStringAsPrecision(int precision); |
129 | 133 |
130 | 134 |
131 } | 135 } |
OLD | NEW |