Last active
October 28, 2022 13:54
-
-
Save ogrisel/eb3073db349cdf6445f9631f4fc416d5 to your computer and use it in GitHub Desktop.
Thanks @smason!
float32(np.uint32(x >> uint32(32)) >> uint32(8)) * (float32(1) / float32(uint32(1) << uint32(24)))
seems to be better, it seems equivalent to casting an intermediate float64 to float32, without actually materializing the float64 !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not sure if it makes much difference, but I think your "smarter" version is preferred these days, i.e.:
the bottom of https://prng.di.unimi.it/ has some comments on some different definitions of uniformity that could apply here
I noticed that your twitter message said you wanted$[0..1]$ , so you might want a
-1
in there. Operator precedence is a bit annoying so it needs more brackets than you might expect:e.g. test with: