in

ASP.NET Weblogs

Memi.Reflection

Private members of memi's thoughts

Division by Zero

Is it possible? I didn't think so either. But read this.

I'm working now on a presentation regarding J2EE and .NET. For the sake of the presentation, I wanted to create error on one of the ASP.NET pages (yes, sometimes we do it just for fun. It's not a Bug, it's a Feature, you know...).

So, what is the easiest way to create an exception, I thought to myself? And immediately added the following code to the Page_Load event:

Response.write(1/0)

and executed the code. To my great surprise there was no exception! The page looked just normal. But while examining it more thoroughly, I found the following text on the upper left corner:

אינסוף חיובי

To those of you who can't read Hebrew (and I guess there are a handful of you), the meaning of those words are: Positive infinity.

WHAT? WTF? But wait - that's not all! When I modified the code to:

Response.write(-3/0)

The result was:

אינסוף שלילי

Which is:

Negative infinity.

Now, this is really strange:

First, since when a division by zero results in an infinity? I don't know much about math, but I asked my mother in law, who has a PhD in Mathematics, and she said that an expression like this is undefined, and definitely not infinity.

Second - localized math result? I liked that!

Anyway, here is an article which discusses this issue, but still does not explain when a division by zero is infinity. On the other side, in this article there is a good explanation why <Quote>division by zero is not defined for reals</Quote>, and when it is defined. Well worth reading.

So, does anybody know why division by zero is allowed in .NET?

Comments

 

Dean Harding said:

What version of .NET are you using? I got 1.1, and I get a compile error ("division by constant zero" if I try to compile your code. I also get an exception when using variables (i.e. "int a = 1, b = 0; int c = a/b;")

However, doing the same with float and double values is different. It is possible, in this case, to divide stuff by zero, resulting in +/- infinity. The reasons are mostly historical, but it does help in certain situations (like it can make formulas for parallel circuits with zero resistances magically work - you get a divide by zero then a divide by infinity).

Anyway, I guess you can say that it results in +/- infinity because "it's in the standard" (that is, IEEE 754 - the ubiquitous standard for floating point numbers)
December 15, 2004 6:12 PM
 

Darren T said:

Division by zero has always resulted in infinity. Computers just can't handle infinity, so you end up with a division by zero answer.
Its fairly easy to see why the answer to a division by zero equation will give you infinity. Start with any number and start dividing it by progressively smaller and smaller values. Your results will get bigger and bigger.

The really curious question is what is zero divided by zero. Personally, I believe its a set of all numbers.
December 16, 2004 2:25 AM
 

Brock Allen said:

You're using VB.NET I'll wager. C# throws.
December 16, 2004 4:17 PM
 

法国 said:

Excellent And
Merry Christmas
December 16, 2004 8:09 PM
 

Dean Harding said:

@Darren: No, division by zero is undefined. What you're thinking of is a different concept, that of the limit of 1/x, as x *approaches* 0 is inifinity. It doesn't mean that 1/0 *equals* infinity.

If you could write "1/0 = ∞", then the inverse needs to be true as well, namely, "0.∞ = 1" but zero multiplied by anything is zero. You could just as easily say "2/0 = ∞", therefore "0.∞ = 2" - clearly the same calculation can't have two different answers, hence division by zero is not defined for real numbers.
December 16, 2004 9:59 PM
 

TrackBack said:

^_^,Pretty Good!
April 9, 2005 10:40 PM
 

Tony Donovan said:

For vales of A close to zero, Sin(A)/A is less than 1 and greater than Cos(A). When A = 0, and Cos(A) = 1, can it be PROVED that Sin(A)/A is not = 1?

July 22, 2007 4:08 AM
 

Tom said:

>For vales of A close to zero, Sin(A)/A is less than 1 and greater than Cos(A). When A = 0, and Cos(A) = 1, can it be PROVED that Sin(A)/A is not = 1?

Yes it can.  In mathematics, *by definition* division by zero does not yield a number.

Floating point numbers, *by definition* do not follow the rules of mathematics in all cases.  Such as division by zero.

October 15, 2007 11:30 AM
 

venousto said:

quel est les solution non reel

de 0X=4

0X=X

0X=i

X^0=i

0X=4i

0X^0=6i

celui de bernard werber

qui prouve à tord que 1=2

et moi je rectifi avec les complyx

quel est la solution non reel

1/(0x^3-0x^2-1+2i)+1/(i-0x^i)-0x^2+0x+4=0

phebus.journalintime.com/.../2006-05-02-zero

June 30, 2008 5:06 AM

Leave a Comment

(required)  
(optional)
(required)  
Add