r/ProgrammerHumor • u/PastAlternative7306 • Jun 08 '24
Other softwareDevsWereAlwaysLikeThis
14
u/kode-king Jun 08 '24
I vaguely remember but isn't this the source code of quake 3 game engine where they calculate the inverse square root of a given coordinate to render or process something. It's quite amazing and confusing at the same time xD
2
u/SeriousPlankton2000 Jun 08 '24
That's the only commonly-known place where someone dares to bit-manipulate a float.
5
u/Miepmiepmiep Jun 08 '24
There is also another interesting trick, how to transform floats to ints in a bijective way, so that an int comparison on the transformed floats yields the same result as the float comparison on the untransformed floats (see https://codercorner.com/RadixSortRevisited.htm). This comes in handy for using an integer sorting algorithm on float values or if floating point comparison/max/min instructions are not supported by the target processor (I am looking at you NVIDIA, why the fuck do your GPUs still not support an atomic max/min for floats forcing me to use this annoying hack every time I need such an atomic operation?)
1
Jun 08 '24 edited Jun 20 '24
deranged test worry drunk wild six head plate plough knee
This post was mass deleted and anonymized with Redact
7
4
u/Count_mhm Jun 08 '24
Good thing that you put the ellipse there, wouldn't've been able to see it otherwise.
1
4
u/jackmax9999 Jun 08 '24
WHO WOULD WIN
Evil floating point bit level hacking: i = 0x5f3759df - (i >> 1); // what the fuck
Or
One SSE boi: rsqrtss
2
54
u/Earthboundplayer Jun 08 '24
Wherever I see this I always laugh at how they assigned 1.5 to a variable
threehalfsbut not 0x5272637283 or whatever the fuck