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

xNextInt: unnecessary if branch? #134

Open
arnaud-ma opened this issue Dec 27, 2024 · 0 comments
Open

xNextInt: unnecessary if branch? #134

arnaud-ma opened this issue Dec 27, 2024 · 0 comments

Comments

@arnaud-ma
Copy link

Here:

cubiomes/rng.h

Lines 214 to 225 in e61f905

static inline int xNextInt(Xoroshiro *xr, uint32_t n)
{
uint64_t r = (xNextLong(xr) & 0xFFFFFFFF) * n;
if ((uint32_t)r < n)
{
while ((uint32_t)r < (~n + 1) % n)
{
r = (xNextLong(xr) & 0xFFFFFFFF) * n;
}
}
return r >> 32;
}

The condition ((uint32_t)r < (~n + 1) % n) will never be true because (~n + 1) % n simplifies to 0 for any value of n.

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