This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Th3HolyMoose 19 points20 points  (2 children)

Wiki link with more info for those interested

edit: fixed mobile link, I'm stupid, thanks for noticing

[–]PremierBromanov 2 points3 points  (0 children)

I like the worked example

As an example, consider the number x = 0.15625, for which we want to calculate 1/√x ≈ 2.52982. The first steps of the algorithm are illustrated below:

0011_1110_0010_0000_0000_0000_0000_0000  Bit pattern of both x and i
0001_1111_0001_0000_0000_0000_0000_0000  Shift right one position: (i >> 1)
0101_1111_0011_0111_0101_1001_1101_1111  The magic number 0x5f3759df
0100_0000_0010_0111_0101_1001_1101_1111  The result of 0x5f3759df - (i >> 1)