Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Division by zero in .NET
Message
From
30/05/2008 06:03:52
 
 
To
30/05/2008 03:51:47
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01320485
Message ID:
01320493
Views:
10
Dunno, Stefan, but I'd say that floating point can represent infinities whereas integer and decimal types cannot

Since division by zero is an infinity and integers don't know how to represent that, it gives a runtime DivideByZeroException
int i, j;
i = 1;
j = 0;


var z = i / j; // DivideByZeroException
>As far as I learned, in .NET a Division By Zero can be done with double types but not with int.
>If that's true, what is the idea behind it?
>
>TIA
>-Stefan
>
>
>            // positive value / 0
>            double d = 1.0 / 0.0;
>            Console.WriteLine(d);
>
>            // negative value / 0
>            d = -1.0 / 0.0;
>            Console.WriteLine(d);
>
>            if (Double.IsPositiveInfinity(d))
>            {
>                Console.WriteLine("Overrun");
>            }
>            if (Double.IsNegativeInfinity(d))
>            {
>                Console.WriteLine("Underrun");
>            }
>
>            // int division by 0?
>            int i = 1 / 0; // compiler says Error CS0020
>
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform