That post seems to be missing.
mox 15 points 2 years ago path: 0 12558618, hotness: undefined, score: 15, children: 0
karlhungus 12 points 2 years ago

Ugh, i thought this was a question, not a link. So i spent time googling for a good tutorial on floats (because I didn't click the link)....

Now i hate myself, and this post.

path: 0 12556131, hotness: undefined, score: 12, children: 0
eric 9 points 2 years ago path: 0 12561659, hotness: undefined, score: 9, children: 0
Zagorath 6 points 2 years ago

A good way to think of it is to compare something similar in decimal. .1 and .2 are precise values in decimal, but can't be represented as perfectly in binary. 1/3 might be a pretty good similar-enough example. With a lack of precision, that might become 0.33333333, which when added in the expression 1/3 + 1/3 + 1/3 will give you 0.99999999, instead of the correct answer of 1.

path: 0 12556073, hotness: undefined, score: 6, children: 7
toasteecup -6 points 2 years ago

Python has no issues representing

1/3 + 1/3 + 1/3

as 1. I just opened a python interpreter, imported absolutely no libraries and typed

1/3 + 1/3 + 1/3 enter and got 1 as the result. Seems like if python could do that, JavaScript should be able to as well.

path: 0 12556073 12556295, hotness: undefined, score: -6, children: 6
andnekon 5 points 2 years ago

Now try opening js interpreter and doing the same.

Also, try 0.1+0.2 in python interpreter.

path: 0 12556073 12556295 12556442, hotness: undefined, score: 5, children: 1
toasteecup 2 points 2 years ago

I'll pass on the js interpreter. I don't feel like learning the arcane runes.

To your point, Python handles those by giving you 0.300000004 might have missed a zero but valid point nonetheless

path: 0 12556073 12556295 12556442 12558172, hotness: undefined, score: 2, children: 0
Zagorath 4 points 2 years ago

I thought it was a rather simple analogue, but I guess it was too complicated for some?

I said nothing about JavaScript or Python or any other language with my 1/3 example. I wasn't even talking about binary. It was an example of something that might be problematic if you added numbers in an imprecise way in decimal, the same way binary floating point fails to accurately represent 1/10 + 1/5 from the OP.

path: 0 12556073 12556295 12556814, hotness: undefined, score: 4, children: 1
ericjmorey 1 point 2 years ago

Perhaps the following rewording of your last sentence would be easier for readers to follow along:

With a lack of precision, 1/3 might become 0.33333333. When evaluating the expression 1/3 + 1/3 + 1/3, using 0.33333333 as an approximate representation of 1/3 will return a result of 0.99999999, instead of the correct answer of 1.

path: 0 12556073 12556295 12556814 12559185, hotness: undefined, score: 1, children: 0
aubeynarf 2 points 2 years ago
path: 0 12556073 12556295 12556845, hotness: undefined, score: 2, children: 0
GetOffMyLan 0 points 2 years ago
path: 0 12556073 12556295 12559762, hotness: undefined, score: 0, children: 0
RagingHungryPanda 6 points 2 years ago

It's how CPUs do floating point calculations. It's not just javascript. Long story short, a float is stored in the format of one bit for the +/-, some bits for a base value (mantissa), and some bits for the exponent. As a result, some numbers aren't quite representable exactly.

path: 0 12555813, hotness: undefined, score: 6, children: 0
germanatlas 4 points 2 years ago
path: 0 12563312, hotness: undefined, score: 4, children: 0
aubeynarf 2 points 2 years ago
path: 0 12556014, hotness: undefined, score: 2, children: 0

thanks for using Leebra!

go to feed...