|
That's because of floating point precision. Your float will never be represented exactly. Check this[^]
|
|
|
|
|
nitin3 wrote: //in the above code c does not contain the the result i expected , it filled with 5.099999 and i get the output Not OK.
how i can check the value of c ? please help me
Try this... works for me...
void main()
{
float a = 5.0f , b = 0.1f ;
float c = a + b;
if( c >= 5.1f )
{
printf( "OK" ) ;
}
else
{
printf( "Not OK" ) ;
}
}
Always append "f" to a float value else it's treated as a double, earlier you were comparing a float var and a double var.
Explained further -> http://nibuthomas.wordpress.com/2007/06/08/comparing-two-float-values/[^]
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
floating point numbers are limited in resolution. They can get very close to the result, but not necessarily exact. You can minimize the problem by using "double" instead of "float", but that doesn't eliminate things. One quick fix is to simply use a small delta value in your computations. For example:
float delta = 0.000000001;
where delta is some number much smaller than you care about in your program. Then for greater than comparisons include it
if (c >= (5.1 + delta)) printf("OK");
|
|
|
|
|
Kwanalouie wrote: float delta = 0.000000001;
Correctly defined as epsilon.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Another approach: Use rational numbers. Use ints for the numerator and denominator. It requires a bit more coding, but your fractional numbers will be exact.
|
|
|
|
|
To create status bar on a dialog which class can be used CStatusBar or CStatusBarCtrl.
I am bit confused
|
|
|
|
|
|
|
Why don't you write a reset member function that does that ?
|
|
|
|
|
See also the Memento design pattern [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi,
How can I send a email message through coding?
|
|
|
|
|
Did U google this ????
you can find it from
<a href="http://www.codeproject.com/KB/aspnet/EmailApplication.aspx">http:
and this also...
[^]
or if u r looking for code only
MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com");
message.To.Add(new MailAddress("recipient1@foo.bar.com"));
message.To.Add(new MailAddress("recipient2@foo.bar.com"));
message.To.Add(new MailAddress("recipient3@foo.bar.com"));
message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
but before asking for help u should google ...
vikas da
|
|
|
|
|
iz ur scrn so sml tht u hve 2 uz txtspk?
|
|
|
|
|
tasumisra wrote: Did U google this ????
you can find it from
But your google was set to ASP.NET but he or she wants for c++?
|
|
|
|
|
I guess he is/was looking for a logic not implimentation
and nobody gonna give him the whole code ...
are you ?????
vikas da
|
|
|
|
|
Did you see other answers?
|
|
|
|
|
Never heard about CP articles search engine [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I also took help from it but could not get somthing that I want
|
|
|
|
|
what else u r looking for ??????
vikas da
|
|
|
|
|
tasumisra wrote: u r
Please avoid using SMS lingo on these boards.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
sure Thanks for reminding me
vikas da
|
|
|
|
|
I think this one http://www.codeproject.com/KB/IP/csmtpconn.aspx[^] maybe helpful.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Click here[^]
You can also search in CP
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
|
MPTP wrote: How can I send a email message through coding?
By looking through the dozens of articles here.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|