Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, 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 // Dart core library. | |
| 6 | |
| 7 // TODO: Convert this abstract class into a concrete class double | 5 // TODO: Convert this abstract class into a concrete class double |
| 8 // that uses the patch class functionality to account for the | 6 // that uses the patch class functionality to account for the |
| 9 // different platform implementations. | 7 // different platform implementations. |
| 10 | 8 |
| 9 /** | |
| 10 * Representation of Dart doubles containing double specific constants | |
| 11 * and operations and specializations of operations inherited from | |
| 12 * [num]. | |
| 13 * | |
| 14 * The [double] type is contagious. Operations on [double]s return | |
| 15 * [double] results. | |
| 16 */ | |
| 11 abstract class double extends num { | 17 abstract class double extends num { |
| 12 static const double NAN = 0.0 / 0.0; | 18 static const double NAN = 0.0 / 0.0; |
| 13 static const double INFINITY = 1.0 / 0.0; | 19 static const double INFINITY = 1.0 / 0.0; |
| 14 static const double NEGATIVE_INFINITY = -INFINITY; | 20 static const double NEGATIVE_INFINITY = -INFINITY; |
| 15 | 21 |
| 16 // Specialization of super-interface. Double is contagious. We can therefore | 22 /** Return the remainder from dividing this [double] by [other]. */ |
| 17 // specialize more methods than in other num sub-interfaces. | |
| 18 abstract double remainder(num other); | 23 abstract double remainder(num other); |
| 24 | |
| 25 /** Addition operator. */ | |
| 19 abstract double operator +(num other); | 26 abstract double operator +(num other); |
| 27 | |
| 28 /** Subtraction operator. */ | |
| 20 abstract double operator -(num other); | 29 abstract double operator -(num other); |
| 30 | |
| 31 /** Multiplication operator. */ | |
| 21 abstract double operator *(num other); | 32 abstract double operator *(num other); |
| 33 | |
| 34 /** Euclidean modulo operator. */ | |
| 22 abstract double operator %(num other); | 35 abstract double operator %(num other); |
| 36 | |
| 37 /** Division operator. */ | |
| 23 abstract double operator /(num other); | 38 abstract double operator /(num other); |
| 39 | |
| 40 /** | |
| 41 * Truncating division operator. | |
| 42 * | |
| 43 * The result of the truncating division [:a ~/ b:] is equivalent to | |
| 44 * [:(a / b).truncate():]. | |
| 45 */ | |
| 24 abstract double operator ~/(num other); | 46 abstract double operator ~/(num other); |
| 47 | |
| 48 /** Negate operator. */ | |
| 25 abstract double operator -(); | 49 abstract double operator -(); |
| 50 | |
| 51 /** Returns the absolute value of this [double]. */ | |
| 26 abstract double abs(); | 52 abstract double abs(); |
| 53 | |
| 54 /** | |
| 55 * Returns the integer value closest to this [double]. | |
| 56 * | |
| 57 * Rounds away from zero when there is no closest integer: | |
| 58 * [:(3.5).round() == 4:] and [:(-3.5).round() == -4:]. | |
|
floitsch
2012/09/24 15:56:14
You should also note what happens for the range ]-
Lasse Reichstein Nielsen
2012/09/24 17:56:42
If the return type is double, I think -0.0 is the
floitsch
2012/09/24 20:17:27
good point. I had thought a lot about this, and ii
| |
| 59 */ | |
| 27 abstract double round(); | 60 abstract double round(); |
| 61 | |
| 62 /** Returns the greatest integer value no greater than this [double]. */ | |
| 28 abstract double floor(); | 63 abstract double floor(); |
| 64 | |
| 65 /** Returns the least integer value that is no smaller than this [double]. */ | |
|
floitsch
2012/09/24 15:56:14
ditto.
| |
| 29 abstract double ceil(); | 66 abstract double ceil(); |
| 67 | |
| 68 /** | |
| 69 * Returns the integer value obtained by discarding any fractional | |
| 70 * digits from this [double]. | |
| 71 */ | |
| 30 abstract double truncate(); | 72 abstract double truncate(); |
| 31 | 73 |
| 32 /** | 74 /** |
| 33 * Provide a representation of this [double] value. | 75 * Provide a representation of this [double] value. |
| 34 * | 76 * |
| 35 * The representation is a number literal such that the closest double value | 77 * The representation is a number literal such that the closest double value |
| 36 * to the representation's mathematical value is this [double]. | 78 * to the representation's mathematical value is this [double]. |
| 37 * | 79 * |
| 38 * Returns "NaN" for the Not-a-Number value. | 80 * Returns "NaN" for the Not-a-Number value. |
| 39 * Returns "Infinity" and "-Infinity" for positive and negative Infinity. | 81 * Returns "Infinity" and "-Infinity" for positive and negative Infinity. |
| 40 * Returns "-0.0" for negative zero. | 82 * Returns "-0.0" for negative zero. |
| 41 * | 83 * |
| 42 * It should always be the case that if [:d:] is a [double], then | 84 * It should always be the case that if [:d:] is a [double], then |
| 43 * [:d == double.parse(d.toString()):]. | 85 * [:d == double.parse(d.toString()):]. |
|
floitsch
2012/09/24 15:56:14
except for NaN. But I agree that we can leave it t
Lasse Reichstein Nielsen
2012/09/24 17:52:46
Including NaN, actually, since double.parse("NaN")
floitsch
2012/09/24 20:17:27
but we don't have NaN == NaN.
| |
| 44 */ | 86 */ |
| 45 abstract String toString(); | 87 abstract String toString(); |
| 46 | 88 |
| 47 /** | 89 /** |
| 48 * Parse [source] as an double literal and return its value. | 90 * Parse [source] as an double literal and return its value. |
| 49 * | 91 * |
| 50 * Accepts the same format as double literals: | 92 * Accepts the same format as double literals: |
| 51 * [: ['+'|'-'] [digit* '.'] digit+ [('e'|'E') ['+'|'-'] digit+] :] | 93 * [: ['+'|'-'] [digit* '.'] digit+ [('e'|'E') ['+'|'-'] digit+] :] |
| 52 * | 94 * |
| 53 * Also recognizes "NaN", "Infinity" and "-Infinity" as inputs and returns the | 95 * Also recognizes "NaN", "Infinity" and "-Infinity" as inputs and |
| 54 * corresponding double value. | 96 * returns the corresponding double value. |
| 97 * | |
| 55 * Throws a [FormatException] if [source] is not a valid double literal. | 98 * Throws a [FormatException] if [source] is not a valid double literal. |
| 56 */ | 99 */ |
| 57 external static double parse(String source); | 100 external static double parse(String source); |
| 58 } | 101 } |
| OLD | NEW |