TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

0x5f3759df and the fast inverse square root (2012)

125 pointsby carljosephover 10 years ago

8 comments

spiritplumberover 10 years ago
If anyone wants a fast atan2 that I wrote a while ago (2007), for making a microcontroller navigate, it&#x27;s at <a href="http:&#x2F;&#x2F;robots-everywhere.com&#x2F;portfolio&#x2F;math&#x2F;" rel="nofollow">http:&#x2F;&#x2F;robots-everywhere.com&#x2F;portfolio&#x2F;math&#x2F;</a>
评论 #8520373 未加载
评论 #8520503 未加载
thewarriorover 10 years ago
Tl;DR :<p>The fast inverse square root is based on the fact that the integer representation of a floating point number is a rough approximation of its logarithm.<p>So convert floating point to its integer representation. So now you have its approximate logarithm. Now take half of that and improve that with some Newton raphson.
评论 #8520362 未加载
评论 #8522532 未加载
simiasover 10 years ago
I&#x27;m really impressed by the generalization to other powers, including the regular square root. It&#x27;s the first time I&#x27;ve seen that hack (actually even the author mentions he found nothing on google). I think I could definitely have used that when I needed to compute square roots of fixedpoint numbers with no HW support, it looks very significantly faster than the iterative &quot;by digit&quot; method.
评论 #8520448 未加载
hbbioover 10 years ago
There is also a Wikipedia page for this:<p><a href="http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fast_inverse_square_root" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fast_inverse_square_root</a>
tempodoxover 10 years ago
And the moral of this story is: Never trust any floating-point number whose bits you haven&#x27;t polished yourself.
jokoonover 10 years ago
how does he adjust his σ value ?
agumonkeyover 10 years ago
Rarely I&#x27;m that amazed at encodings.
KhalilKover 10 years ago
I may be going on rampage here but &quot;<i>It does contain a fair bit of math</i>&quot; really grinds my gears!<p>Of course it does, it is about square roots and inversions.<p>In most of the cases, in order to optimize an algorithm or solve a problem, mathematics will do it for you, and that ranges from simple arithmetic properties to base changing theorems in linear algebra.<p>You just can not tackle such subjects without expecting it to <i>contain a fair bit of math</i> .
评论 #8519985 未加载
评论 #8520336 未加载
评论 #8519936 未加载