| 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 // A part of the dart:math library. | 5 // A part of the dart:math library. |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Base of the natural logarithms. | 8 * Base of the natural logarithms. |
| 9 */ | 9 */ |
| 10 final double E = 2.718281828459045; | 10 final double E = 2.718281828459045; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Square root of 2. | 43 * Square root of 2. |
| 44 */ | 44 */ |
| 45 final double SQRT2 = 1.4142135623730951; | 45 final double SQRT2 = 1.4142135623730951; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Parses a [String] representation of an [int], and returns an [int]. Throws a | 48 * Parses a [String] representation of an [int], and returns an [int]. Throws a |
| 49 * [FormatException] if [str] cannot be parsed as an [int]. | 49 * [FormatException] if [str] cannot be parsed as an [int]. |
| 50 */ | 50 */ |
| 51 int parseInt(String str) => MathNatives.parseInt(str); | 51 external int parseInt(String str); |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Parses a [String] representation of a [double], and returns a [double]. | 54 * Parses a [String] representation of a [double], and returns a [double]. |
| 55 * Throws a [FormatException] if [str] cannot be parsed as a [double]. | 55 * Throws a [FormatException] if [str] cannot be parsed as a [double]. |
| 56 */ | 56 */ |
| 57 double parseDouble(String str) => MathNatives.parseDouble(str); | 57 external double parseDouble(String str); |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Returns the minimum of two numbers. If either argument is NaN returns NaN. | 60 * Returns the minimum of two numbers. If either argument is NaN returns NaN. |
| 61 * The minimum of [:-0.0:] and [:0.0:] is [:-0.0:]. If both arguments are | 61 * The minimum of [:-0.0:] and [:0.0:] is [:-0.0:]. If both arguments are |
| 62 * equal (int and doubles with the same mathematical value are equal) then | 62 * equal (int and doubles with the same mathematical value are equal) then |
| 63 * it is unspecified which of the two arguments is returned. | 63 * it is unspecified which of the two arguments is returned. |
| 64 */ | 64 */ |
| 65 num min(num a, num b) { | 65 num min(num a, num b) { |
| 66 if (a is num) { | 66 if (a is num) { |
| 67 // TODO(floitsch): merge this if into the previous one, once dart2js | 67 // TODO(floitsch): merge this if into the previous one, once dart2js |
| 68 // correctly propagates types for logical ands. | 68 // correctly propagates types for logical ands. |
| 69 if (b is num) { | 69 if (b is num) { |
| 70 if (a > b) return b; | 70 if (a > b) return b; |
| 71 if (a < b) return a; | 71 if (a < b) return a; |
| 72 if (b is double) { | 72 if (b is double) { |
| 73 // Special case for NaN and -0.0. If one argument is NaN return NaN. | 73 // Special case for NaN and -0.0. If one argument is NaN return NaN. |
| 74 // [min] must also distinguish between -0.0 and 0.0. | 74 // [min] must also distinguish between -0.0 and 0.0. |
| 75 if (a is double) { | 75 if (a is double) { |
| 76 if (a == 0.0) { | 76 if (a == 0.0) { |
| 77 // a is either 0.0 or -0.0. b is either 0.0, -0.0 or NaN. | 77 // a is either 0.0 or -0.0. b is either 0.0, -0.0 or NaN. |
| 78 // The following returns -0.0 if either a or b is -0.0, and it | 78 // The following returns -0.0 if either a or b is -0.0, and it |
| 79 // returns NaN if b is NaN. | 79 // returns NaN if b is NaN. |
| 80 return (a + b) * a * b; | 80 return (a + b) * a * b; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 // Check for NaN and b == -0.0. | 83 // Check for NaN and b == -0.0. |
| 84 if (a == 0 && b.isNegative() || b.isNan()) return b; | 84 if (a == 0 && b.isNegative() || b.isNaN()) return b; |
| 85 return a; | 85 return a; |
| 86 } | 86 } |
| 87 return a; | 87 return a; |
| 88 } | 88 } |
| 89 throw new IllegalArgumentException(b); | 89 throw new IllegalArgumentException(b); |
| 90 } | 90 } |
| 91 throw new IllegalArgumentException(a); | 91 throw new IllegalArgumentException(a); |
| 92 } | 92 } |
| 93 | 93 |
| 94 /** | 94 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 124 return a; | 124 return a; |
| 125 } | 125 } |
| 126 throw new IllegalArgumentException(b); | 126 throw new IllegalArgumentException(b); |
| 127 } | 127 } |
| 128 throw new IllegalArgumentException(a); | 128 throw new IllegalArgumentException(a); |
| 129 } | 129 } |
| 130 | 130 |
| 131 /** | 131 /** |
| 132 * Returns the arc tangent of [a]/[b] with sign according to quadrant. | 132 * Returns the arc tangent of [a]/[b] with sign according to quadrant. |
| 133 */ | 133 */ |
| 134 double atan2(num a, num b) => MathNatives.atan2(a, b); | 134 external double atan2(num a, num b); |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * If the [exponent] is an integer the result is of the same type as [x]. | 137 * If the [exponent] is an integer the result is of the same type as [x]. |
| 138 * Otherwise it is a [double]. | 138 * Otherwise it is a [double]. |
| 139 */ | 139 */ |
| 140 num pow(num x, num exponent) => MathNatives.pow(x, exponent); | 140 external num pow(num x, num exponent); |
| 141 | 141 |
| 142 double sin(num x) => MathNatives.sin(x); | 142 // TODO(4512): Add documentation. |
| 143 double cos(num x) => MathNatives.cos(x); | 143 external double sin(num x); |
| 144 double tan(num x) => MathNatives.tan(x); | 144 external double cos(num x); |
| 145 double acos(num x) => MathNatives.acos(x); | 145 external double tan(num x); |
| 146 double asin(num x) => MathNatives.asin(x); | 146 external double acos(num x); |
| 147 double atan(num x) => MathNatives.atan(x); | 147 external double asin(num x); |
| 148 double sqrt(num x) => MathNatives.sqrt(x); | 148 external double atan(num x); |
| 149 double exp(num x) => MathNatives.exp(x); | 149 external double sqrt(num x); |
| 150 double log(num x) => MathNatives.log(x); | 150 external double exp(num x); |
| 151 external double log(num x); |
| OLD | NEW |