Discuss Scratch

pikchiu
Scratcher
41 posts

The calculate blocks in scratch is broken

We all know 0.45 x 7 is 3.15 right?
But somehow 3.15 - 0.45 is 2.*6*.
It’s supposed to be 2.7.
Well please fix this when you know it scratch team!








By pikchiu
6thJune,2021
pikchiu
Scratcher
41 posts

The calculate blocks in scratch is broken

I forgot to say the number in * * (<—this) means the number is infinitely going.
Chiroyce
Scratcher
1000+ posts

The calculate blocks in scratch is broken



Actually Scratch is correct, rounding 2.69999999 is actually 2.7. So Scratch is extremely accurate then!
NOT a Bug

Last edited by Chiroyce (June 6, 2021 10:45:30)

CST1229
Scratcher
1000+ posts

The calculate blocks in scratch is broken

Not a Bug, floating point arithmetic is not perfect.
I'm just gonna quote @Flowermanvista:

Flowermanvista wrote:

Not a bug, that's just the inherent limitations of a floating point number. The site 0.30000000000000004.com gives what I think is a pretty good explanation:

0.30000000000000004.com wrote:

Floating Point Math

Your language isn't broken, it's doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. That's why, more often than not, .1 + .2 != .3.

Why does this happen?

It's actually rather interesting. When you have a base 10 system (like ours), it can only express fractions that use a prime factor of the base. The prime factors of 10 are 2 and 5. So 1/2, 1/4, 1/5, 1/8, and 1/10 can all be expressed cleanly because the denominators all use prime factors of 10. In contrast, 1/3, 1/6, and 1/7 are all repeating decimals because their denominators use a prime factor of 3 or 7. In binary (or base 2), the only prime factor is 2. So you can only express fractions cleanly which only contain 2 as a prime factor. In binary, 1/2, 1/4, 1/8 would all be expressed cleanly as decimals. While, 1/5 or 1/10 would be repeating decimals. So 0.1 and 0.2 (1/10 and 1/5) while clean decimals in a base 10 system, are repeating decimals in the base 2 system the computer is operating in. When you do math on these repeating decimals, you end up with leftovers which carry over when you convert the computer's base 2 (binary) number into a more human readable base 10 number.
SonicFanX123_321
Scratcher
1000+ posts

The calculate blocks in scratch is broken

NOT A BUG

Float point arethmatic is not perfect.

pikchiu wrote:

But somehow 3.15 - 0.45 is 2.*6*.
Yes thats right.
<((3.15) - (0.45)) = (2.699999999...)>
But
(round <((3.15) - (0.45)) = (2.7)>)
So 2.69999999… and 2.7 are tecnicly both correct.
Chiroyce
Scratcher
1000+ posts

The calculate blocks in scratch is broken

but guys, isn't 2.69999999 more accurate than 2.7? So isn't floating point math more accurate?

Powered by DjangoBB