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 // Native methods for Math. | |
6 var native_Math_ceil = Math.ceil; | |
7 var native_Math_floor = Math.floor; | |
8 var native_Math_max = Math.max; | |
9 var native_Math_min = Math.min; | |
10 var native_Math_round = Math.round; | |
11 | |
12 // A valid integer-string is composed of: | |
13 // optional whitespace: \s* | |
14 // an optional sign: [+-]? | |
15 // either digits (at least one): \d+ | |
16 // or a hex-literal: 0[xX][0-9abcdefABCDEF]+ | |
17 // optional whitespace: \s* | |
18 var math$INT_REGEXP = | |
19 /^\s*[+-]?(:?\d+|0[xX][0-9abcdefABCDEF]+)\s*$/; | |
20 | |
21 // A valid double-string is composed of: | |
22 // optional whitespace: \s* | |
23 // an optional sign: [+-]? | |
24 // either: | |
25 // digits* . digits+ exponent? | |
26 // digits+ exponent | |
27 // Infinity | |
28 // NaN | |
29 // optional whitespace: \s* | |
30 var math$DOUBLE_REGEXP = | |
31 /^\s*[+-]?((\d*\.\d+([eE][+-]?\d+)?)|(\d+([eE][+-]?\d+))|Infinity|NaN)\s*$/; | |
32 | |
33 function native_MathNatives_parseDouble(str) { | |
34 if (math$INT_REGEXP.test(str) || math$DOUBLE_REGEXP.test(str)) return +str; | |
35 throw native_MathNatives__newBadNumberFormat(str); | |
36 } | |
37 | |
38 | |
39 | |
40 function native_MathNatives_parseInt(str) { | |
41 if (math$INT_REGEXP.test(str)) return +str; | |
42 throw native_MathNatives__newBadNumberFormat(str); | |
43 } | |
44 | |
45 function native_MathNatives_random() { return Math.random(); } | |
46 function native_MathNatives_sin(x) { return Math.sin(x); } | |
47 function native_MathNatives_cos(x) { return Math.cos(x); } | |
48 function native_MathNatives_tan(x) { return Math.tan(x); } | |
49 function native_MathNatives_asin(x) { return Math.asin(x); } | |
50 function native_MathNatives_acos(x) { return Math.acos(x); } | |
51 function native_MathNatives_atan(x) { return Math.atan(x); } | |
52 function native_MathNatives_atan2(x, y) { return Math.atan2(x, y); } | |
53 function native_MathNatives_sqrt(x) { return Math.sqrt(x); } | |
54 function native_MathNatives_exp(x) { return Math.exp(x); } | |
55 function native_MathNatives_log(x) { return Math.log(x); } | |
56 function native_MathNatives_pow(x, y) { return Math.pow(x, y); } | |
OLD | NEW |