| 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 // Patch file for dart:math library. | 5 // Patch file for dart:math library. |
| 6 | 6 |
| 7 // Imports checkNum etc. used below. | 7 // Imports checkNum etc. used below. |
| 8 #import("js_helper.dart"); | 8 #import("js_helper.dart"); |
| 9 | 9 |
| 10 patch double sqrt(num x) | 10 patch double sqrt(num x) |
| 11 => JS('double', @'Math.sqrt(#)', checkNum(x)); | 11 => JS('double', r'Math.sqrt(#)', checkNum(x)); |
| 12 | 12 |
| 13 patch double sin(num x) | 13 patch double sin(num x) |
| 14 => JS('double', @'Math.sin(#)', checkNum(x)); | 14 => JS('double', r'Math.sin(#)', checkNum(x)); |
| 15 | 15 |
| 16 patch double cos(num x) | 16 patch double cos(num x) |
| 17 => JS('double', @'Math.cos(#)', checkNum(x)); | 17 => JS('double', r'Math.cos(#)', checkNum(x)); |
| 18 | 18 |
| 19 patch double tan(num x) | 19 patch double tan(num x) |
| 20 => JS('double', @'Math.tan(#)', checkNum(x)); | 20 => JS('double', r'Math.tan(#)', checkNum(x)); |
| 21 | 21 |
| 22 patch double acos(num x) | 22 patch double acos(num x) |
| 23 => JS('double', @'Math.acos(#)', checkNum(x)); | 23 => JS('double', r'Math.acos(#)', checkNum(x)); |
| 24 | 24 |
| 25 patch double asin(num x) | 25 patch double asin(num x) |
| 26 => JS('double', @'Math.asin(#)', checkNum(x)); | 26 => JS('double', r'Math.asin(#)', checkNum(x)); |
| 27 | 27 |
| 28 patch double atan(num x) | 28 patch double atan(num x) |
| 29 => JS('double', @'Math.atan(#)', checkNum(x)); | 29 => JS('double', r'Math.atan(#)', checkNum(x)); |
| 30 | 30 |
| 31 patch double atan2(num a, num b) | 31 patch double atan2(num a, num b) |
| 32 => JS('double', @'Math.atan2(#, #)', checkNum(a), checkNum(b)); | 32 => JS('double', r'Math.atan2(#, #)', checkNum(a), checkNum(b)); |
| 33 | 33 |
| 34 patch double exp(num x) | 34 patch double exp(num x) |
| 35 => JS('double', @'Math.exp(#)', checkNum(x)); | 35 => JS('double', r'Math.exp(#)', checkNum(x)); |
| 36 | 36 |
| 37 patch double log(num x) | 37 patch double log(num x) |
| 38 => JS('double', @'Math.log(#)', checkNum(x)); | 38 => JS('double', r'Math.log(#)', checkNum(x)); |
| 39 | 39 |
| 40 patch num pow(num x, num exponent) { | 40 patch num pow(num x, num exponent) { |
| 41 checkNum(x); | 41 checkNum(x); |
| 42 checkNum(exponent); | 42 checkNum(exponent); |
| 43 return JS('num', @'Math.pow(#, #)', x, exponent); | 43 return JS('num', r'Math.pow(#, #)', x, exponent); |
| 44 } | 44 } |
| 45 | 45 |
| 46 patch class Random { | 46 patch class Random { |
| 47 patch factory Random([int seed]) => const _Random(); | 47 patch factory Random([int seed]) => const _Random(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 class _Random implements Random { | 50 class _Random implements Random { |
| 51 // The Dart2JS implementation of Random doesn't use a seed. | 51 // The Dart2JS implementation of Random doesn't use a seed. |
| 52 const _Random(); | 52 const _Random(); |
| 53 | 53 |
| 54 int nextInt(int max) { | 54 int nextInt(int max) { |
| 55 if (max < 0) throw new IllegalArgumentException("negative max: $max"); | 55 if (max < 0) throw new IllegalArgumentException("negative max: $max"); |
| 56 if (max > 0xFFFFFFFF) max = 0xFFFFFFFF; | 56 if (max > 0xFFFFFFFF) max = 0xFFFFFFFF; |
| 57 return JS("int", "(Math.random() * #) >>> 0", max); | 57 return JS("int", "(Math.random() * #) >>> 0", max); |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Generates a positive random floating point value uniformly distributed on | 61 * Generates a positive random floating point value uniformly distributed on |
| 62 * the range from 0.0, inclusive, to 1.0, exclusive. | 62 * the range from 0.0, inclusive, to 1.0, exclusive. |
| 63 */ | 63 */ |
| 64 double nextDouble() => JS("double", "Math.random()"); | 64 double nextDouble() => JS("double", "Math.random()"); |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Generates a random boolean value. | 67 * Generates a random boolean value. |
| 68 */ | 68 */ |
| 69 bool nextBool() => JS("bool", "Math.random() < 0.5"); | 69 bool nextBool() => JS("bool", "Math.random() < 0.5"); |
| 70 } | 70 } |
| OLD | NEW |