File:Log by aliasing to int.svg
![File:Log by aliasing to int.svg](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Log_by_aliasing_to_int.svg/640px-Log_by_aliasing_to_int.svg.png?20140725112048)
Original file (SVG file, nominally 640 × 480 pixels, file size: 13 KB)
Captions
Captions
Summary
[edit]DescriptionLog by aliasing to int.svg |
English: Aliasing a positive IEEE-754 floating point number x to an integer Ix (like in C: float x = ...; int32_t i = * (int32_t *) &x; ) yields a scaled and shifted approximation of its base-2 logarithm. This is the basis of the fast inverse square root algorithm.Français : Si un nombre positif x représenté en virgule flottante au format IEEE 754 est interprété comme un entier Ix (comme en C : float x = ...; int32_t i = * (int32_t *) &x; ) cela produit, à une transformation linéaire près, une approximation de son logarithme en base 2. Cette approximation est le fondement de l'algorithme de racine carrée inverse rapide. |
Date | |
Source | Own work |
Author | Edgar Bonet |
Gnuplot source
[edit]Warning: This source contains non-ASCII characters in label 3, in the title of the first curve and in comments.
#!/usr/bin/gnuplot
# Aliasing a float32 to an int32 yields an approximation of its base-2
# logarithm.
# Parameters for IEEE-754 single-precision floats
L = 2**23 # mantissa scaling factor
B = 127 # exponent bias
# For m ∈ [0, 1), log₂(1 + m) ≈ 1 + σ
sigma = 0.0430357
# Assume x is a positive normal float32.
# Compute I(x): the int32 aliased to x.
log_of_2 = log(2)
log2(x) = log(x) / log_of_2
round(x) = floor(x + 0.5)
e(x) = floor(log2(x)) # exponent
m(x, e_x) = x / 2**e_x - 1 # mantissa, without the leading 1
M(x, e_x) = round(m(x, e_x) * L) # scaled and rounded mantissa
I2(x, e_x) = (e_x + B) * L + M(x, e_x)
I(x) = I2(x, e(x))
# Best fit to a logarithm
scaled_log(x) = L * log2(x) + L * (B - sigma)
# Do the plot
set terminal svg size 640, 480 enhanced
set output 'Log_by_aliasing_to_int.svg'
set xrange [0:10]
set yrange [0x3d800000:]
set format y "0x%x"
set ytics L
set key top left Left reverse invert spacing 1.4
set samples 200
set style line 1 lw 3 lc rgb "gray80"
set style line 2 lw 1 lc rgb "blue"
set style increment user
set label 1 "L = 2^{23}" at 6, 0x3fc00000
set label 2 "B = 127" at 6, 0x3f600000
set label 3 "σ = 0.0430357" at 6, 0x3f000000
plot scaled_log(x) title "L log_2(x) + L (B − σ)", \
I(x) title 'I_x' lt 3
Licensing
[edit]![w:en:Creative Commons](https://upload.wikimedia.org/wikipedia/commons/thumb/7/79/CC_some_rights_reserved.svg/90px-CC_some_rights_reserved.svg.png)
![attribution](https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Cc-by_new_white.svg/24px-Cc-by_new_white.svg.png)
![share alike](https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Cc-sa_white.svg/24px-Cc-sa_white.svg.png)
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 11:20, 25 July 2014 | ![]() | 640 × 480 (13 KB) | Edgar.bonet (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
File usage on other wikis
The following other wikis use this file:
- Usage on bn.wikipedia.org
- Usage on en.wikipedia.org
- Usage on fr.wikipedia.org
- Usage on fr.wikibooks.org
- Usage on ko.wikipedia.org
- Usage on pl.wikipedia.org
- Usage on uk.wikipedia.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Image title | Produced by GNUPLOT 4.4 patchlevel 3 |
---|---|
Width | 640 |
Height | 480 |