| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 * [FormatException] if [str] cannot be parsed as an [int]. | 49 * [FormatException] if [str] cannot be parsed as an [int]. |
| 50 */ | 50 */ |
| 51 external int parseInt(String 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 external double parseDouble(String str); | 57 external double parseDouble(String str); |
| 58 | 58 |
| 59 /** |
| 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 |
| 62 * equal (int and doubles with the same mathematical value are equal) then |
| 63 * it is unspecified which of the two arguments is returned. |
| 64 */ |
| 59 num min(num a, num b) { | 65 num min(num a, num b) { |
| 60 int c = a.compareTo(b); | 66 if (a is num) { |
| 61 if (c == 0) return a; | 67 // TODO(floitsch): merge this if into the previous one, once dart2js |
| 62 if (c < 0) { | 68 // correctly propagates types for logical ands. |
| 63 if ((b is double) && b.isNaN()) return b; | 69 if (b is num) { |
| 64 return a; | 70 if (a > b) return b; |
| 71 if (a < b) return a; |
| 72 if (b is double) { |
| 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. |
| 75 if (a is double) { |
| 76 if (a == 0.0) { |
| 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 |
| 79 // returns NaN if b is NaN. |
| 80 return (a + b) * a * b; |
| 81 } |
| 82 } |
| 83 // Check for NaN and b == -0.0. |
| 84 if (a == 0 && b.isNegative() || b.isNaN()) return b; |
| 85 return a; |
| 86 } |
| 87 return a; |
| 88 } |
| 89 throw new IllegalArgumentException(b); |
| 65 } | 90 } |
| 66 if ((a is double) && a.isNaN()) return a; | 91 throw new IllegalArgumentException(a); |
| 67 return b; | |
| 68 } | |
| 69 | |
| 70 num max(num a, num b) { | |
| 71 // NaNs are handled correctly since the compareTo function always considers | |
| 72 // them to be bigger than any other operand. | |
| 73 return (a.compareTo(b) < 0) ? b : a; | |
| 74 } | 92 } |
| 75 | 93 |
| 76 /** | 94 /** |
| 95 * Returns the maximum of two numbers. If either argument is NaN returns NaN. |
| 96 * The maximum of [:-0.0:] and [:0.0:] is [:0.0:]. If both arguments are |
| 97 * equal (int and doubles with the same mathematical value are equal) then |
| 98 * it is unspecified which of the two arguments is returned. |
| 99 */ |
| 100 num max(num a, num b) { |
| 101 if (a is num) { |
| 102 // TODO(floitsch): merge this if into the previous one, once dart2js |
| 103 // correctly propagates types for logical ands. |
| 104 if (b is num) { |
| 105 if (a > b) return a; |
| 106 if (a < b) return b; |
| 107 if (b is double) { |
| 108 // Special case for NaN and -0.0. If one argument is NaN return NaN. |
| 109 // [max] must also distinguish between -0.0 and 0.0. |
| 110 if (a is double) { |
| 111 if (a == 0.0) { |
| 112 // a is either 0.0 or -0.0. b is either 0.0, -0.0, or NaN. |
| 113 // The following returns 0.0 if either a or b is 0.0, and it |
| 114 // returns NaN if b is NaN. |
| 115 return a + b; |
| 116 } |
| 117 } |
| 118 // Check for NaN. |
| 119 if (b.isNaN()) return b; |
| 120 return a; |
| 121 } |
| 122 // max(-0.0, 0) must return 0. |
| 123 if (b == 0 && a.isNegative()) return b; |
| 124 return a; |
| 125 } |
| 126 throw new IllegalArgumentException(b); |
| 127 } |
| 128 throw new IllegalArgumentException(a); |
| 129 } |
| 130 |
| 131 /** |
| 77 * 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. |
| 78 */ | 133 */ |
| 79 external double atan2(num a, num b); | 134 external double atan2(num a, num b); |
| 80 | 135 |
| 81 /** | 136 /** |
| 82 * 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]. |
| 83 * Otherwise it is a [double]. | 138 * Otherwise it is a [double]. |
| 84 */ | 139 */ |
| 85 external num pow(num x, num exponent); | 140 external num pow(num x, num exponent); |
| 86 | 141 |
| 87 external double sin(num x); | 142 external double sin(num x); |
| 88 external double cos(num x); | 143 external double cos(num x); |
| 89 external double tan(num x); | 144 external double tan(num x); |
| 90 external double acos(num x); | 145 external double acos(num x); |
| 91 external double asin(num x); | 146 external double asin(num x); |
| 92 external double atan(num x); | 147 external double atan(num x); |
| 93 external double sqrt(num x); | 148 external double sqrt(num x); |
| 94 external double exp(num x); | 149 external double exp(num x); |
| 95 external double log(num x); | 150 external double log(num x); |
| OLD | NEW |