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

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

Issue 1263963003: Fix some TODOs (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « runtime/lib/integers.dart ('k') | runtime/lib/string_buffer_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: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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 // Implements: 108 // Implements:
109 // var state = ((_A * (_state[kSTATE_LO])) + _state[kSTATE_HI]) & _MASK_64; 109 // var state = ((_A * (_state[kSTATE_LO])) + _state[kSTATE_HI]) & _MASK_64;
110 // _state[kSTATE_LO] = state & _MASK_32; 110 // _state[kSTATE_LO] = state & _MASK_32;
111 // _state[kSTATE_HI] = state >> 32; 111 // _state[kSTATE_HI] = state >> 32;
112 // This is a native to prevent 64-bit operations in Dart, which 112 // This is a native to prevent 64-bit operations in Dart, which
113 // fail with --throw_on_javascript_int_overflow. 113 // fail with --throw_on_javascript_int_overflow.
114 void _nextState() native "Random_nextState"; 114 void _nextState() native "Random_nextState";
115 115
116 int nextInt(int max) { 116 int nextInt(int max) {
117 // TODO(srdjan): Remove the 'limit' check once optimizing comparison of
118 // Smi-s with Mint constants.
119 final limit = 0x3FFFFFFF; 117 final limit = 0x3FFFFFFF;
120 if (max <= 0 || ((max > limit) && (max > _POW2_32))) { 118 if (max <= 0 || ((max > limit) && (max > _POW2_32))) {
121 throw new ArgumentError("max must be positive and < 2^32:" 119 throw new ArgumentError("max must be positive and < 2^32:"
122 " $max"); 120 " $max");
123 } 121 }
124 if ((max & -max) == max) { 122 if ((max & -max) == max) {
125 // Fast case for powers of two. 123 // Fast case for powers of two.
126 _nextState(); 124 _nextState();
127 return _state[kSTATE_LO] & (max - 1); 125 return _state[kSTATE_LO] & (max - 1);
128 } 126 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 static Uint32List _setupSeed(int seed) native "Random_setupSeed"; 160 static Uint32List _setupSeed(int seed) native "Random_setupSeed";
163 // Get a seed from the VM's random number provider. 161 // Get a seed from the VM's random number provider.
164 static Uint32List _initialSeed() native "Random_initialSeed"; 162 static Uint32List _initialSeed() native "Random_initialSeed";
165 163
166 static int _nextSeed() { 164 static int _nextSeed() {
167 // Trigger the PRNG once to change the internal state. 165 // Trigger the PRNG once to change the internal state.
168 _prng._nextState(); 166 _prng._nextState();
169 return _prng._state[kSTATE_LO]; 167 return _prng._state[kSTATE_LO];
170 } 168 }
171 } 169 }
OLDNEW
« no previous file with comments | « runtime/lib/integers.dart ('k') | runtime/lib/string_buffer_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698