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 patch num pow(num x, num exponent) => MathNatives.pow(x, exponent); | 6 patch num pow(num x, num exponent) => MathNatives.pow(x, exponent); |
7 patch double atan2(num a, num b) => MathNatives.atan2(a, b); | 7 patch double atan2(num a, num b) => MathNatives.atan2(a, b); |
8 patch double sin(num x) => MathNatives.sin(x); | 8 patch double sin(num x) => MathNatives.sin(x); |
9 patch double cos(num x) => MathNatives.cos(x); | 9 patch double cos(num x) => MathNatives.cos(x); |
10 patch double tan(num x) => MathNatives.tan(x); | 10 patch double tan(num x) => MathNatives.tan(x); |
(...skipping 29 matching lines...) Expand all Loading... |
40 // The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32. | 40 // The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32. |
41 // http://en.wikipedia.org/wiki/Multiply-with-carry | 41 // http://en.wikipedia.org/wiki/Multiply-with-carry |
42 // The constant A is selected from "Numerical Recipes 3rd Edition" p.348 B1. | 42 // The constant A is selected from "Numerical Recipes 3rd Edition" p.348 B1. |
43 int _nextInt32() { | 43 int _nextInt32() { |
44 _state = ((_A * (_state & _MASK_32)) + (_state >> 32)) & _MASK_64; | 44 _state = ((_A * (_state & _MASK_32)) + (_state >> 32)) & _MASK_64; |
45 return _state & _MASK_32; | 45 return _state & _MASK_32; |
46 } | 46 } |
47 | 47 |
48 int nextInt(int max) { | 48 int nextInt(int max) { |
49 if (max <= 0 || max > _POW2_32) { | 49 if (max <= 0 || max > _POW2_32) { |
50 throw new IllegalArgumentException("max must be positive and < 2^32:" | 50 throw new ArgumentError("max must be positive and < 2^32:" |
51 " $max"); | 51 " $max"); |
52 } | 52 } |
53 if ((max & -max) == max) { | 53 if ((max & -max) == max) { |
54 // Fast case for powers of two. | 54 // Fast case for powers of two. |
55 return _nextInt32() & (max - 1); | 55 return _nextInt32() & (max - 1); |
56 } | 56 } |
57 | 57 |
58 var rnd32; | 58 var rnd32; |
59 var result; | 59 var result; |
60 do { | 60 do { |
(...skipping 25 matching lines...) Expand all Loading... |
86 static int _nextSeed() { | 86 static int _nextSeed() { |
87 if (_prng == null) { | 87 if (_prng == null) { |
88 // TODO(iposva): Use system to get a random seed. | 88 // TODO(iposva): Use system to get a random seed. |
89 _prng = new Random(new Date.now().millisecondsSinceEpoch); | 89 _prng = new Random(new Date.now().millisecondsSinceEpoch); |
90 } | 90 } |
91 // Trigger the PRNG once to change the internal state. | 91 // Trigger the PRNG once to change the internal state. |
92 _prng._nextInt32(); | 92 _prng._nextInt32(); |
93 return _prng._state; | 93 return _prng._state; |
94 } | 94 } |
95 } | 95 } |
OLD | NEW |