Re: Strange BUG in teh Framework?

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 10/11/04


Date: Mon, 11 Oct 2004 15:16:37 -0500

David,
I don't believe its a bug per se, its due to the inexact nature of how
floating point numbers are stored.

If you change xSng to a Double or Decimal, you get the correct result.

For a complete discussion (and explaination) of how floating point numbers
work in .NET see:

http://www.yoda.arachsys.com/csharp/floatingpoint.html

http://www.yoda.arachsys.com/csharp/decimal.html

Hope this helps
Jay

"David" <David.Konig@nowhere.com> wrote in message
news:epx1At8rEHA.3964@TK2MSFTNGP10.phx.gbl...
> hello.
> when doing the simple following computation, the value put into the
> variable
> numMinusOne is NOT the same as what the computation is showed to be in the
> Watch window!!
> here is the code:
> Dim xSng As Single = 6547.972
> Dim yInt As Integer = 8000
> Dim num As Integer = CInt(Math.Floor(xSng * yInt))
> Dim numMinusOne As Integer = CInt(Math.Floor(xSng * yInt) - 1)
>
> After running these 4 lines, numMinusOne will be:52383776
> while the Watch window will claim that the value of :
> CInt(Math.Floor(xSng * yInt) - 1) = 52383775
>
> BTW, the Watch window is correct.
>
> how come the numMinusOne does not get the correct value?
>
>



Relevant Pages

  • Re: Strange BUG in teh Framework?
    ... If you change xSng to a Double or Decimal, ... For a complete discussion of how floating point numbers ... > while the Watch window will claim that the value of: ... > how come the numMinusOne does not get the correct value? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Strange BUG in teh Framework?
    ... If you change xSng to a Double or Decimal, ... For a complete discussion of how floating point numbers ... > while the Watch window will claim that the value of: ... > how come the numMinusOne does not get the correct value? ...
    (microsoft.public.dotnet.general)
  • Re: Strange BUG in teh Framework?
    ... David wrote: ... > while the Watch window will claim that the value of: ... > how come the numMinusOne does not get the correct value? ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Strange BUG in teh Framework?
    ... David wrote: ... > while the Watch window will claim that the value of: ... > how come the numMinusOne does not get the correct value? ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.framework)
  • Re: Strange BUG in teh Framework?
    ... David wrote: ... > while the Watch window will claim that the value of: ... > how come the numMinusOne does not get the correct value? ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.general)