Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Division by zero in .NET
Message
From
30/05/2008 08:34:50
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01320485
Message ID:
01320510
Views:
20
It's ridiculous anyway. In any type of math, division by zero is not supposed to be 'infinity', it's supposed to be 'undefined'. But you're right, infinity should be outside the range of double and float, but they have special values of positive infinity and negative infinity. I have no good idea why. 5/0 gives positive infinity. -5/0 gives negative infinity.

They also accept positive and negative zero. However, dividing zero by zero gives NAN (not a number).

>In C# the result of dividing any number by zero is infinity. The Double and Float types have a special value that represents infinity, while other numeric types do not, as you have observed. The explanation I have read is that infinity is outside the range of the smaller data types. That doesn't really make sense to me. Isn't infinity, by definition, outside the range of any data type?
>
>By design, but infinitely confusing.....
>
>
>>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
>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform