[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Doom

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 10
Thread images: 3

In layman terms, how does this black magic work?
>>
>>58690993
https://en.wikipedia.org/wiki/Fast_inverse_square_root#Algorithm
>>
>>58690993

The goal of this function is to do hit detection so it's got to be optimized to hell because that's a classically computationally intense process.

The obvious hit detection method is to go though and check every combination of objects for hits by their distance from each other. To do this you would need to use the distance formula, which uses square roots.

While not completely accurate, inverse square root is close enough to square root to be used to estimate what objects definitely aren't touching while being way faster. From this graph notice how terrible calculating a square root is.

newton's method is used to numerically estimate a function from its derivative. This method requires an initial guess (one of the constants) and is iterative (the blacked out line). I'm pretty sure that's what the C standard library already does to calculate square roots, they just use however many iterations are required to get a sure answer. This just uses only one iteration.

It's actually a common optimization. Read about it in "art of computer programming: bitwise tricks" and "hacker's delight", the second of which actually mentions inverse square root by name

oh yeah, and also remember that floating point = scientific notation so they use that fact to their advantage
>>
>>58690993
It doesn't. It's undefined behavior
>>
>>58691450
>From this graph notice how terrible calculating a square root is

ummmmmmmmm
>>
>doom
>>
>>58691450
Senpai, it just shows the different degrees of complexity, not the complexity of the algorithm required to calculate the square root.
>>
File: 1482119175326.png (312KB, 2002x936px) Image search: [Google]
1482119175326.png
312KB, 2002x936px
>>58694561
>pic
>>
>>58691450
>From this graph notice how terrible calculating a square root is.

Posts like these make me paranoid. The rest of your post would make me think you knew what you were talking about.
>>
why is fuck censored in that image?

Also, this hasn't been a real optimization since SSE came into existence, since it has a fast aproximate inverse square root instruction.

>>58691726
What's undefined about that? strict aliasing was only added in C99
Thread posts: 10
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

If you need a post removed click on it's [Report] button and follow the instruction.
If you like this website please support us by donating with Bitcoin at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties. Posts and uploaded images are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that website. If you need information about a Poster - contact 4chan. This project is not affiliated in any way with 4chan.