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

Fix Random() for big-endian systems #987

Open
wants to merge 1 commit into
base: vanilla
Choose a base branch
from

Conversation

th-otto
Copy link
Contributor

@th-otto th-otto commented Mar 27, 2024

This might be not strictly needed, but fixes failures in tests/irandom

This might be not strictly needed, but fixes failures in tests/irandom
bytes[1] = (bytes[1] << 1) | cf1;
cf1 = (bytes[2] >> 7) & 1;
bytes[2] = (bytes[2] << 1) | cf2;
cf2 = (tmp_a - (RandNumb + (cf1 != 1))) & 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this on the second iteration change RandNumb's value and then change cf2 Can you please elaborate why it works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code treats the unsigned int RandNumb as a 4 byte array. So the endianness has to be taken into account (the comment already warns about this). The new code essentially does the same as the original code for big-endian systems.

Since this is supposed to generate random numbers, it does not make much difference at runtime, but the tests/irandom.cpp only works on little-endian systems.

Copy link
Collaborator

@giulianobelinassi giulianobelinassi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving since the testsuite accepts this .

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

Successfully merging this pull request may close these issues.

None yet

2 participants