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

Unified Diff: runtime/lib/math.cc

Issue 136453012: Fix http://dartbug.com/16111 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/bigint_operations.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/math.cc
===================================================================
--- runtime/lib/math.cc (revision 31849)
+++ runtime/lib/math.cc (working copy)
@@ -123,8 +123,23 @@
const TypedData& array = TypedData::Handle(GetRandomStateArray(receiver));
ASSERT(!seed_int.IsNull());
ASSERT(!array.IsNull());
- // TODO(srdjan): Reduce Bigint to 64 bit value.
- int64_t seed = seed_int.IsBigint() ? 0 : seed_int.AsInt64Value();
+ int64_t seed = 0;
+ if (seed_int.IsBigint()) {
+ const Bigint& mask64 = Bigint::Handle(
+ BigintOperations::NewFromUint64(0xffffffffffffffff));
+ Bigint& big_seed = Bigint::Handle();
+ big_seed ^= seed_int.raw();
+ Bigint& low64 = Bigint::Handle();
+ while (!big_seed.IsZero()) {
+ low64 = BigintOperations::BitAnd(big_seed, mask64);
+ ASSERT(BigintOperations::FitsIntoUint64(low64));
+ seed ^= BigintOperations::ToUint64(low64);
+ big_seed = BigintOperations::ShiftRight(big_seed, 64);
+ }
+ } else {
+ seed = seed_int.AsInt64Value();
+ }
+
do {
seed = seed + 0x5A17;
} while (seed == 0);
« no previous file with comments | « no previous file | runtime/vm/bigint_operations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698