| 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 // A VM patch of the dart:math library. | 5 // A VM patch of the dart:math library. |
| 6 | |
| 7 patch int parseInt(String str) => MathNatives.parseInt(str); | 6 patch int parseInt(String str) => MathNatives.parseInt(str); |
| 8 | |
| 9 patch double parseDouble(String str) => MathNatives.parseDouble(str); | 7 patch double parseDouble(String str) => MathNatives.parseDouble(str); |
| 10 | 8 patch num pow(num x, num exponent) => MathNatives.pow(x, exponent); |
| 11 patch double atan2(num a, num b) => MathNatives.atan2(a, b); | 9 patch double atan2(num a, num b) => MathNatives.atan2(a, b); |
| 12 | |
| 13 patch num pow(num x, num exponent) => MathNatives.pow(x, exponent); | |
| 14 | |
| 15 patch double sin(num x) => MathNatives.sin(x); | 10 patch double sin(num x) => MathNatives.sin(x); |
| 16 patch double cos(num x) => MathNatives.cos(x); | 11 patch double cos(num x) => MathNatives.cos(x); |
| 17 patch double tan(num x) => MathNatives.tan(x); | 12 patch double tan(num x) => MathNatives.tan(x); |
| 18 patch double acos(num x) => MathNatives.acos(x); | 13 patch double acos(num x) => MathNatives.acos(x); |
| 19 patch double asin(num x) => MathNatives.asin(x); | 14 patch double asin(num x) => MathNatives.asin(x); |
| 20 patch double atan(num x) => MathNatives.atan(x); | 15 patch double atan(num x) => MathNatives.atan(x); |
| 21 patch double sqrt(num x) => MathNatives.sqrt(x); | 16 patch double sqrt(num x) => MathNatives.sqrt(x); |
| 22 patch double exp(num x) => MathNatives.exp(x); | 17 patch double exp(num x) => MathNatives.exp(x); |
| 23 patch double log(num x) => MathNatives.log(x); | 18 patch double log(num x) => MathNatives.log(x); |
| 24 | 19 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 return new _Random._internal(seed); | 31 return new _Random._internal(seed); |
| 37 } | 32 } |
| 38 } | 33 } |
| 39 | 34 |
| 40 | 35 |
| 41 class _Random implements Random { | 36 class _Random implements Random { |
| 42 // Internal state of the random number generator. | 37 // Internal state of the random number generator. |
| 43 var _state; | 38 var _state; |
| 44 | 39 |
| 45 _Random._internal(this._state); | 40 _Random._internal(this._state); |
| 46 | 41 |
| 47 // The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32. | 42 // The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32. |
| 48 // http://en.wikipedia.org/wiki/Multiply-with-carry | 43 // http://en.wikipedia.org/wiki/Multiply-with-carry |
| 49 // The constant A is selected from "Numerical Recipes 3rd Edition" p.348 B1. | 44 // The constant A is selected from "Numerical Recipes 3rd Edition" p.348 B1. |
| 50 int _nextInt32() { | 45 int _nextInt32() { |
| 51 _state = ((_A * (_state & _MASK_32)) + (_state >> 32)) & _MASK_64; | 46 _state = ((_A * (_state & _MASK_32)) + (_state >> 32)) & _MASK_64; |
| 52 return _state & _MASK_32; | 47 return _state & _MASK_32; |
| 53 } | 48 } |
| 54 | 49 |
| 55 int nextInt(int max) { | 50 int nextInt(int max) { |
| 56 if (max <= 0 || max > _POW2_32) { | 51 if (max <= 0 || max > _POW2_32) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 static int _nextSeed() { | 88 static int _nextSeed() { |
| 94 if (_prng == null) { | 89 if (_prng == null) { |
| 95 // TODO(iposva): Use system to get a random seed. | 90 // TODO(iposva): Use system to get a random seed. |
| 96 _prng = new Random(new Date.now().millisecondsSinceEpoch); | 91 _prng = new Random(new Date.now().millisecondsSinceEpoch); |
| 97 } | 92 } |
| 98 // Trigger the PRNG once to change the internal state. | 93 // Trigger the PRNG once to change the internal state. |
| 99 _prng._nextInt32(); | 94 _prng._nextInt32(); |
| 100 return _prng._state; | 95 return _prng._state; |
| 101 } | 96 } |
| 102 } | 97 } |
| OLD | NEW |