Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: runtime/lib/math_patch.dart

Issue 12622002: - Avoid wrapping into Mints when generating random numbers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/string_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:scalarlist";
6
5 // A VM patch of the dart:math library. 7 // A VM patch of the dart:math library.
6 patch num pow(num x, num exponent) { 8 patch num pow(num x, num exponent) {
7 if (exponent is int) { 9 if (exponent is int) {
8 return x.pow(exponent); 10 return x.pow(exponent);
9 } 11 }
10 // Double.pow will call exponent.toDouble(). 12 // Double.pow will call exponent.toDouble().
11 return x.toDouble().pow(exponent); 13 return x.toDouble().pow(exponent);
12 } 14 }
13 15
14 patch double atan2(num a, num b) => _atan2(a.toDouble(), b.toDouble()); 16 patch double atan2(num a, num b) => _atan2(a.toDouble(), b.toDouble());
(...skipping 29 matching lines...) Expand all
44 do { 46 do {
45 seed = (seed + 0x5A17) & _Random._MASK_64; 47 seed = (seed + 0x5A17) & _Random._MASK_64;
46 } while (seed == 0); 48 } while (seed == 0);
47 return new _Random._internal(seed); 49 return new _Random._internal(seed);
48 } 50 }
49 } 51 }
50 52
51 53
52 class _Random implements Random { 54 class _Random implements Random {
53 // Internal state of the random number generator. 55 // Internal state of the random number generator.
54 final _state = new List(2); 56 final _state = new Uint32List(2);
55 static const kSTATE_LO = 0; 57 static const kSTATE_LO = 0;
56 static const kSTATE_HI = 1; 58 static const kSTATE_HI = 1;
57 59
58 _Random._internal(state) { 60 _Random._internal(state) {
59 _state[kSTATE_LO] = state & _MASK_32; 61 _state[kSTATE_LO] = state & _MASK_32;
60 _state[kSTATE_HI] = state >> 32; 62 _state[kSTATE_HI] = state >> 32;
61 } 63 }
62 64
63 // The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32. 65 // The algorithm used here is Multiply with Carry (MWC) with a Base b = 2^32.
64 // http://en.wikipedia.org/wiki/Multiply-with-carry 66 // http://en.wikipedia.org/wiki/Multiply-with-carry
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 112
111 static int _nextSeed() { 113 static int _nextSeed() {
112 if (_prng == null) { 114 if (_prng == null) {
113 // TODO(iposva): Use system to get a random seed. 115 // TODO(iposva): Use system to get a random seed.
114 _prng = new Random(new DateTime.now().millisecondsSinceEpoch); 116 _prng = new Random(new DateTime.now().millisecondsSinceEpoch);
115 } 117 }
116 // Trigger the PRNG once to change the internal state. 118 // Trigger the PRNG once to change the internal state.
117 return _prng._nextInt32(); 119 return _prng._nextInt32();
118 } 120 }
119 } 121 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/string_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698