4 ms·
Yeah, I'm pretty sure this isn't the same kind of thing as Carmack's (edit: not Carmack's) legendary inverse square root function [1], which has that 0x5F3759DF
by humanistbot 4y ago
Yeah, I'm pretty sure this isn't the same kind of thing as Carmack's (edit: not Carmack's) legendary inverse square root function [1], which has that 0x5F3759DF constant (edit: magic number):
[1] https://en.wikipedia.org/wiki/Fast_inverse_square_root https://en.wikipedia.org/wiki/Fast_inverse_square_root
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number \* 0.5F;
y = number;
i = \* ( long \* ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = \* ( float \* ) &i;
y = y \* ( threehalfs - ( x2 \* y \* y ) ); // 1st iteration
// y = y \* ( threehalfs - ( x2 \* y \* y ) ); // 2nd iteration, this can be removed
return y;
}
- secondcoming 4y agoWhat has this got to do with seeding a RNG?
- allan_s 4y agoI think the comment author meant "a magical constant that has been found by someone by empirical method without a nice paper pointing why it's a good value" (even though I think now the constant above has a paper on why it's actually so good)
- humanistbot 4y agoThis was an example of a seemingly random magic number appearing in code for a very clever hack. I think the OP was assuming there was something similar at work with the PRNG magic numbers.
- silisili 4y agoNot Carmack's, it says so in the link you provided. > The algorithm was originally attributed to John Carmack, but an investigation showed that the code had deeper roots in the hardware and software side of computer graphics. Adjustments and alterations passed through both Silicon Graphics and 3dfx Interactive, with the original constant being derived in a collaboration between Cleve Moler and Gregory Walsh, while Gregory worked for Ardent Computing in the late 1980s.[3] Walsh and Moler adapted their version from an unpublished paper by William Kahan and K.C. Ng circulated in May 1986.