4 ms·
This is the core trick in the Fast Inverse Square Root[0], as made famous by the Quake III source code. It uses a shift (equivalent to dividing) and a subtrac
by sethaurus 2y ago
This is the core trick in the Fast Inverse Square Root[0], as made famous by the Quake III source code.
It uses a shift (equivalent to dividing) and a subtraction in integer-land to estimate x^(-0.5) in float-land.
[0]: https://en.m.wikipedia.org/wiki/Fast_inverse_square_root https://en.m.wikipedia.org/wiki/Fast_inverse_square_root
- Timwi 2y agoI've always hated that it's called an “inverse”. It's not an inverse. The inverse of square root is square. If they had called it “reciprocal”, it would have been clear to me what it does, but “inverse” confused the hell out of me when I first saw it.
- deleted 2y ago[deleted]
- Someone 2y agoIt’s confusing for non-mathematicians, but (and you may know that) it is not incorrect. https://en.wikipedia.org/wiki/Inverse_element https://en.wikipedia.org/wiki/Inverse_element: “In mathematics, the concept of an inverse element generalises the concepts of opposite (−x) and reciprocal (1/x) of numbers.”
- bmacho 2y agoNo, it's confusing for mathematicians because it is directly opposing math terminology. (Which is okay, but confusing.)
- Grimblewald 2y agoIt doesnt though, inverse strictly speaking means the multiplicative inverse. The idea was extended in inverse functions eventually which for sake of brevity we also call the inverse. Now f^{-1}(x) and f(x)^{-1} are clearly different beasts the first would describe the square (for square root) while the second describes what quake was doing. Wether you call something an inverse or its full name (multiplicative/functional - inverse) depends on if its unclear from context which was meant.
- throwawaymaths 2y agothe function inverse is the multiplicative inverse in the group of automorphisms over sets (when the multiplication operation is functional composition).
- cluckindan 2y agoFound the Haskell guy.
- throwawaymaths 2y agoim so anti-haskell, your comment pained me to hear
- Grimblewald 2y agoI think it's clear we both know that but for the sake of the commenter arguing the two things are different, it's does not help to simply say they the same without giving example, no?
- throwawaymaths 2y agoyou misunderstand my intent, sorry! i was boosting your point, not arguing against it. please insert the word "yep," in front of my parent comment
- disconcision 2y agoi think this is just typical natural language ambiguity: "Inverse Square root" is used to mean "(Multiplicative) Inverse (of the) Square root" as opposed to "(Square root) Inverse"
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- seeknotfind 2y agoRight, the bang per syllable loss is it's ambiguous, not that it's incorrect. Inverse square root could also mean -(x^0.5) if it meant the additive inverse, and it could mean x^2 if it meant the functional inverse, as said here.
- manojlds 2y agoThe inverse is about the negative power right? Square root is the 0.5
- vrighter 2y ago"inverse" has a very specific meaning: inverse(x) * x = 1 x^2 * x != 1 for any x other than 1. So no, x^2 is not the inverse of sqrt(x)
- tczMUFlmoNk 2y agoBut sqrt · square = 1, where "sqrt: R⁺ → R⁺" is the square root operation, "square: R⁺ → R⁺" is the squaring operation, "1: R⁺ → R⁺" is the identity operation, and (·) is function composition: i.e., working in the monoid of functions R⁺ → R⁺. So x² and sqrt(x), as elements of R, are not inverses, but sqrt and square, as elements of R⁺ → R⁺, are. It depends on how you parse the phrase "fast inverse square root".
- xigoi 2y agoThis is true, but interpreting it one way is clearly absurd (nobody would call a square the “inverse square root”), which implicates that the other meaning was intended.
- quietbritishjim 2y agoNo. "inverse" has a very specific meaning: the operation that undoes whatever operation you're talking about. https://en.m.wikipedia.org/wiki/Inverse_function https://en.m.wikipedia.org/wiki/Inverse_function The inverse of multiplying by 3 is dividing by 3, and vice-versa. The inverse of squaring is squart root, and vice-versa. The inverse of a number or other element (rather than an operation / function) means whatever number would form the inverse if you use it with whatever binary operation you're talking about. So the additive inverse of 3 is –3, the inverse of "rotate clockwise 90 degrees" in the group of geometric operations is "rotate anticlockwise 90 degrees", and the multiplicative inverse of 3 is 1/3. Saying "the inverse of 3" to mean 1/3, i.e. its multiplicative inverse, is sloppy but acceptable so long as everyone knows what you mean (and it's fairly common). Saying "the inverse square root" to mean 1/square root is just wrong.
- sunk1st 2y agoIs it acceptable to use the imperative? That is, to say: “Now, invert the element”. Or should it always be, “take the inverse of …”?
- bee_rider 2y agoInterestingly Intel got it right, thus the rsqrt family of instructions.
- empath75 2y agoSince calling the square an inverse square root makes zero sense in any practical context, the other common meaning being applied is obvious. In this case, it's not the inverse of a _function_, it's the inverse of a _number_, which is usually considered to be the same as the reciprocal.
- throwawaymaths 2y agoas a mathematician: its fine. the word "multiplicative" is just silent in the phrase.