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.

--~--~---------~--~----~------------~-------~--~----~
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