evil floating point bit level hacking - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: evil floating point bit level hacking (/thread-4994.html) |
evil floating point bit level hacking - Thomas Klemm - 10-22-2015 07:45 PM There's this fast inverse square root method that is often used in 3D graphics programs to calculate a normalized vector: Code: float Q_rsqrt( float number ) While it's not precisely known how the magic number 0x5f3759df was determined the idea of the algorithm appears already in a drafted paper by Prof W. Kahan and K.C. Ng, written in May, 1986: Quote:B. sqrt(x) by Reciproot Iteration-- sqrt implementation in fdlibm Since Kahan was the primary architect behind the IEEE 754-1985 standard for floating-point computation I wonder whether he already had that trick in mind when defining their representation: Though the HP-71B was the first handheld to implement the IEEE floating-point standard I doubt that this trick could be used. Since it was also HP's first calculator based on the Saturn processor the floating point numbers are BCD-formatted coded. But then the approximation \(\log(1+x)\approx x\) can't be used since \(x\) isn't \(\ll 1\). Cheers Thomas RE: evil floating point bit level hacking - Han - 10-22-2015 09:29 PM As the "father of floating point," Kahan discovering this trick would not surprise me "one bit" |