| 349 | #define scaleFIG (l_mathop(0.5) / ((Rand64)1 << (FIGS - 1))) |
| 350 | |
| 351 | static lua_Number I2d (Rand64 x) { |
| 352 | SRand64 sx = (SRand64)(trim64(x) >> shift64_FIG); |
| 353 | lua_Number res = (lua_Number)(sx) * scaleFIG; |
| 354 | if (sx < 0) |
| 355 | res += l_mathop(1.0); /* correct the two's complement if negative */ |
| 356 | lua_assert(0 <= res && res < 1); |
| 357 | return res; |
| 358 | } |
| 359 | |
| 360 | /* convert a 'Rand64' to a 'lua_Unsigned' */ |
| 361 | #define I2UInt(x) ((lua_Unsigned)trim64(x)) |