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 library dart.math; | 8 library dart.math; |
9 | 9 |
10 part "jenkins_smi_hash.dart"; | 10 part "jenkins_smi_hash.dart"; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 /** | 57 /** |
58 * Returns the lesser of two numbers. | 58 * Returns the lesser of two numbers. |
59 * | 59 * |
60 * Returns NaN if either argument is NaN. | 60 * Returns NaN if either argument is NaN. |
61 * The lesser of [:-0.0:] and [:0.0:] is [:-0.0:]. | 61 * The lesser of [:-0.0:] and [:0.0:] is [:-0.0:]. |
62 * If the arguments are otherwise equal (including int and doubles with the | 62 * If the arguments are otherwise equal (including int and doubles with the |
63 * same mathematical value) then it is unspecified which of the two arguments | 63 * same mathematical value) then it is unspecified which of the two arguments |
64 * is returned. | 64 * is returned. |
65 */ | 65 */ |
66 num min(num a, num b) { | 66 num/*=T*/ min/*<T extends num>*/(num/*=T*/ a, num/*=T*/ b) { |
67 // These partially redundant type checks improve code quality for dart2js. | 67 // These partially redundant type checks improve code quality for dart2js. |
68 // Most of the improvement is at call sites from the inferred non-null num | 68 // Most of the improvement is at call sites from the inferred non-null num |
69 // return type. | 69 // return type. |
70 if (a is! num) throw new ArgumentError(a); | 70 if (a is! num) throw new ArgumentError(a); |
71 if (b is! num) throw new ArgumentError(b); | 71 if (b is! num) throw new ArgumentError(b); |
72 | 72 |
73 if (a > b) return b; | 73 if (a > b) return b; |
74 if (a < b) return a; | 74 if (a < b) return a; |
75 if (b is double) { | 75 if (b is double) { |
76 // Special case for NaN and -0.0. If one argument is NaN return NaN. | 76 // Special case for NaN and -0.0. If one argument is NaN return NaN. |
(...skipping 14 matching lines...) Expand all Loading... |
91 } | 91 } |
92 | 92 |
93 /** | 93 /** |
94 * Returns the larger of two numbers. | 94 * Returns the larger of two numbers. |
95 * | 95 * |
96 * Returns NaN if either argument is NaN. | 96 * Returns NaN if either argument is NaN. |
97 * The larger of [:-0.0:] and [:0.0:] is [:0.0:]. If the arguments are | 97 * The larger of [:-0.0:] and [:0.0:] is [:0.0:]. If the arguments are |
98 * otherwise equal (including int and doubles with the same mathematical value) | 98 * otherwise equal (including int and doubles with the same mathematical value) |
99 * then it is unspecified which of the two arguments is returned. | 99 * then it is unspecified which of the two arguments is returned. |
100 */ | 100 */ |
101 num max(num a, num b) { | 101 num/*=T*/ max/*<T extends num>*/(num/*=T*/ a, num/*=T*/ b) { |
102 // These partially redundant type checks improve code quality for dart2js. | 102 // These partially redundant type checks improve code quality for dart2js. |
103 // Most of the improvement is at call sites from the inferred non-null num | 103 // Most of the improvement is at call sites from the inferred non-null num |
104 // return type. | 104 // return type. |
105 if (a is! num) throw new ArgumentError(a); | 105 if (a is! num) throw new ArgumentError(a); |
106 if (b is! num) throw new ArgumentError(b); | 106 if (b is! num) throw new ArgumentError(b); |
107 | 107 |
108 if (a > b) return a; | 108 if (a > b) return a; |
109 if (a < b) return b; | 109 if (a < b) return b; |
110 if (b is double) { | 110 if (b is double) { |
111 // Special case for NaN and -0.0. If one argument is NaN return NaN. | 111 // Special case for NaN and -0.0. If one argument is NaN return NaN. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 * Returns NaN if [x] is NaN. | 244 * Returns NaN if [x] is NaN. |
245 */ | 245 */ |
246 external double exp(num x); | 246 external double exp(num x); |
247 | 247 |
248 /** | 248 /** |
249 * Converts [x] to a double and returns the natural logarithm of the value. | 249 * Converts [x] to a double and returns the natural logarithm of the value. |
250 * Returns negative infinity if [x] is equal to zero. | 250 * Returns negative infinity if [x] is equal to zero. |
251 * Returns NaN if [x] is NaN or less than zero. | 251 * Returns NaN if [x] is NaN or less than zero. |
252 */ | 252 */ |
253 external double log(num x); | 253 external double log(num x); |
OLD | NEW |