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

RNG-81: NumberFactory to sample all rationals between 0 and 1. #29

Merged
merged 1 commit into from Mar 19, 2019

Conversation

aherbert
Copy link
Contributor

@aherbert aherbert commented Mar 6, 2019

This changes the nextFloat/nextDouble methods to use an extra bit of
state from the underlying int or long primitive.

@coveralls
Copy link

coveralls commented Mar 7, 2019

Coverage Status

Coverage remained the same at 98.223% when pulling 647326a on aherbert:improvement-RNG-81 into 3288206 on apache:master.

Copy link
Member

@grimreaper grimreaper left a comment

Choose a reason for hiding this comment

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

Overall seems reasonable to me

Assert.assertEquals(0, (noBits >>> 9) * 0x1.0p-23f, 0);
Assert.assertEquals(0, (noBits >>> 8) * 0x1.0p-24f, 0);
Assert.assertEquals(0, Float.intBitsToFloat(0x7f << 23 | noBits >>> 9) - 1.0f, 0);
Assert.assertEquals(0f, (noBits >>> 9) * 0x1.0p-23f, 0);
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: if you're changing the first argument anyways use the canonical form

Suggested change
Assert.assertEquals(0f, (noBits >>> 9) * 0x1.0p-23f, 0);
Assert.assertEquals(0.0f, (noBits >>> 9) * 0x1.0p-23f, 0);

Assert.assertEquals(0, (noBits >>> 8) * 0x1.0p-24f, 0);
Assert.assertEquals(0, Float.intBitsToFloat(0x7f << 23 | noBits >>> 9) - 1.0f, 0);
Assert.assertEquals(0f, (noBits >>> 9) * 0x1.0p-23f, 0);
Assert.assertEquals(0f, (noBits >>> 8) * 0x1.0p-24f, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Assert.assertEquals(0f, (noBits >>> 8) * 0x1.0p-24f, 0);
Assert.assertEquals(0.0f, (noBits >>> 8) * 0x1.0p-24f, 0);

Assert.assertEquals(0, Float.intBitsToFloat(0x7f << 23 | noBits >>> 9) - 1.0f, 0);
Assert.assertEquals(0f, (noBits >>> 9) * 0x1.0p-23f, 0);
Assert.assertEquals(0f, (noBits >>> 8) * 0x1.0p-24f, 0);
Assert.assertEquals(0f, Float.intBitsToFloat(0x7f << 23 | noBits >>> 9) - 1.0f, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Assert.assertEquals(0f, Float.intBitsToFloat(0x7f << 23 | noBits >>> 9) - 1.0f, 0);
Assert.assertEquals(0.0f, Float.intBitsToFloat(0x7f << 23 | noBits >>> 9) - 1.0f, 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed all 0f with 0.0f. Thanks.

This changes the nextFloat/nextDouble methods to use an extra bit of
state from the underlying int or long primitive.
@asfgit asfgit merged commit 647326a into apache:master Mar 19, 2019
asfgit pushed a commit that referenced this pull request Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants