| 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 /** | 5 /** |
| 6 * Mathematical constants and functions, plus a random number generator. | 6 * Mathematical constants and functions, plus a random number generator. |
| 7 * | 7 * |
| 8 * To use this library in your code: | 8 * To use this library in your code: |
| 9 * | 9 * |
| 10 * import 'dart:math'; | 10 * import 'dart:math'; |
| 11 */ | 11 */ |
| 12 library dart.math; | 12 library dart.math; |
| 13 | 13 |
| 14 part "jenkins_smi_hash.dart"; | 14 part "jenkins_smi_hash.dart"; |
| 15 part "point.dart"; | 15 part "point.dart"; |
| 16 part "random.dart"; | 16 part "random.dart"; |
| 17 part "rectangle.dart"; | 17 part "rectangle.dart"; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Base of the natural logarithms. | 20 * Base of the natural logarithms. |
| 21 * | 21 * |
| 22 * Typically written as "e". | 22 * Typically written as "e". |
| 23 */ | 23 */ |
| 24 const double E = 2.718281828459045; | 24 const double E = 2.718281828459045; |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Natural logarithm of 10. | 27 * Natural logarithm of 10. |
| 28 * | |
| 29 * The natural logarithm of 10 is the number such that `pow(E, LN10) == 10`. | |
| 30 * This value is not exact, but it is the closest representable double to the | |
| 31 * exact mathematical value. | |
| 32 */ | 28 */ |
| 33 const double LN10 = 2.302585092994046; | 29 const double LN10 = 2.302585092994046; |
| 34 | 30 |
| 35 /** | 31 /** |
| 36 * Natural logarithm of 2. | 32 * Natural logarithm of 2. |
| 37 * | |
| 38 * The natural logarithm of 2 is the number such that `pow(E, LN2) == 2`. | |
| 39 * This value is not exact, but it is the closest representable double to the | |
| 40 * exact mathematical value. | |
| 41 */ | 33 */ |
| 42 const double LN2 = 0.6931471805599453; | 34 const double LN2 = 0.6931471805599453; |
| 43 | 35 |
| 44 /** | 36 /** |
| 45 * Base-2 logarithm of [E]. | 37 * Base-2 logarithm of [E]. |
| 46 */ | 38 */ |
| 47 const double LOG2E = 1.4426950408889634; | 39 const double LOG2E = 1.4426950408889634; |
| 48 | 40 |
| 49 /** | 41 /** |
| 50 * Base-10 logarithm of [E]. | 42 * Base-10 logarithm of [E]. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return a; | 127 return a; |
| 136 } | 128 } |
| 137 // max(-0.0, 0) must return 0. | 129 // max(-0.0, 0) must return 0. |
| 138 if (b == 0 && a.isNegative) return b; | 130 if (b == 0 && a.isNegative) return b; |
| 139 return a; | 131 return a; |
| 140 } | 132 } |
| 141 | 133 |
| 142 /** | 134 /** |
| 143 * A variant of [atan]. | 135 * A variant of [atan]. |
| 144 * | 136 * |
| 145 * Converts both arguments to [double]s. | 137 * Converts both arguments to doubles. |
| 146 * | 138 * |
| 147 * Returns the angle in radians between the positive x-axis | 139 * Returns the angle between the positive x-axis and the vector ([b],[a]). |
| 148 * and the vector ([b],[a]). | 140 * The result, in radians, is in the range -PI..PI. |
| 149 * The result is in the range -PI..PI. | |
| 150 * | 141 * |
| 151 * If [b] is positive, this is the same as `atan(b/a)`. | 142 * If [b] is positive, this is the same as `atan(b/a)`. |
| 152 * | 143 * |
| 153 * The result is negative when [a] is negative (including when [a] is the | 144 * The result is negative when [a] is negative (including when [a] is the |
| 154 * double -0.0). | 145 * double -0.0). |
| 155 * | 146 * |
| 156 * If [a] is equal to zero, the vector ([b],[a]) is considered parallel to | 147 * If [a] is equal to zero, the vector ([b],[a]) is considered parallel to |
| 157 * the x-axis, even if [b] is also equal to zero. The sign of [b] determines | 148 * the x-axis, even if [b] is also equal to zero. The sign of [b] determines |
| 158 * the direction of the vector along the x-axis. | 149 * the direction of the vector along the x-axis. |
| 159 * | 150 * |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 * - if `y` is -Infinity, the result is `1/pow(x, Infinity)`. | 185 * - if `y` is -Infinity, the result is `1/pow(x, Infinity)`. |
| 195 * | 186 * |
| 196 * This corresponds to the `pow` function defined in the IEEE Standard 754-2008. | 187 * This corresponds to the `pow` function defined in the IEEE Standard 754-2008. |
| 197 * | 188 * |
| 198 * Notice that an [int] result cannot overflow, but a [double] result might | 189 * Notice that an [int] result cannot overflow, but a [double] result might |
| 199 * be [double.INFINITY]. | 190 * be [double.INFINITY]. |
| 200 */ | 191 */ |
| 201 external num pow(num x, num exponent); | 192 external num pow(num x, num exponent); |
| 202 | 193 |
| 203 /** | 194 /** |
| 204 * Converts [radians] to a [double] and returns the sine of the value. | 195 * Converts [x] to a double and returns the sine of the value. |
| 205 * | 196 * |
| 206 * If [radians] is not a finite number, the result is NaN. | 197 * If [x] is not a finite number, the result is NaN. |
| 207 */ | 198 */ |
| 208 external double sin(num radians); | 199 external double sin(num x); |
| 209 | 200 |
| 210 /** | 201 /** |
| 211 * Converts [radians] to a [double] and returns the cosine of the value. | 202 * Converts [x] to a double and returns the cosine of the value. |
| 212 * | 203 * |
| 213 * If [radians] is not a finite number, the result is NaN. | 204 * If [x] is not a finite number, the result is NaN. |
| 214 */ | 205 */ |
| 215 external double cos(num radians); | 206 external double cos(num x); |
| 216 | 207 |
| 217 /** | 208 /** |
| 218 * Converts [radians] to a [double] and returns the tangent of the value. | 209 * Converts [x] to a double and returns the tangent of the value. |
| 219 * | 210 * |
| 220 * The tangent function is equivalent to `sin(radians)/cos(radians)` and may be | 211 * The tangent function is equivalent to `sin(x)/cos(x)` and may be |
| 221 * infinite (positive or negative) when `cos(radians)` is equal to zero. | 212 * infinite (positive or negative) when `cos(x)` is equal to zero. |
| 222 * If [radians] is not a finite number, the result is NaN. | 213 * If [x] is not a finite number, the result is NaN. |
| 223 */ | 214 */ |
| 224 external double tan(num radians); | 215 external double tan(num x); |
| 225 | 216 |
| 226 /** | 217 /** |
| 227 * Converts [x] to a [double] and returns its arc cosine in radians. | 218 * Converts [x] to a double and returns the arc cosine of the value. |
| 228 * | 219 * |
| 229 * Returns a value in the range 0..PI, or NaN if [x] is outside | 220 * Returns a value in the range 0..PI, or NaN if [x] is outside |
| 230 * the range -1..1. | 221 * the range -1..1. |
| 231 */ | 222 */ |
| 232 external double acos(num x); | 223 external double acos(num x); |
| 233 | 224 |
| 234 /** | 225 /** |
| 235 * Converts [x] to a [double] and returns its arc sine in radians. | 226 * Converts [x] to a double and returns the arc sine of the value. |
| 236 * | 227 * |
| 237 * Returns a value in the range -PI/2..PI/2, or NaN if [x] is outside | 228 * Returns a value in the range -PI/2..PI/2, or NaN if [x] is outside |
| 238 * the range -1..1. | 229 * the range -1..1. |
| 239 */ | 230 */ |
| 240 external double asin(num x); | 231 external double asin(num x); |
| 241 | 232 |
| 242 /** | 233 /** |
| 243 * Converts [x] to a [double] and returns its arc tangent in radians. | 234 * Converts [x] to a double and returns the arc tangent of the value. |
| 244 * | 235 * |
| 245 * Returns a value in the range -PI/2..PI/2, or NaN if [x] is NaN. | 236 * Returns a value in the range -PI/2..PI/2, or NaN if [x] is NaN. |
| 246 */ | 237 */ |
| 247 external double atan(num x); | 238 external double atan(num x); |
| 248 | 239 |
| 249 /** | 240 /** |
| 250 * Converts [x] to a [double] and returns the positive square root of the value. | 241 * Converts [x] to a double and returns the positive square root of the value. |
| 251 * | 242 * |
| 252 * Returns -0.0 if [x] is -0.0, and NaN if [x] is otherwise negative or NaN. | 243 * Returns -0.0 if [x] is -0.0, and NaN if [x] is otherwise negative or NaN. |
| 253 */ | 244 */ |
| 254 external double sqrt(num x); | 245 external double sqrt(num x); |
| 255 | 246 |
| 256 /** | 247 /** |
| 257 * Converts [x] to a [double] and returns the natural exponent, [E], | 248 * Converts [x] to a double and returns the natural exponent, [E], |
| 258 * to the power [x]. | 249 * to the power [x]. |
| 259 * | 250 * |
| 260 * Returns NaN if [x] is NaN. | 251 * Returns NaN if [x] is NaN. |
| 261 */ | 252 */ |
| 262 external double exp(num x); | 253 external double exp(num x); |
| 263 | 254 |
| 264 /** | 255 /** |
| 265 * Converts [x] to a [double] and returns the natural logarithm of the value. | 256 * Converts [x] to a double and returns the natural logarithm of the value. |
| 266 * | 257 * |
| 267 * Returns negative infinity if [x] is equal to zero. | 258 * Returns negative infinity if [x] is equal to zero. |
| 268 * Returns NaN if [x] is NaN or less than zero. | 259 * Returns NaN if [x] is NaN or less than zero. |
| 269 */ | 260 */ |
| 270 external double log(num x); | 261 external double log(num x); |
| OLD | NEW |