Python Sum() Function Is WRONG! #python #programming #coding

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

It's called floating point rounding error. As everyone who codes should know.

grapes
Автор

Mathematicians: I see nothing wrong with this.

davidpement
Автор

Except that the sum function is doing exactly what it's supposed to, the problem is simply that floating points number are not infinitely precise and so 9.999 is actually the correct answer. You need additionnal processing to get 10 and that's not always what you want.

TomiDJtal
Автор

not really a flaw in the python function just how floating points work. Although the python hate is apprecihated this is not its fault. It ironically also shows why you should learn coding with a type strong language

jakob
Автор

this is not an error, it's a correct computation becouse you can't write down 0.1 decimal in binary it's periodic 0.0(0011) fraction.

thefoe
Автор

That aint a sum() exclusive problem, neither is it exclusive to python

CorruptMem
Автор

This example is used in the Python documentation for Math.fsum().

OriginalCloud
Автор

I asume you know what the binary problem is with decimals

eryarer
Автор

“Did you know there is a major flaw in python?” - should have stopped there 😂

davidfreer
Автор

Is it incorrect or is it floating point addition

ttrss
Автор

Except Computers only do what we tell them to do. They don't have thoughts. So when it outputs a number, you're human brain says no its equal to 1, but the computer the numbers and added them together perfectly, without bias. And when you add the Math Function instead of just getting the sum of the numbers, you introduce a new rule set for the numbers based on a pattern defined by humans. Still doesn't make it equal one, and I'll die on this hill, cause i think anyone that thinks 1 can be divided by three in the first place is incompetent, and shouldn't be allowed to voice their opinions on the internet. Because if you divide one you can get two equal parts but one part will always be larger. Cut a pizza into three cut a cake into three, it will never be exactly the same mass in all three portions without removing a portion entirely, no matter how infintecimally small.

cypherparadigm
Автор

Someone doesn’t know how computers work

uxkkvpm
Автор

Which ide you are using??
I am just a beginner!

deadpoolspeaking
Автор

Couldn’t you just do print(round(sum(x), 1)) ?

Levnt
Автор

0.9999 = 1 is a proof, I learnt in Highschool.

God_f_Death