Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Binary logarithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Piecewise-linear approximation=== For a number <math>x</math> represented in [[floating point]] as <math>x=2^E(1+m)</math>, with integer exponent <math>E</math> and [[significand|mantissa]] <math>m</math> in the range <math>0\le m<1</math>, the binary logarithm can be roughly approximated as <math>\log_2 x\approx E+m</math>.<ref name=mitchell/> This approximation is exact at both ends of the range of mantissas but underestimates the logarithm in the middle of the range, reaching a maximum error of approximately 0.086 at a mantissa of approximately 0.44. It can be made more accurate by using a [[piecewise linear function]] of <math>m</math>,<ref>{{citation | last1 = Combet | first1 = M. | last2 = Van Zonneveld | first2 = H. | last3 = Verbeek | first3 = L. | date = December 1965 | doi = 10.1109/pgec.1965.264080 | issue = 6 | journal = IEEE Transactions on Electronic Computers | pages = 863β867 | title = Computation of the base two logarithm of binary numbers | volume = EC-14}}</ref> or more crudely by adding a constant correction term <math>\log_2 x\approx E+m+\sigma</math>. For instance choosing <math>\sigma\approx 0.043</math> would halve the maximum error. The [[fast inverse square root]] algorithm uses this idea, with a different correction term that can be inferred to be <math>\sigma\approx 0.0450466</math>, by directly manipulating the binary representation of <math>x</math> to multiply this approximate logarithm by <math>-\tfrac12</math>, obtaining a floating point value that approximates <math>1/\sqrt x</math>.<ref>{{citation |url=http://www.daxia.com/bibis/upload/406Fast_Inverse_Square_Root.pdf |title=The Mathematics Behind the Fast Inverse Square Root Function Code |last=McEniry |first=Charles |date=August 2007 |archive-url=https://web.archive.org/web/20150511044204/http://www.daxia.com/bibis/upload/406Fast_Inverse_Square_Root.pdf |archive-date=2015-05-11}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)