Re: Divide by Zero

Frans Bouma <[email protected]> Tue, 26 Feb 2008 11:04:56 +0100
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <009701c8785f$0a016930$1e043b90$@nl>
> On Tue, 26 Feb 2008 10:35:15 +0100, Frans Bouma <[email protected]> wrote:
>
> >> In a little more than a nutshell, why does the CLR only throw a divide by
> >> zero exception for integers?
> >
> > I think because, if I recall correctly, a floating point number is
> > always an approximation, so you can have a floating point value
> > which seems 0 but actually isn't.
>
> I disagree. PositiveInfinity, for example, is not an approximation. It's
> really infinity.
> http://msdn2.microsoft.com/en-us/library/system.double.positiveinfinity.aspx

        Though how would you store 'e' or 'pi' ? You have just 4 or 8 bytes.
You can't possibly store everything in there.

        As Efran showed in a little example, it is possible to get weird
results with float arithmetic. Problems arise when very small values have to
be stored in the 8 bytes and there's not enough room to store the small value
in its full range (e.g. a non-repetitive fraction at
-e10000000000000000000000000000 in a float.) What to do? is this 0 ? Or very
close to 0?

        So dividing by a number which ISN'T 0 theoretically but in practise
the value is 0 because there's no room to store the value, as it's that small,
could result in an exception which isn't correct.

        At least that's what I remember (hence 'if I recall correctly' ;))
from my days in 3D programming land in C. ;)

                FB

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com