OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var rngstate; // Initialized to a Uint32Array during genesis. | 5 var rngstate; // Initialized to a Uint32Array during genesis. |
6 | 6 |
7 (function(global, utils) { | 7 (function(global, utils) { |
8 | |
9 "use strict"; | 8 "use strict"; |
10 | 9 |
11 %CheckIsBootstrapping(); | 10 %CheckIsBootstrapping(); |
12 | 11 |
13 // ------------------------------------------------------------------- | 12 // ------------------------------------------------------------------- |
14 // Imports | 13 // Imports |
15 | 14 |
16 var GlobalObject = global.Object; | 15 var GlobalObject = global.Object; |
17 var InternalArray = utils.InternalArray; | 16 var InternalArray = utils.InternalArray; |
18 | 17 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 function MathRandom() { | 130 function MathRandom() { |
132 var r0 = (MathImul(18030, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0; | 131 var r0 = (MathImul(18030, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0; |
133 rngstate[0] = r0; | 132 rngstate[0] = r0; |
134 var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16)) | 0; | 133 var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16)) | 0; |
135 rngstate[1] = r1; | 134 rngstate[1] = r1; |
136 var x = ((r0 << 16) + (r1 & 0xFFFF)) | 0; | 135 var x = ((r0 << 16) + (r1 & 0xFFFF)) | 0; |
137 // Division by 0x100000000 through multiplication by reciprocal. | 136 // Division by 0x100000000 through multiplication by reciprocal. |
138 return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10; | 137 return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10; |
139 } | 138 } |
140 | 139 |
| 140 function MathRandomRaw() { |
| 141 var r0 = (MathImul(18030, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0; |
| 142 rngstate[0] = r0; |
| 143 var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16)) | 0; |
| 144 rngstate[1] = r1; |
| 145 var x = ((r0 << 16) + (r1 & 0xFFFF)) | 0; |
| 146 return x & 0x3fffffff; |
| 147 } |
| 148 |
141 // ECMA 262 - 15.8.2.15 | 149 // ECMA 262 - 15.8.2.15 |
142 function MathRound(x) { | 150 function MathRound(x) { |
143 return %RoundNumber(TO_NUMBER_INLINE(x)); | 151 return %RoundNumber(TO_NUMBER_INLINE(x)); |
144 } | 152 } |
145 | 153 |
146 // ECMA 262 - 15.8.2.17 | 154 // ECMA 262 - 15.8.2.17 |
147 function MathSqrtJS(x) { | 155 function MathSqrtJS(x) { |
148 return %_MathSqrt(+x); | 156 return %_MathSqrt(+x); |
149 } | 157 } |
150 | 158 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 %SetForceInlineFlag(MathSqrtJS); | 359 %SetForceInlineFlag(MathSqrtJS); |
352 %SetForceInlineFlag(MathTrunc); | 360 %SetForceInlineFlag(MathTrunc); |
353 | 361 |
354 // ------------------------------------------------------------------- | 362 // ------------------------------------------------------------------- |
355 // Exports | 363 // Exports |
356 | 364 |
357 utils.Export(function(to) { | 365 utils.Export(function(to) { |
358 to.MathAbs = MathAbs; | 366 to.MathAbs = MathAbs; |
359 to.MathExp = MathExp; | 367 to.MathExp = MathExp; |
360 to.MathFloor = MathFloorJS; | 368 to.MathFloor = MathFloorJS; |
| 369 to.IntRandom = MathRandomRaw; |
361 to.MathMax = MathMax; | 370 to.MathMax = MathMax; |
362 to.MathMin = MathMin; | 371 to.MathMin = MathMin; |
363 }); | 372 }); |
364 | 373 |
365 }) | 374 }) |
OLD | NEW |