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 import "dart:typed_data"; | 5 import "dart:typed_data"; |
6 | 6 |
7 // A VM patch of the dart:math library. | 7 // A VM patch of the dart:math library. |
8 | 8 |
9 // If [x] is an [int] and [exponent] is a non-negative [int], the result is | 9 // If [x] is an [int] and [exponent] is a non-negative [int], the result is |
10 // an [int], otherwise the result is a [double]. | 10 // an [int], otherwise the result is a [double]. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 double _asin(double x) native "Math_asin"; | 75 double _asin(double x) native "Math_asin"; |
76 double _atan(double x) native "Math_atan"; | 76 double _atan(double x) native "Math_atan"; |
77 double _sqrt(double x) native "Math_sqrt"; | 77 double _sqrt(double x) native "Math_sqrt"; |
78 double _exp(double x) native "Math_exp"; | 78 double _exp(double x) native "Math_exp"; |
79 double _log(double x) native "Math_log"; | 79 double _log(double x) native "Math_log"; |
80 | 80 |
81 | 81 |
82 // TODO(iposva): Handle patch methods within a patch class correctly. | 82 // TODO(iposva): Handle patch methods within a patch class correctly. |
83 @patch class Random { | 83 @patch class Random { |
84 | 84 |
85 /*@patch*/ factory Random([int seed]) { | 85 @patch factory Random([int seed]) { |
86 var state = _Random._setupSeed((seed == null) ? _Random._nextSeed() : seed); | 86 var state = _Random._setupSeed((seed == null) ? _Random._nextSeed() : seed); |
87 // Crank a couple of times to distribute the seed bits a bit further. | 87 // Crank a couple of times to distribute the seed bits a bit further. |
88 return new _Random._withState(state).._nextState() | 88 return new _Random._withState(state).._nextState() |
89 .._nextState() | 89 .._nextState() |
90 .._nextState() | 90 .._nextState() |
91 .._nextState(); | 91 .._nextState(); |
92 } | 92 } |
93 | 93 |
94 /*@patch*/ factory Random.secure() { | 94 @patch factory Random.secure() { |
95 return new _SecureRandom(); | 95 return new _SecureRandom(); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 class _Random implements Random { | 100 class _Random implements Random { |
101 // Internal state of the random number generator. | 101 // Internal state of the random number generator. |
102 final _state; | 102 final _state; |
103 static const _kSTATE_LO = 0; | 103 static const _kSTATE_LO = 0; |
104 static const _kSTATE_HI = 1; // Unused in Dart code. | 104 static const _kSTATE_HI = 1; // Unused in Dart code. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 bool nextBool() { | 206 bool nextBool() { |
207 return _getBytes(1).isEven; | 207 return _getBytes(1).isEven; |
208 } | 208 } |
209 | 209 |
210 // Constants used by the algorithm. | 210 // Constants used by the algorithm. |
211 static const _POW2_32 = 1 << 32; | 211 static const _POW2_32 = 1 << 32; |
212 static const _POW2_53_D = 1.0 * (1 << 53); | 212 static const _POW2_53_D = 1.0 * (1 << 53); |
213 } | 213 } |
214 | 214 |
OLD | NEW |