This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-03-01 11:59:31

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Dividing by 0

I know that when you divide by 0, technically the result is not a number, but this is really inconvenient.

Please change this so that it will become a 0 automatically, the distance formula keeps messing up... (and I DID put absolute values before the square roots, but I have to add 0.01 and I'm using really small sprites)

It can't be that hard... right?


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#2 2010-03-01 12:00:31

BWOG
Scratcher
Registered: 2008-09-19
Posts: 1000+

Re: Dividing by 0

I know. It's annoying when the whole project stops because of it.

Offline

 

#3 2010-03-01 15:53:38

Ace-of-Spades
Scratcher
Registered: 2010-01-08
Posts: 1000+

Re: Dividing by 0

You get a squeak error though because it's Squeak itself that can't handle dividing by 0, not Scratch. So it's out of the Scratch Team's hands.


11110010100011010100011010101000100011011011001010111100101000110101000110101010001000110110110010101111001010001101010001101010100010001101101100101011110010100011010100011010101000100011011011001010
110101010010001010101010101010101010101010100110101010010101010010101001101011010101010010101010101

Offline

 

#4 2010-03-01 16:09:45

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Dividing by 0

I like the idea of setting anything divide by 0 to NaN (not a number) instead of crashing the program.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2010-03-01 16:23:41

jake451998
Scratcher
Registered: 2009-04-01
Posts: 100+

Re: Dividing by 0

juststickman wrote:

I know that when you divide by 0, technically the result is not a number, but this is really inconvenient.

Please change this so that it will become a 0 automatically, the distance formula keeps messing up... (and I DID put absolute values before the square roots, but I have to add 0.01 and I'm using really small sprites)

It can't be that hard... right?

I did it online with my calculator,It said infinity or put  the symbol

Offline

 

#6 2010-03-01 16:38:16

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Dividing by 0

Not a bad idea. Along with archmage's idea.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#7 2010-03-01 17:09:42

RHY3756547
Scratcher
Registered: 2009-08-15
Posts: 1000+

Re: Dividing by 0

+0.001 still gets me close answers to what I want and doesn't make much of a difference to the calculation other than making it not infinite - so I think it's just fine.

Offline

 

#8 2010-03-01 20:29:59

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Dividing by 0

You might want to talk too the guys who invented math. Just kidding  smile . I agree, it would be useful.


http://i48.tinypic.com/2z5pqad.png

Offline

 

#9 2010-03-01 23:50:40

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Dividing by 0

Ace-of-Spades wrote:

You get a squeak error though because it's Squeak itself that can't handle dividing by 0, not Scratch. So it's out of the Scratch Team's hands.

Actually, if this were the case, it wouldn't. Squeak is fully self modifiable.
However, it is actually handled by scratch, using the red script thing.

As far as any programming use, it is generally most useful to assume x/0 to be infinity, unless x=0.
Squeak does support infinity.
So if anything, we should have it return infinity in the instance of dividing a number by zero.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#10 2010-03-02 08:32:18

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: Dividing by 0

For me, I think it should be zero.

Because 0/0 means that you have no groups and nothing to put into the groups. You should get the answer 0 because there wasn't anything in the groups.

Offline

 

#11 2010-03-02 10:05:19

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: Dividing by 0

ThePCKid wrote:

For me, I think it should be zero.

Because 0/0 means that you have no groups and nothing to put into the groups. You should get the answer 0 because there wasn't anything in the groups.

1/0 is infinity.

There are zero groups of 1, with infinity in each of them(or the one of them). Why?

1/1 = 1
1/2 = 0.5

1/(1/10) = 10
1/(1/100) = 100
1/(1/1,000,000) = 1,000,000

As the divisor gets larger, the answer swings closer to zero.
As it gets smaller, the answer gets larger.

Sometimes math is hard, I don't blame you, a nine-year kid.  tongue


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#12 2010-03-12 18:59:48

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: Dividing by 0

Greatdane wrote:

ThePCKid wrote:

For me, I think it should be zero.

Because 0/0 means that you have no groups and nothing to put into the groups. You should get the answer 0 because there wasn't anything in the groups.

1/0 is infinity.

There are zero groups of 1, with infinity in each of them(or the one of them). Why?

1/1 = 1
1/2 = 0.5

1/(1/10) = 10
1/(1/100) = 100
1/(1/1,000,000) = 1,000,000

As the divisor gets larger, the answer swings closer to zero.
As it gets smaller, the answer gets larger.

Sometimes math is hard, I don't blame you, a nine-year kid.  tongue

O RLY? http://www.wolframalpha.com/input/?i=0/0

Offline

 

#13 2010-03-12 21:49:31

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: Dividing by 0

ThePCKid wrote:

Greatdane wrote:

ThePCKid wrote:

For me, I think it should be zero.

Because 0/0 means that you have no groups and nothing to put into the groups. You should get the answer 0 because there wasn't anything in the groups.

1/0 is infinity.

There are zero groups of 1, with infinity in each of them(or the one of them). Why?

1/1 = 1
1/2 = 0.5

1/(1/10) = 10
1/(1/100) = 100
1/(1/1,000,000) = 1,000,000

As the divisor gets larger, the answer swings closer to zero.
As it gets smaller, the answer gets larger.

Sometimes math is hard, I don't blame you, a nine-year kid.  tongue

O RLY? http://www.wolframalpha.com/input/?i=0/0

0/0 is an exception duh, if you haven't figured it out yet. http://www.wolframalpha.com/input/?i=x+ … inity}+x/0

Last edited by Greatdane (2010-03-12 21:50:13)


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#14 2010-03-12 22:58:48

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Dividing by 0

It's normal for divide by zero to throw an error in computer programs. 
or it could output an incorrect result...
http://en.wikipedia.org/wiki/Division_by_zero#In_computer_arithmetic
http://mathworld.wolfram.com/DivisionbyZero.html
http://mathforum.org/dr.math/faq/faq.divideby0.html

You can program to avoid it:
-don't let it get to zero like someone suggested already.
-test for 0 before you divide, make it do something else if it is.
-For what I need it for, sometimes I can use multiplication by a decimal number instead:
4/8 = .5
4/4 = 1
4/2 = 2
4/0 = infinity or error

4 * .125 = .5
4 * .25 = 1
4 * .5 = 2
4 * 0 = 0

there's probably better tips for avoiding /0 errors somewhere.

Last edited by AddZero (2010-03-12 23:26:37)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#15 2010-03-13 02:19:59

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Dividing by 0

For now RHY3756547's idea would work, along with the (round) block. But if they decide to change it from the "red outline of death", it should give the ∞ symbol.


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#16 2010-03-13 07:54:08

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Dividing by 0

hmnwilson wrote:

For now RHY3756547's idea would work, along with the (round) block. But if they decide to change it from the "red outline of death", it should give the ∞ symbol.

But infinity also causes errors.

Infinity-1=error
Infinity^2=error
Infinity=error
Infinity+0=error


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#17 2010-03-13 08:57:25

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: Dividing by 0

juststickman wrote:

hmnwilson wrote:

For now RHY3756547's idea would work, along with the (round) block. But if they decide to change it from the "red outline of death", it should give the ∞ symbol.

But infinity also causes errors.

Infinity-1=error
Infinity^2=error
Infinity=error
Infinity+0=error

The last one should be Infinity not error <abbr title="In My Opinion">IMO</abbr>

Oops I keep forgetting HTML doesn't work in the forums

Last edited by ThePCKid (2010-03-13 10:30:48)

Offline

 

#18 2010-03-13 09:08:57

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Dividing by 0

ThePCKid wrote:

juststickman wrote:

hmnwilson wrote:

For now RHY3756547's idea would work, along with the (round) block. But if they decide to change it from the "red outline of death", it should give the ∞ symbol.

But infinity also causes errors.

Infinity-1=error
Infinity^2=error
Infinity=error
Infinity+0=error

The last one should be Infinity not error <abbr title="In My Opinion">IMO</abbr>

I'm just saying what happens when you put it in scratch.


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

Board footer