It is a memory problem, but it has nothing to do with memory being
bad. It has to do with how the numbers are represented in a relatively
small amount of memory. Wikipedia has an excellent article on the
topic: http://en.wikipedia.org/wiki/IEEE_754 . Read that, and try to
answer Mr. Lopez's question "How would the computer increment by a
10th? How is it represented in binary?" and you'll see the problem.
You can also google IEEE 754 for even more info.

(Answer: You can't represent 0.1 in a floating number, you can only
get close.)

On Sep 6, 12:17 pm, "Charles A. Lopez" <[EMAIL PROTECTED]>
wrote:
> Here are my thoughts
>
> Before and after the decimal point a number is stored in the computer as
> binary.
>
> Before the decimal we have
>
> 2^0 = 1
> 2^1 = 2
> 2^2 = 4
> 2^3 = 8
> 2^4 = 16
> 2^5 = 32
> 2^6 = 64
> 2^7 = 128
>
> After the decimal we have
>
> 2^-1 = 1/2  = .5
> 2^-2 = 1/4 = .25
> 2^-3 = 1/8 = .125
> 2^-4 = 1/16 = .0625
> 2^-5 = 1/32 = .03125
> 2^-6 = 1/64 = 0.015625
> 2^-7 = 1/128 = 0.0078125
>
> How would the computer increment by a 10th? How is it represented in binary?
>
>
>
> On Fri, Sep 5, 2008 at 1:17 AM, velsankar <[EMAIL PROTECTED]> wrote:
>
> > A very basic problem, every one used to come across on our learning
> > times itself (mostly overlooked & the result oriented attitude rather
> > than why it is happening), still we have solution to avoid these.But
> > anyone know why it is happening???? The problem is the following code
> > only:
>
> > for (float i = 10; i <= 11; i =i+ 0.1f)
> >                Console.WriteLine(i);
>
> > We will get answer as 10,10.0,....,10.9
>
> > Look @ the condition: it's <= & not <. Obviously, 11.0 should come.
> > Why it is not coming?
>
> > When I asked my profs on my college days(even seniors, expd's), they
> > advised to use double. Of course, its a solution to get 11.0. But what
> > happened to float? Is the float not precise???? For some days(truly in
> > years), I believed it might be memory issue. Because when  we see the
> > entire 32 bytes of the increment float value, it is not increasing
> > 0.10000000000.... but 0.10000010000 (The value is not constant, It can
> > be in any one of the 256 bits). Recently I tested with fresh(means the
> > first application to run after installed the windows embedded xp os)
> > thin client. Shocked!!!! The end result is same:(
>
> > Is it Really a memory problem? If so, how can we identify better than
> > test as first application after os installed. Or the way I looking the
> > problem???. And more it is not the language issue. Its starts with c
> > only. Tested with c++, java also. I want to know the reason. Please
> > don't suggest to use double, if so why it is happening with float &
> > not with double???
>
> > Think, its not looks like advanced level programming, But the issue @
> > core, fundamentals, how far we are understanding our process. Hope I
> > will get the genuine cause.
>
> --
> Charles A. Lopez
> [EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---

Reply via email to