Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_multiplication32 seems to be broken... #1

Open
patniemeyer opened this issue Mar 9, 2022 · 2 comments
Open

_multiplication32 seems to be broken... #1

patniemeyer opened this issue Mar 9, 2022 · 2 comments

Comments

@patniemeyer
Copy link

and this lib is not matching others. I'm looking into a fix.

@patniemeyer
Copy link
Author

_unsigned32 can now be:
return n1.toUnsigned(32);
and if the operands of _multiplication32() are always positive 32 bit integers it seems like:
return (n1 * n2) & 0xFFFFFFFFFF is correct? (64 bit overflow in dart truncated down to 32 bits). This matches another implementation I'm trying to sync up with.

@patniemeyer
Copy link
Author

patniemeyer commented Mar 10, 2022

Actually, that will fail on Dart for web which doesn't have true 64 bit ints. The following emulates what the JS Mersenne Twister impl does and produces output consistent with it on native and web:

    assert(n1 < 4294967296);
    assert(n2 < 4294967296);
    return (((_unsigned32((n1 & 0xffff0000) >> 16) * n2) << 16) + (n1 & 0x0000ffff) * n2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant