Discuss Scratch

cs2627883
Scratcher
100+ posts

Multiplication BUG: 1.1 * 100 = 110.(0repeating)1 (or 110.000000001)

My browser / operating system: Windows NT 10.0, Chrome 90.0.4430.212, No Flash version detected

So, I don't know why this happens, but 1.1 * 100 and 100 * 1.1 aren't returning right. Other similar calculations like 1.1 * 10, 1.1 * 1000, and 1.2 * 100 are correct, but this isn't,

I thought I was crazy and checked using both Google's calculator and a psychical one. Still was giving me 110 there.

SEE MY PROJECT EXPLAINING THIS BUG:
https://scratch.mit.edu/projects/534286121/

Last edited by cs2627883 (May 21, 2021 19:34:42)

BrycedTea
Scratcher
100+ posts

Multiplication BUG: 1.1 * 100 = 110.(0repeating)1 (or 110.000000001)

You are seeing the limitations of floating point math. .1 in binary is not a nice neat fraction, it becomes a repeating “decimal” (but the binary version) in the same way that 1/3 becomes a repeating decimal in base 10. At a certain point, the computer rounds or truncates the number, which causes minor inaccuracies.

Many tools do some slightly fancier calculations to round numbers to make more sense to people. Scratch does in some situations, like in speech bubbles, (in your case you converted the value to a string before putting it into the bubble with the join block), but not when you check the value of that reporter.

You can find more information about it here: 0.30000000000000004.com
cs2627883
Scratcher
100+ posts

Multiplication BUG: 1.1 * 100 = 110.(0repeating)1 (or 110.000000001)

BrycedTea wrote:

You are seeing the limitations of floating point math. .1 in binary is not a nice neat fraction, it becomes a repeating “decimal” (but the binary version) in the same way that 1/3 becomes a repeating decimal in base 10. At a certain point, the computer rounds or truncates the number, which causes minor inaccuracies.

Many tools do some slightly fancier calculations to round numbers to make more sense to people. Scratch does in some situations, like in speech bubbles, (in your case you converted the value to a string before putting it into the bubble with the join block), but not when you check the value of that reporter.

You can find more information about it here: 0.30000000000000004.com
Considering how scratch uses an external PRNG, I think it should also use an external calculator. It would just make sense. So I'm calling it a “bug”. Thanks, though!
Chiroyce
Scratcher
1000+ posts

Multiplication BUG: 1.1 * 100 = 110.(0repeating)1 (or 110.000000001)

cs2627883 wrote:

Considering how scratch uses an external PRNG, I think it should also use an external calculator. It would just make sense. So I'm calling it a “bug”. Thanks, though!
Scratch uses JavaScript's
math.random()
that also only returns double precision floating point numbers, JavaScript itself uses double precision floating point numbers, so how will Scratch use an external calculator?







April Fools' topics:
New Buildings in Scratch's headquarters
Give every Scratcher an M1 MacBook Air
Scratch should let users edit other Scratchers' projects
Make a statue for Jeffalo
Scratch Tech Tips™
Make a Chiroyce statue emoji


<img src=“x” onerror=“alert('XSS vulnerability discovered')”>

this is a test sentence
cs2627883
Scratcher
100+ posts

Multiplication BUG: 1.1 * 100 = 110.(0repeating)1 (or 110.000000001)

Chiroyce wrote:

cs2627883 wrote:

Considering how scratch uses an external PRNG, I think it should also use an external calculator. It would just make sense. So I'm calling it a “bug”. Thanks, though!
Scratch uses JavaScript's
math.random()
that also only returns double precision floating point numbers, JavaScript itself uses double precision floating point numbers, so how will Scratch use an external calculator?
Oh okay, I thought it used google's translate and random number generator.

Powered by DjangoBB