Date: 2022-04-21 10:33 (UTC)
fanf: (Default)
From: [personal profile] fanf

Both algorithms immediately return 0 in the limit == 0 case because their slow path guards check for something less than the limit, which is never the case for unsigned comparison with 0 :-)

I was recently reminded of this for the nearly-divisionless algorithm when I was using it to replace some code that uses two divisions per random number. The two-division code had an early check for limit < 2, which made me double-check the nearly-divisionless code, and I was pleased that the limit < 2 check could be completely deleted. (And I added a comment noting what happens in the limit == 0 case.)

This account has disabled anonymous posting.
(will be screened if not on Access List)
(will be screened if not on Access List)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

June 2025

S M T W T F S
1234567
8 91011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated 2025-06-17 00:13
Powered by Dreamwidth Studios