Re: Divide by Zero
Efran Cobisi <[email protected]> Tue, 26 Feb 2008 10:36:08 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Organization | cobisi.com |
| Message-ID | <[email protected]> |
A nice side effect of this approximation is that the two outputs of the
following example differ.
Awesome! :)
decimal d = 0m;
float f = 0f;
for (var i = 0; i < 10; i++)
{
d += 0.1m;
f += 0.1f;
}
Console.WriteLine(d == 1m);
Console.WriteLine(f == 1f);
--
Efran Cobisi
http://www.cobisi.com
Frans Bouma 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.
>
> Though for decimals, it should indeed...
>
> FB
>
> ===================================
> This list is hosted by DevelopMentor® http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com