Discuss Scratch

MrSherlockHolmes
Scratcher
500+ posts

10 ^ x block is innacurate

([10 ^ v] of (2))
Gives you 99.9999998, surely it's just 100!
With 10^3 it gives 999.999998?
Can someone explain this? Thanks
SH
Doodle-cats
Scratcher
500+ posts

10 ^ x block is innacurate

I think a better place for this would be in “Bugs And Glitches” forum
MrSherlockHolmes
Scratcher
500+ posts

10 ^ x block is innacurate

Doodle-cats wrote:

I think a better place for this would be in “Bugs And Glitches” forum
Good point.
Doodle-cats
Scratcher
500+ posts

10 ^ x block is innacurate

MrSherlockHolmes wrote:

Doodle-cats wrote:

I think a better place for this would be in “Bugs And Glitches” forum
Good point.
You could tell Paddle2See to maybe move this discussion
MrSherlockHolmes
Scratcher
500+ posts

10 ^ x block is innacurate

Doodle-cats wrote:

MrSherlockHolmes wrote:

Doodle-cats wrote:

I think a better place for this would be in “Bugs And Glitches” forum
Good point.
You could tell Paddle2See to maybe move this discussion
K
TheLogFather
Scratcher
1000+ posts

10 ^ x block is innacurate

Welcome to the joys of floating-point arithmetic

Now, you might be thinking that you haven't used any non-integer numbers (I mean ten… to the power of two…?!), but that doesn't mean the computer hasn't.

Under the hood, powers are generally worked out using the formula x ^ y = e ^ y*(lnx)

That means 10^2 is e^2*ln(10). Unfortunately, both e and ln(2) are not whole numbers, so you've now entered the realm of inexact floating-point arithmetic

I've got a project which contains a generalised power-of custom block:


http://scratch.mit.edu/projects/16871883

One of its features is that it detects when both x & y are integers and rounds the result (as well as constructing integer powers of ten using text containing a one & zeros, plus decimal point for 10^negative).

Hope that makes sense of it!

Last edited by TheLogFather (Jan. 18, 2015 16:50:28)

MrSherlockHolmes
Scratcher
500+ posts

10 ^ x block is innacurate

TheLogFather wrote:

Welcome to the joys of floating-point arithmetic

Now, you might be thinking that you haven't used any non-integer numbers (I mean ten… to the power of two…?!), but that doesn't mean the computer hasn't.

Under the hood, powers are generally worked out using the formula x ^ y = e ^ y*(lnx)

That means 10^2 is e^2*ln(10). Unfortunately, both e and ln(2) are not whole numbers, so you've now entered the realm of inexact floating-point arithmetic

I've got a project which contains a generalised power-of custom block:


http://scratch.mit.edu/projects/16871883

One of its features is that it detects when both x & y are integers and rounds the result (as well as constructing integer powers of ten using text containing a one & zeros, plus decimal point for 10^negative).

Hope that makes sense of it!
Thanks!

Powered by DjangoBB