3 ms·
If you just keep the higher 64 bits, what kind of sense does it make ? We're talking about integer here, not float. At least, keeping the lower 64 bits is the
by littlestymaar 9y ago
If you just keep the higher 64 bits, what kind of sense does it make ? We're talking about integer here, not float.
At least, keeping the lower 64 bits is the usual overflow behavior and if the result of the multiplication fits in 64 bits it just works fine.
- barrkel 9y agoThere are cases for keeping just the high bits. For example, many language runtime libraries have pseudo random number generators (PRNGs) use a 32-bit linear congruential generator (LCG). Suppose you want to create a rand(n) function which returns an integer between 0 and n-1. One good way of doing this is multiplying the lcg_output (a 32-bit unsigned integer) by n, and returning the high 32 bits. It's better to do this than a modulus operation because the low bits on LCG sequences are highly predictable. (This is how the Delphi Random(n) function works.)