From a90a9c8e1bb250f3096df14dc1c47b842bc44e4d Mon Sep 17 00:00:00 2001 From: Zolisa Bleki <44142765+zoj613@users.noreply.github.com> Date: Tue, 21 Jun 2022 21:26:33 +0200 Subject: [PATCH] MAINT: Get full precision for 32 bit floating point random values. The formula to convert a 32 bit random integer to a random float32, (((rng)->next_uint32((rng)->state) >> 9) * (1.0f / 8388608.0f)) shifts by one bit too many, resulting in uniform float32 samples always having a 0 in the least significant bit. The formula is corrected to (((rng)->next_uint32((rng)->state) >> 8) * (1.0f / 16777216.0f)) See https://github.com/numpy/numpy/pull/20314 for more details. --- src/pgm_macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pgm_macros.h b/src/pgm_macros.h index 75a51ef..b7017ea 100644 --- a/src/pgm_macros.h +++ b/src/pgm_macros.h @@ -52,7 +52,7 @@ * adapted from a private function of a similar name */ #define next_float(rng) \ - (((rng)->next_uint32((rng)->state) >> 9) * (1.0f / 8388608.0f)) + (((rng)->next_uint32((rng)->state) >> 8) * (1.0f / 16777216.0f)) /* * Generate a random double precision float in the range [0, 1). This macros is