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

Unified Diff: src/math.js

Issue 82763005: Reland "Implement Math.random() purely in JavaScript" plus fixes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added assertion Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ia32/lithium-ia32.cc ('k') | src/mips/full-codegen-mips.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/math.js
diff --git a/src/math.js b/src/math.js
index c163d9a46fd2590e3e9bf71cb8e009b1c732b205..fb7d30694e48781b80eca7f95748527b1bcbce63 100644
--- a/src/math.js
+++ b/src/math.js
@@ -169,8 +169,15 @@ function MathPow(x, y) {
}
// ECMA 262 - 15.8.2.14
+var rngstate; // Initialized to a Uint32Array during genesis.
function MathRandom() {
- return %_RandomHeapNumber();
+ var r0 = (MathImul(18273, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0;
+ rngstate[0] = r0;
+ var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16)) | 0;
+ rngstate[1] = r1;
+ var x = ((r0 << 16) + (r1 & 0xFFFF)) | 0;
+ // Division by 0x100000000 through multiplication by reciprocal.
+ return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10;
}
// ECMA 262 - 15.8.2.15
« no previous file with comments | « src/ia32/lithium-ia32.cc ('k') | src/mips/full-codegen-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698