fast square root fast square root referred fast constant method calculating square root bit floating point number floating point format probably developed early 1990s implementation appeared iii arena source code method appear public forums discussion chinese developer forum time primary advantage came avoiding expensive floating point operations favor operations square roots angles reflection lighting computer graphics accepts bit floating point number input stores value later use treating bits representing floating point number bit logical shift right bit performed result magic number square root input treating bits floating point runs iteration newton method return precise square root floating point number approximately times faster floating point division originally attributed investigation showed code deeper roots hardware software computer graphics adjustments alterations passed interactive implementation earliest known use known constant originally derived investigation shed light possible methods motivation square root floating point number calculating normalized graphics program uses normalized determine lighting reflection millions calculations second creation specialized hardware handle transform lighting software slow specifically code developed early 1990s floating point processing power speed processing length determined calculating norm square root sum squares components component divided length new unit pointing direction formula norm analogous calculation distance points space formula normalized unit formula represent formula formula relates unit square root distance components iii arena fast square root speed graphics processing unit implemented dedicated hardware field gate overview code following code fast square root implementation stripped including exact original comment text order determine square root formula determined software numerical method revise came acceptable error range actual result common software methods early 1990s drew table bit code proved faster table approximately times faster regular floating point division loss precision occurred offset significant gains performance designed bit floating point specification mind investigation later showed implemented floating point specifications advantages speed offered fast square root came treating containing floating point number specific constant purpose constant immediately clear viewing code like found code called magic number bit shift results treated floating point number rough square root input number iteration newton method performed gain accuracy code finished generates reasonably accurate results unique newton method slower accurate instruction released worked example example consider number want steps illustrated bit pattern shift right position magic number result bit representation bit pattern floating point number gives error single iteration newton method final result error working performing following steps alias argument way use alias float way single iteration newton method floating point representation relies heavily bit level representation single precision floating point numbers short overview representation provided order non zero real number single precision float step write normalized number formula representation noted single bit point need stored form unsigned sign bit bit biased bias bits bits fields packed left right bit container example consider number yields formula unsigned fields fields packed shown figure approximate computer table useful identity valid base fast square root based identity fact gives rough positive normal number formula formula right hand formula free tune example yields exact results ends interval yields optimal best sense uniform norm error formula hand interpreting bit pattern yields formula appears scaled shifted linear illustrated figure right words formula result calculation based identity formula applied equation gives formula formula written code term magic number formula second term calculated shifting bits position right newton method performing operations treats floating point number float performs floating point operation floating point operation represents single iteration newton method finding roots given equation example formula square root function formula formula represents general expression newton method formula formula expression formula formula formula generated operations input lines function repeated output function formula input iteration cause converge root increasing precision purposes iii engine iteration second iteration remained code commented accuracy noted surprisingly accurate right plots error function error improved running iteration newton method starting standard library gives result gives making difference absolute error drops relative error stays bounds orders magnitude history investigation source code iii released copies fast square root code appeared forums early initial speculation pointed probable author code suggested written accomplished assembly programmer previously helped software written implementation similar bit code late 1990s original authors proved history computer graphics implementation possible earliest known use concluded original devised consultation creator learned trick code written berkeley comment section end code demonstrated simple square root column known precisely exact value magic number determined developed function minimize error choosing magic number range optimal constant linear step close new constant gave slightly accuracy iteration newton method searched constant optimal newton found accurate original iteration stage concluded asking exact value original constant chosen trial error pointed magic number bit size type double later shown exactly performed similar sophisticated likely values initial force search resulted constant determined attempted find constant weighted specific value function occurred leading believe constant originally derived given tolerance documents jim july floating point tricks jim corner isbn david game engine design isbn john 2nd san_francisco isbn david august spectrum chris february fast square root retrieved charles august mathematics fast square root function code retrieved george june embedded embedded system design topics techniques trends working conference international embedded systems california isbn jason december fast square root reilly media archived original retrieved
Fast inverse square root