| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of dart.core; | |
| 6 | |
| 7 // TODO: Convert this abstract class into a concrete class double | |
| 8 // that uses the patch class functionality to account for the | |
| 9 // different platform implementations. | |
| 10 | |
| 11 /** | |
| 12 * A double-precision floating point number. | |
| 13 * | |
| 14 * Representation of Dart doubles containing double specific constants | |
| 15 * and operations and specializations of operations inherited from | |
| 16 * [num]. Dart doubles are 64-bit floating-point numbers as specified in the | |
| 17 * IEEE 754 standard. | |
| 18 * | |
| 19 * The [double] type is contagious. Operations on [double]s return | |
| 20 * [double] results. | |
| 21 * | |
| 22 * It is a compile-time error for a class to attempt to extend or implement | |
| 23 * double. | |
| 24 */ | |
| 25 abstract class double extends num { | |
| 26 static const double NAN = 0.0 / 0.0; | |
| 27 static const double INFINITY = 1.0 / 0.0; | |
| 28 static const double NEGATIVE_INFINITY = -INFINITY; | |
| 29 static const double MIN_POSITIVE = 5e-324; | |
| 30 static const double MAX_FINITE = 1.7976931348623157e+308; | |
| 31 | |
| 32 double remainder(num other); | |
| 33 | |
| 34 /** Addition operator. */ | |
| 35 double operator +(num other); | |
| 36 | |
| 37 /** Subtraction operator. */ | |
| 38 double operator -(num other); | |
| 39 | |
| 40 /** Multiplication operator. */ | |
| 41 double operator *(num other); | |
| 42 | |
| 43 double operator %(num other); | |
| 44 | |
| 45 /** Division operator. */ | |
| 46 double operator /(num other); | |
| 47 | |
| 48 /** | |
| 49 * Truncating division operator. | |
| 50 * | |
| 51 * The result of the truncating division `a ~/ b` is equivalent to | |
| 52 * `(a / b).truncate()`. | |
| 53 */ | |
| 54 int operator ~/(num other); | |
| 55 | |
| 56 /** Negate operator. */ | |
| 57 double operator -(); | |
| 58 | |
| 59 /** Returns the absolute value of this [double]. */ | |
| 60 double abs(); | |
| 61 | |
| 62 /** | |
| 63 * Returns the sign of the double's numerical value. | |
| 64 * | |
| 65 * Returns -1.0 if the value is less than zero, | |
| 66 * +1.0 if the value is greater than zero, | |
| 67 * and the value itself if it is -0.0, 0.0 or NaN. | |
| 68 */ | |
| 69 double get sign; | |
| 70 | |
| 71 /** | |
| 72 * Returns the integer closest to `this`. | |
| 73 * | |
| 74 * Rounds away from zero when there is no closest integer: | |
| 75 * `(3.5).round() == 4` and `(-3.5).round() == -4`. | |
| 76 * | |
| 77 * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError]. | |
| 78 */ | |
| 79 int round(); | |
| 80 | |
| 81 /** | |
| 82 * Returns the greatest integer no greater than `this`. | |
| 83 * | |
| 84 * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError]. | |
| 85 */ | |
| 86 int floor(); | |
| 87 | |
| 88 /** | |
| 89 * Returns the least integer no smaller than `this`. | |
| 90 * | |
| 91 * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError]. | |
| 92 */ | |
| 93 int ceil(); | |
| 94 | |
| 95 /** | |
| 96 * Returns the integer obtained by discarding any fractional | |
| 97 * digits from `this`. | |
| 98 * | |
| 99 * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError]. | |
| 100 */ | |
| 101 int truncate(); | |
| 102 | |
| 103 /** | |
| 104 * Returns the integer double value closest to `this`. | |
| 105 * | |
| 106 * Rounds away from zero when there is no closest integer: | |
| 107 * `(3.5).roundToDouble() == 4` and `(-3.5).roundToDouble() == -4`. | |
| 108 * | |
| 109 * If this is already an integer valued double, including `-0.0`, or it is not | |
| 110 * a finite value, the value is returned unmodified. | |
| 111 * | |
| 112 * For the purpose of rounding, `-0.0` is considered to be below `0.0`, | |
| 113 * and `-0.0` is therefore considered closer to negative numbers than `0.0`. | |
| 114 * This means that for a value, `d` in the range `-0.5 < d < 0.0`, | |
| 115 * the result is `-0.0`. | |
| 116 */ | |
| 117 double roundToDouble(); | |
| 118 | |
| 119 /** | |
| 120 * Returns the greatest integer double value no greater than `this`. | |
| 121 * | |
| 122 * If this is already an integer valued double, including `-0.0`, or it is not | |
| 123 * a finite value, the value is returned unmodified. | |
| 124 * | |
| 125 * For the purpose of rounding, `-0.0` is considered to be below `0.0`. | |
| 126 * A number `d` in the range `0.0 < d < 1.0` will return `0.0`. | |
| 127 */ | |
| 128 double floorToDouble(); | |
| 129 | |
| 130 /** | |
| 131 * Returns the least integer double value no smaller than `this`. | |
| 132 * | |
| 133 * If this is already an integer valued double, including `-0.0`, or it is not | |
| 134 * a finite value, the value is returned unmodified. | |
| 135 * | |
| 136 * For the purpose of rounding, `-0.0` is considered to be below `0.0`. | |
| 137 * A number `d` in the range `-1.0 < d < 0.0` will return `-0.0`. | |
| 138 */ | |
| 139 double ceilToDouble(); | |
| 140 | |
| 141 /** | |
| 142 * Returns the integer double value obtained by discarding any fractional | |
| 143 * digits from `this`. | |
| 144 * | |
| 145 * If this is already an integer valued double, including `-0.0`, or it is not | |
| 146 * a finite value, the value is returned unmodified. | |
| 147 * | |
| 148 * For the purpose of rounding, `-0.0` is considered to be below `0.0`. | |
| 149 * A number `d` in the range `-1.0 < d < 0.0` will return `-0.0`, and | |
| 150 * in the range `0.0 < d < 1.0` it will return 0.0. | |
| 151 */ | |
| 152 double truncateToDouble(); | |
| 153 | |
| 154 /** | |
| 155 * Provide a representation of this [double] value. | |
| 156 * | |
| 157 * The representation is a number literal such that the closest double value | |
| 158 * to the representation's mathematical value is this [double]. | |
| 159 * | |
| 160 * Returns "NaN" for the Not-a-Number value. | |
| 161 * Returns "Infinity" and "-Infinity" for positive and negative Infinity. | |
| 162 * Returns "-0.0" for negative zero. | |
| 163 * | |
| 164 * For all doubles, `d`, converting to a string and parsing the string back | |
| 165 * gives the same value again: `d == double.parse(d.toString())` (except when | |
| 166 * `d` is NaN). | |
| 167 */ | |
| 168 String toString(); | |
| 169 | |
| 170 /** | |
| 171 * Parse [source] as an double literal and return its value. | |
| 172 * | |
| 173 * Accepts an optional sign (`+` or `-`) followed by either the characters | |
| 174 * "Infinity", the characters "NaN" or a floating-point representation. | |
| 175 * A floating-point representation is composed of a mantissa and an optional | |
| 176 * exponent part. The mantissa is either a decimal point (`.`) followed by a | |
| 177 * sequence of (decimal) digits, or a sequence of digits | |
| 178 * optionally followed by a decimal point and optionally more digits. The | |
| 179 * (optional) exponent part consists of the character "e" or "E", an optional | |
| 180 * sign, and one or more digits. | |
| 181 * | |
| 182 * Leading and trailing whitespace is ignored. | |
| 183 * | |
| 184 * If the [source] is not a valid double literal, the [onError] | |
| 185 * is called with the [source] as argument, and its return value is | |
| 186 * used instead. If no `onError` is provided, a [FormatException] | |
| 187 * is thrown instead. | |
| 188 * | |
| 189 * The [onError] function is only invoked if [source] is a [String] with an | |
| 190 * invalid format. It is not invoked if the [source] is invalid for some | |
| 191 * other reason, for example by being `null`. | |
| 192 * | |
| 193 * Examples of accepted strings: | |
| 194 * | |
| 195 * "3.14" | |
| 196 * " 3.14 \xA0" | |
| 197 * "0." | |
| 198 * ".0" | |
| 199 * "-1.e3" | |
| 200 * "1234E+7" | |
| 201 * "+.12e-9" | |
| 202 * "-NaN" | |
| 203 */ | |
| 204 static double parse(String source, | |
| 205 [double onError(String source)]) { | |
| 206 return Primitives.parseDouble(source, onError); | |
| 207 } | |
| 208 } | |
| OLD | NEW |