Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart core library. | 5 // Dart core library. |
| 6 | 6 |
| 7 class Math native 'Math' { | 7 class Math native 'Math' { |
| 8 /** | 8 /** |
| 9 * Base of the natural logarithms. | 9 * Base of the natural logarithms. |
| 10 */ | 10 */ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 /** | 43 /** |
| 44 * Square root of 2. | 44 * Square root of 2. |
| 45 */ | 45 */ |
| 46 static final double SQRT2 = 1.4142135623730951; | 46 static final double SQRT2 = 1.4142135623730951; |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Parses a [String] representation of an [int], and returns | 49 * Parses a [String] representation of an [int], and returns |
| 50 * an [int]. Throws a [BadNumberFormatException] if [str] | 50 * an [int]. Throws a [BadNumberFormatException] if [str] |
| 51 * cannot be parsed as an [int]. | 51 * cannot be parsed as an [int]. |
| 52 */ | 52 */ |
| 53 static int parseInt(String str) native '''var ret = parseInt(str); | 53 static int parseInt(String str) native ''' |
| 54 var isHex = (str.length > 2) && str[0] == '0' && | |
|
kasperl
2012/03/02 13:34:10
Do you need to trim first?
floitsch
2012/03/02 17:00:29
Using a regexp now.
| |
| 55 (str[1] == 'x' || str[1] == 'X'); | |
| 56 var ret = parseInt(str, isHex ? 16 : 10); | |
| 54 if (isNaN(ret)) \$throw(new BadNumberFormatException(str)); | 57 if (isNaN(ret)) \$throw(new BadNumberFormatException(str)); |
| 55 return ret;''' { throw new BadNumberFormatException(""); } | 58 return ret;''' { throw new BadNumberFormatException(""); } |
| 56 | 59 |
| 57 /** | 60 /** |
| 58 * Parses a [String] representation of a [double], and returns | 61 * Parses a [String] representation of a [double], and returns |
| 59 * a [double]. Throws a [BadNumberFormatException] if [str] cannot | 62 * a [double]. Throws a [BadNumberFormatException] if [str] cannot |
| 60 * be parsed as a [double]. | 63 * be parsed as a [double]. |
| 61 */ | 64 */ |
| 62 static double parseDouble(String str) native '''var ret = parseFloat(str); | 65 static double parseDouble(String str) native '''var ret = parseFloat(str); |
| 63 if (isNaN(ret) && str != 'NaN') \$throw(new BadNumberFormatException(str)); | 66 if (isNaN(ret) && str != 'NaN') \$throw(new BadNumberFormatException(str)); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 93 static double sin(num x) native; | 96 static double sin(num x) native; |
| 94 static double cos(num x) native; | 97 static double cos(num x) native; |
| 95 static double tan(num x) native; | 98 static double tan(num x) native; |
| 96 static double acos(num x) native; | 99 static double acos(num x) native; |
| 97 static double asin(num x) native; | 100 static double asin(num x) native; |
| 98 static double atan(num x) native; | 101 static double atan(num x) native; |
| 99 static double sqrt(num x) native; | 102 static double sqrt(num x) native; |
| 100 static double exp(num x) native; | 103 static double exp(num x) native; |
| 101 static double log(num x) native; | 104 static double log(num x) native; |
| 102 } | 105 } |
| OLD | NEW |