You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On https://github.com/darach/jch-erl/blob/master/c_src/jch.c, a uint64_t (not necesarily unsigned long) seed is converted to double. An IEEE 754 floating point number only has 53-bit mantissa digits; dividing the seed is redundant and misleading (ULONG_MAX is also converted to an inaccurate 53-bit number).
An example of more efficient algorithm, using the higher 52 bits (discarding the lower 12 bits) of the 64-bit random unsigned integer to double precision floating point number is:
// uint_64 *x// Forced casting of a 64-bit unsigned integer to double// results in [1.0, 2.0) double numbersreturn ((double)((*x >> 12) | 0x3ff0000000000000LL) -1.0)
@jj1bdx I've changed unsigned long to uint64_t. I've left the PRNG as is for now as the overhead is dominated by the usual suspects, xorshift64* works well with the hash algorithm, and its fast enough for the use cases I have in mind. On the other hand, if you can make beam.smp process_main 5x faster I might have to revisit! ;)
On https://github.com/darach/jch-erl/blob/master/c_src/jch.c, a
uint64_t
(not necesarilyunsigned long
) seed is converted todouble
. An IEEE 754 floating point number only has 53-bit mantissa digits; dividing the seed is redundant and misleading (ULONG_MAX
is also converted to an inaccurate 53-bit number).An example of more efficient algorithm, using the higher 52 bits (discarding the lower 12 bits) of the 64-bit random unsigned integer to double precision floating point number is:
See http://en.wikipedia.org/wiki/Double-precision_floating-point_format for the details.
The text was updated successfully, but these errors were encountered: