| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Dart core library. | |
| 6 | |
| 7 class Math native 'Math' { | |
| 8 /** | |
| 9 * Base of the natural logarithms. | |
| 10 */ | |
| 11 static final double E = 2.718281828459045; | |
| 12 | |
| 13 /** | |
| 14 * Natural logarithm of 10. | |
| 15 */ | |
| 16 static final double LN10 = 2.302585092994046; | |
| 17 | |
| 18 /** | |
| 19 * Natural logarithm of 2. | |
| 20 */ | |
| 21 static final double LN2 = 0.6931471805599453; | |
| 22 | |
| 23 /** | |
| 24 * Base-2 logarithm of E. | |
| 25 */ | |
| 26 static final double LOG2E = 1.4426950408889634; | |
| 27 | |
| 28 /** | |
| 29 * Base-10 logarithm of E. | |
| 30 */ | |
| 31 static final double LOG10E = 0.4342944819032518; | |
| 32 | |
| 33 /** | |
| 34 * The PI constant. | |
| 35 */ | |
| 36 static final double PI = 3.1415926535897932; | |
| 37 | |
| 38 /** | |
| 39 * Square root of 1/2. | |
| 40 */ | |
| 41 static final double SQRT1_2 = 0.7071067811865476; | |
| 42 | |
| 43 /** | |
| 44 * Square root of 2. | |
| 45 */ | |
| 46 static final double SQRT2 = 1.4142135623730951; | |
| 47 | |
| 48 /** | |
| 49 * Parses a [String] representation of an [int], and returns | |
| 50 * an [int]. Throws a [BadNumberFormatException] if [str] | |
| 51 * cannot be parsed as an [int]. | |
| 52 */ | |
| 53 static int parseInt(String str) native ''' | |
| 54 var match = /^\\s*[+-]?(?:(0[xX][abcdefABCDEF0-9]+)|\\d+)\\s*\$/.exec(str); | |
| 55 if (!match) \$throw(new BadNumberFormatException(str)); | |
| 56 var isHex = !!match[1]; | |
| 57 var ret = parseInt(str, isHex ? 16 : 10); | |
| 58 if (isNaN(ret)) \$throw(new BadNumberFormatException(str)); | |
| 59 return ret;''' { throw new BadNumberFormatException(""); } | |
| 60 | |
| 61 /** | |
| 62 * Parses a [String] representation of a [double], and returns | |
| 63 * a [double]. Throws a [BadNumberFormatException] if [str] cannot | |
| 64 * be parsed as a [double]. | |
| 65 */ | |
| 66 static double parseDouble(String str) native '''var ret = parseFloat(str); | |
| 67 if (isNaN(ret) && str != 'NaN') \$throw(new BadNumberFormatException(str)); | |
| 68 return ret;''' { throw new BadNumberFormatException(""); } | |
| 69 | |
| 70 static num min(num a, num b) native '''if (a == b) return a; | |
| 71 if (a < b) { | |
| 72 if (isNaN(b)) return b; | |
| 73 else return a; | |
| 74 } | |
| 75 if (isNaN(a)) return a; | |
| 76 else return b;'''; | |
| 77 | |
| 78 static num max(num a, num b) native 'return (a >= b) ? a : b;'; | |
| 79 | |
| 80 /** | |
| 81 * Returns the arc tangent of [a]/[b] with sign according to quadrant. | |
| 82 */ | |
| 83 static double atan2(num a, num b) native; | |
| 84 | |
| 85 /** | |
| 86 * If the [exponent] is an integer the result is of the same type as [x]. | |
| 87 * Otherwise it is a [double]. | |
| 88 */ | |
| 89 static num pow(num x, num exponent) native; | |
| 90 | |
| 91 /** | |
| 92 * Returns a random double greater than or equal to 0.0 and less | |
| 93 * than 1.0. | |
| 94 */ | |
| 95 static double random() native; | |
| 96 | |
| 97 static double sin(num x) native; | |
| 98 static double cos(num x) native; | |
| 99 static double tan(num x) native; | |
| 100 static double acos(num x) native; | |
| 101 static double asin(num x) native; | |
| 102 static double atan(num x) native; | |
| 103 static double sqrt(num x) native; | |
| 104 static double exp(num x) native; | |
| 105 static double log(num x) native; | |
| 106 } | |
| OLD | NEW |