Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: sdk/lib/core/num.dart

Issue 12317107: ceil/floor/truncate/round return integers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reupload due to error3 Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/int.dart ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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<num> { 10 abstract class num implements Comparable<num> {
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 * If either operand is a [double] then the result of the truncating division
30 * [:(a / b).truncate().toInt():]. 30 * [:a ~/ b:] is equivalent to [:(a / b).truncate().toInt():].
31 *
32 * If both operands are [int]s then [:a ~/ b:] performs the truncating
33 * integer division.
31 */ 34 */
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); 35 int operator ~/(num other);
35 36
36 /** Negate operator. */ 37 /** Negate operator. */
37 num operator -(); 38 num operator -();
38 39
39 /** Return the remainder from dividing this [num] by [other]. */ 40 /** Return the remainder from dividing this [num] by [other]. */
40 num remainder(num other); 41 num remainder(num other);
41 42
42 /** Relational less than operator. */ 43 /** Relational less than operator. */
43 bool operator <(num other); 44 bool operator <(num other);
44 45
45 /** Relational less than or equal operator. */ 46 /** Relational less than or equal operator. */
46 bool operator <=(num other); 47 bool operator <=(num other);
47 48
48 /** Relational greater than operator. */ 49 /** Relational greater than operator. */
49 bool operator >(num other); 50 bool operator >(num other);
50 51
51 /** Relational greater than or equal operator. */ 52 /** Relational greater than or equal operator. */
52 bool operator >=(num other); 53 bool operator >=(num other);
53 54
54 bool get isNaN; 55 bool get isNaN;
55 56
56 bool get isNegative; 57 bool get isNegative;
57 58
58 bool get isInfinite; 59 bool get isInfinite;
59 60
60 /** Returns the absolute value of this [num]. */ 61 /** Returns the absolute value of this [num]. */
61 num abs(); 62 num abs();
62 63
63 /** Returns the greatest integer value no greater than this [num]. */
64 num floor();
65
66 /** Returns the least integer value that is no smaller than this [num]. */
67 num ceil();
68
69 /** 64 /**
70 * Returns the integer value closest to this [num]. 65 * Returns the integer closest to `this`.
71 * 66 *
72 * Rounds away from zero when there is no closest integer: 67 * Rounds away from zero when there is no closest integer:
73 * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:]. 68 * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:].
69 *
70 * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
74 */ 71 */
75 num round(); 72 int round();
76 73
77 /** 74 /**
78 * Returns the integer value obtained by discarding any fractional 75 * Returns the greatest integer no greater than `this`.
79 * digits from this [num]. 76 *
77 * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
80 */ 78 */
81 num truncate(); 79 int floor();
80
81 /**
82 * Returns the least integer no smaller than `this`.
83 *
84 * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
85 */
86 int ceil();
87
88 /**
89 * Returns the integer obtained by discarding any fractional
90 * digits from `this`.
91 *
92 * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
93 */
94 int truncate();
95
96 /**
97 * Returns the integer value closest to `this`.
98 *
99 * Rounds away from zero when there is no closest integer:
100 * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:].
101 *
102 * The result is a double.
103 */
104 double roundToDouble();
105
106 /**
107 * Returns the greatest integer value no greater than `this`.
108 *
109 * The result is a double.
110 */
111 double floorToDouble();
112
113 /**
114 * Returns the least integer value no smaller than `this`.
115 *
116 * The result is a double.
117 */
118 double ceilToDouble();
119
120 /**
121 * Returns the integer obtained by discarding any fractional
122 * digits from `this`.
123 *
124 * The result is a double.
125 */
126 double truncateToDouble();
82 127
83 /** 128 /**
84 * Clamps [this] to be in the range [lowerLimit]-[upperLimit]. The comparison 129 * Clamps [this] to be in the range [lowerLimit]-[upperLimit]. The comparison
85 * is done using [compareTo] and therefore takes [:-0.0:] into account. 130 * 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. 131 * It also implies that [double.NAN] is treated as the maximal double value.
87 */ 132 */
88 num clamp(num lowerLimit, num upperLimit); 133 num clamp(num lowerLimit, num upperLimit);
89 134
90 /** Truncates this [num] to an integer and returns the result as an [int]. */ 135 /** Truncates this [num] to an integer and returns the result as an [int]. */
91 int toInt(); 136 int toInt();
(...skipping 30 matching lines...) Expand all
122 * Converts [this] to a string representation with [precision] significant 167 * Converts [this] to a string representation with [precision] significant
123 * digits. 168 * digits.
124 * 169 *
125 * The parameter [precision] must be an integer satisfying: 170 * The parameter [precision] must be an integer satisfying:
126 * [:1 <= precision <= 21:]. 171 * [:1 <= precision <= 21:].
127 */ 172 */
128 String toStringAsPrecision(int precision); 173 String toStringAsPrecision(int precision);
129 174
130 175
131 } 176 }
OLDNEW
« no previous file with comments | « sdk/lib/core/int.dart ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698