| 377 | #define scaleFIG (l_mathop(0.5) / ((Rand64)1 << (FIGS - 1))) |
| 378 | |
| 379 | static lua_Number I2d (Rand64 x) { |
| 380 | SRand64 sx = (SRand64)(trim64(x) >> shift64_FIG); |
| 381 | lua_Number res = (lua_Number)(sx) * scaleFIG; |
| 382 | if (sx < 0) |
| 383 | res += l_mathop(1.0); /* correct the two's complement if negative */ |
| 384 | lua_assert(0 <= res && res < 1); |
| 385 | return res; |
| 386 | } |
| 387 | |
| 388 | /* convert a 'Rand64' to a 'lua_Unsigned' */ |
| 389 | #define I2UInt(x) ((lua_Unsigned)trim64(x)) |