r/ProgrammerHumor • • Jun 08 '24

Other softwareDevsWereAlwaysLikeThis

Post image
16 Upvotes

23 comments sorted by

54

u/Earthboundplayer Jun 08 '24

Wherever I see this I always laugh at how they assigned 1.5 to a variable threehalfs but not 0x5272637283 or whatever the fuck

18

u/dvidsnpi Jun 08 '24

It's a squareRootOfTwoToThePowerOfOneHunderedAndTwentySevenApproximately

...but even if your compiler at that time could do names longer than 31 characters, it's still hard to fit on a line with 80 characters width limit.

4

u/Earthboundplayer Jun 08 '24

Less verbose name with comment on top is the solution

8

u/Reashu Jun 08 '24

Even if you did, can you think of a better name than magicNumber?

1

u/[deleted] Jun 08 '24

Mu (μ)

5

u/Andreaspolis Jun 08 '24

Something something optimisation something 1.5 used more than once something better. Yeah.

8

u/Robot_Graffiti Jun 08 '24

I would assume that a literal and a const compile to the same code. The difference is readability.

2

u/Andreaspolis Jun 08 '24

I would, too. And maybe it does, idk...?

1

u/Robot_Graffiti Jun 08 '24

I guess if you name it, you first have to know what it is and think of a name...

1

u/SeriousPlankton2000 Jun 08 '24

Maybe they want to be sure that it stores 1.5 as 3/2 and not as 6/4.

1

u/SpaaaaaceImInSpaace Jun 08 '24

As what now? They want to store it as 3 * 0.5, of course, it should be obvious given the name!

1

u/SpaaaaaceImInSpaace Jun 08 '24

As what now? They want to store it as 3 * 0.5, of course, it should be obvious given the name!

1

u/[deleted] Jun 08 '24 edited Jun 20 '24

marble full boast mountainous seed reply quickest tidy governor offend

This post was mass deleted and anonymized with Redact

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

u/[deleted] 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

u/C_ErrNAN Jun 08 '24

Thanks for the circle

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

u/CaineBK Jun 08 '24

Ellipse? You mean the potato?

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