[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]

>your code will never stump john carmack why even live bros?

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: 49
Thread images: 4

File: quickinversesquare.png (18KB, 764x269px) Image search: [Google]
quickinversesquare.png
18KB, 764x269px
>your code will never stump john carmack
why even live bros?
>>
>>60645656
oh I'm sure my code raises a few WTFs
>>
>>60645656
>posting code not written by carmack
>>
>>60645656
don't worry, most developers are retards and still manage to earn a shitton of money anyway
>>
>>60645656
So how does it work anyway?
>>
>>60645709
t. author of the code 1 year later
>>
>>60645709
if john carmack cant even explain how the code in his game works, what shot do I have?
>>
>>60645709
https://en.wikipedia.org/wiki/Fast_inverse_square_root
>>
File: all_sgi.jpg (201KB, 1000x669px) Image search: [Google]
all_sgi.jpg
201KB, 1000x669px
>>60645656
This was actually invented at SGI.
Damn, what a shame they went under.
>>
Just get some knowledge of the business process and make sure to NEVER comment and they can't fire you ;)
>>
>>60645757
Underrated comment
>>
>>60645709
It does memory level hacking to shift bits around which simulates division and then exploits a hexadecimal constant in C to do something...
>>
Exactly what about this code is confusing? Nothing about this function is particularly arcane, well except for the magic number.

Still, this algorithm is well documented now. Most C tutorials even will have this level pointer play.
>>
>>60645656
nigga that methods so private its name is redacted
>>
>>60646270
Other than the magic number, it's literally just Newton's method. Now, the magic number, I don't even fucking know how they got that
>>
>>60645757
very underrated comment
>>60646528
kek
>>
>>60646498
>Nothing about this function is particularly arcane, well except [the thing]
haha uninstall yourself my man
>>
File: 1495845923381.jpg (14KB, 480x480px) Image search: [Google]
1495845923381.jpg
14KB, 480x480px
>>60646528
>>
>>60646552
This is what I really want to know.
>>
>>60646552
Apparently a mathematician sat down and found a more accurate magic number to use in this method, returns a more accurate answer, but it somehow ran slower than this one.
Even the guy who wrote it isn't really sure where he got it from.
>>
>It is not known how the constant was originally derived

Did the guy who came up with it just forget?
>>
>>60646964
I get the feeling Carmack used the old "educated guess" method to get that number. It's worked for me in the past, can't see why it wouldn't work for a genius like him.
>>
>>60647018
cumrag didn't write it tho
>>
>>60646964
Maybe God told him but Carmack didn't want everyone to think he was crazy like Terry so he kept his mouth shut.
>>
File: Ot9xvxh.jpg (211KB, 869x1776px) Image search: [Google]
Ot9xvxh.jpg
211KB, 869x1776px
>>60645656
>your code will never stump john car-
>>
>>60645656
Can this be implemented in Python?
>>
>>60647278
Nice troll image.
>>
>>60647289
Trolling autistics like that in their homeland is an internet war crime.
>>
>>60647278
>>^_^
>>
>>60645800
>>60647096
>>60647206
Carmack didn't actually invent any of that newfags. He stole it from some people working on graphics stuff, as he usually does.
>>
>>60647285
Javascript

var buf = new ArrayBuffer(4);
var f32 = new Float32Array(buf);
var u32 = new Uint32Array(buf);

function q2(x) {
var x2 = 0.5 * (f32[0] = x);
u32[0] = (0x5f3759df - (u32[0] >> 1));
var y = f32[0];
y = y * ( 1.5 - ( x2 * y * y ) );

return y;
}
>>
>>60646611
He seems to have commented just about everything else. Nothing about the code itself is weird and even if you don't understand what it's meant for, the actual instructions are as common and basic as they get for C.

His reaction to the code is exaggerated to say the least. Even the "Seasoned Professional" hello world example is more strange than this one.
>>
>>60646498
You're so smart, now implement it.
>>
>>60647490
Here it is in Python :^)
def inverse_square(n):
return n**-0.5
>>
There is a simple explanation for the source of the constant. It came from the other side of the Stargate that they found in Iraq, just like the microprocessor and the KFC 14 spice recpe.
>>
>>60646964
How the fuck could a different magic num alter the speed? All the operations are fixed cycle duration on anything more powerful than a toaster.
>>
>>60645656
You didn't hear my boss on Thursday
> WTF is this anon? Who can read this or understand what you've done here but you?
> make it user friendly
It's user friendly now, but the magic is still there
>>
>>60645757
Kek
>>
>>60648159
4.5 times slower than the javascript solution
25 times slower than Carmack's C solution
>>
>>60648215
Think Anon got confused. They found another magic number that produced a more accurate estimate but it was less accurate after the first iteration of newton's method
>>
>>60647278
max(22, 22); // returns 5
>>
>>60647490
should be SharedArrayBuffer desu fampai
>>
>>60647473
Source?
>>
>>60650154
As in you timed it yourself, or that Python's powers implementation is slow?
>>
It's not certain Carmack actually even wrote this code, and this method of computing fast inverse squares actually predates Doom by about ten years.

>The algorithm was originally attributed to John Carmack, but an investigation showed that the code had deeper roots in both the hardware and software side of computer graphics. Adjustments and alterations passed through both Silicon Graphics and 3dfx Interactive, with Gary Tarolli's implementation for the SGI Indigo as the earliest known use.

from wikipedia
>>
>>60646552
it has to do with the bit depth used to represent the numbers
something about it fits just right with the manipulation that needs to be done
>>
>>60650622
He's full of shit. He got the code when working with some other graphics engineer in the 90s, before the code had ever been seen online.
>>
>>60650660
I am aware. Even John Carmack couldn't understand how the code worked, but it did, so Id used it. Hence his comments.
>>
>>60645691
>being too stupid to understand what you read
Thread posts: 49
Thread images: 4


[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]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.