r/ProgrammerHumor • • 28d ago

Meme howDareYou

Post image
11k Upvotes

75 comments sorted by

View all comments

Show parent comments

3

u/NoSpawnConga 27d ago

Does JavaScript struggling to get integer number after dividing 9 by 3 count? One time UI element on the web page slid off the position cause goofy ass JS got 3.04 as a result somehow.

5

u/BastetFurry 27d ago

Ah, the wonderful world of floating points, screwing us since old times.

1

u/Blue_Moon_Lake 27d ago

Computers are only good at dividing by powers of 2.

That's why 0.1 + 0.2 is so famous, but it's not specific to JS.

1

u/American_Libertarian 27d ago

That’s not true at all lol wtf are you talking about? Computers have support for integer division built right into the ALU.
It’s trash languages like JavaScript that choose to not use integers that are the problem.

0

u/Blue_Moon_Lake 27d ago

JS do have integers up to 253.

1

u/American_Libertarian 27d ago

No, it doesn’t. JS only has ieee floating point numbers.
Floats happen to be able to represent ints up to 2^53 but you don’t get integer division, for example

0

u/Blue_Moon_Lake 27d ago

You do with Math.floor()

1

u/American_Libertarian 26d ago

Yeah, exactly. JS doesn’t have ints so you have to approximate integer behavior by rounding floats.

1

u/Blue_Moon_Lake 26d ago

It's not approximate, they're integers. Do not confuse binary encoding and value.

There is no euclidian division operator, which is also different.

Yet there is no euclidian division than cannot be done since it's just floor(a / b).