Chris Lomont
lomont.org · Personal blog · on HN since 2007
Chris Lomont, a physicist and programmer, writes technical papers on numerical methods, math in everyday devices, and software oddities.
What HN saysHN commenters point to his paper on the fast inverse square root as the best explanation of the magic constant 0x5f3759df and its history.
20HN people shared it
13linked it in comments
7stories submitted
15story points
3 months agolast shared
2007people per year2026
Most-shared posts
- 1Fast Inverse Square Root (2003) [pdf]10 people · 6 points · first shared 2008 · 1 comments on HN
- 2Accurate int/float colour conversions1 people · 2 points · first shared 2026 · discussion on HN
- 3Fast Inverse Square Root [pdf]1 people · 2 points · first shared 2020 · discussion on HN
- 4The Excel Bug Disassembled [pdf]1 people · 2 points · first shared 2007 · discussion on HN
- 5How much Math is there in an iPhone?1 people · 2 points · first shared 2011 · discussion on HN
- 6Efficient Divisibility Testing (2017)1 people · 1 points · first shared 2025 · 1 comments on HN
- 7Excel2007Bug.pdf1 people · first shared 2023
- 8SpaceTimeTalk.pdf1 people · first shared 2020
- 9CompareFloat.pdf1 people · first shared 2026
- 10Robotron1 people · first shared 2021
- 11Fractran1 people · first shared 2024
- 12Robotron1 people · first shared 2017
What HN people wrote when they linked it
lscharen · 2018-03-25
I always thought of this bit of code as a great example of applied numerical methods techniques, rather than “Black Magic” The magic constant is derivable from standard methods and one can even choose to optimize other measures of error.
http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
lvoudour · 2017-08-16
I first saw the code in the early 2000's and although I figured out the newton-rapshon part I couldn't wrap my head around the magic number, until I read chris Lomont's famous paper[1]. A little gem which reminds us that not that long ago computing resources were a limited commodity.
Abundance is great and speeds up development time, but unfortunately it leads to laziness and bloat
[1] http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
koz1000 · 2017-01-30
Want to know the best part? Nearly all of those signature sounds were generated algorithmically by the processor on the sound board.
The main program would feed some values into a series of feedback loops and shifts to generate the waves before pushing them out the DAC. Game programmers would just play around with various vectors until they found something that sounded interesting.
The whole shebang ran in 2KiB of ROM firmware and 128 bytes of RAM. At 894 kilohertz.
This dude reverse engineered the 6802 code and translated it to C#. Pretty amazing:
http://www.lomont.org/Software/Misc/Robotron/
Next time on our show we'll talk about the magic of palette cycling. Jarvis still uses this on his games to this very day. Kind of his signature now, right?
sandGorgon · 2009-10-22
I think the best paper that explains the magic number (0x5f3759df) is http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
Lomont traces the history of the algorithm and the possible way that the magic number was derived - including more magic numbers (0x5f375a86)
ChrisLomont · 2020-08-27
>>time dialation (something completely alien to all before him
>Hendrik Lorentz prop
Lorentz did not think that time actually dilated; his notion of "local time" he considered purely a mathematical trick, unrelated to actual physics, in the same manner that renormalization sweeps away infinities in a clever manner.
Here's the quote: "While for Lorentz length contraction was a real physical effect, he considered the time transformation only as a heuristic working hypothesis and a mathematical stipulation to simplify the calculation from the resting to a "fictitious" moving system. " [1]
So no, Lorentz absolutely did not think physical time actually dilated. Stop repeating this nonsense.
Also, Lorentz was not the first to publish the time dilation formula. And, like Lorentz, all before him thought it a neat mathematical trick, devoid of actual physics.
Poincare did think it may be actual time dilation, but he too lacked the insights that Einstein had that put these dilation and stretching concepts not as ad-hoc after effects, but that they come from a simple, single physical principle. What's more, Einstein's way of looking at it all was the one that turned out to match reality the best.
For example, in 1905 Poincare introduced "Poincare stresses", another fictitious set of forces, to reconcile the math they didn't like from what they thought of as reality.
Lorentz and Poincare used the now-disproven aether as the basis for their theories. Einstein did not.
Spend a…
Jach · 2012-01-12
Hey, you finally made the leap to HN! Did you independently discover a lot of these things yourself or did you come across parts in books/papers? For me the canonical example of deriving magic numbers is with the fast inverse square root trick (my favorite paper on it is http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf ) but I haven't seen many other instances... I haven't gone nearly far enough yet but I like getting pointed suggestions.
There were some recent submissions here about related topics like space-filling curves and secret sharing that I've looked at before. When I started looking into abstract algebra and came across finite fields I sort of laughed at the Wikipedia page mentioning right at the beginning "Finite fields are important in number theory, algebraic geometry, Galois theory, cryptography, coding theory and Quantum error correction" with each topic being linked. It's a fun way to procrastinate.
If your engine isn't part of some secret sauce I think it would be neat to study it. Unless you know of an already existing open source equivalent that's not hidden away in the corners of something like GCC?
SideQuark · 2026-04-18
Completely worked out at least 20 years ago: https://www.lomont.org/papers/2005/CompareFloat.pdf
mlnhd · 2023-06-17
Here is a nice white paper about a previous Excel 2007 bug, where a calculation that should result in 65535 is displayed as 100,000. The author concludes that since the patch only alters a few lines of assembly, that it was hand-coded.
http://lomont.org/papers/2007/excel-2007-bug/Excel2007Bug.pdf
msarnoff · 2021-07-13
Thank you, that's awesome!
I never published my reverse engineering work, but I think you're referring to http://lomont.org/software/misc/robotron/
achille · 2011-10-15
Also see:
http://en.wikipedia.org/wiki/Fast_inverse_square_root
And for more analysis and improvements see those papers:
http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
http://www.daxia.com/bibis/upload/406Fast_Inverse_Square_Root.pdf
http://www.geometrictools.com/Documentation/FastInverseSqrt.pdf
hyperbovine · 2009-11-18
If, like me, you were left hoping for some explanation of the actual magic behind this code, try this: http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
gcv · 2009-01-04
According to this article, neither of them: http://www.beyond3d.com/content/articles/8/
That article also links to a paper (http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf) analyzing the initial approximation constant.
dangoldin · 2008-06-09