Re:Fast Inverse Square Root
by recursive on Monday November 02, 2020 @05:49PM
(#24974395)
Thanks for this. I have one nit. You show `q = 1598029824 - u/2;` as being identical to `q = 0x5F400000 - u >> 1;`, but every language I know of uses a different order of operations, giving different results. It might be clearest to provide parentheses in the second case.
[ Parent
| on HN ]
Interestingly enough it seems to do the shift first in Swift
All well-known programming languages will do the shift first.
Re:Fast Inverse Square Root
by thehobgoblin on Monday November 02, 2020 @10:24PM
(#24976003)
I looked at about 20 different "popular" languages and I believe that only 2 (Go and Swift) of them have shifts at a higher precedence than addition.
I think I'm missing a reference/joke =/
Or this might just be another confident but baseless HN commenter assertion.
Re:Fast Inverse Square Root
by copascetic on Tuesday November 03, 2020 @01:13AM
(#24976871)
C, C++, Java, and Rust all have shift as lower precedence than addition/subtraction. Edit: and Javascript, Python.
You can add C# as well.
Re:Fast Inverse Square Root
by beached_whale on Monday November 02, 2020 @10:04PM
(#24975923)
Use brackets to be explicit about your expected order of operations.