Click here to Skip to main content
15,917,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralWeird <= operation Pin
alex120514-Jan-05 4:08
alex120514-Jan-05 4:08 
GeneralRe: Weird <= operation Pin
basementman14-Jan-05 4:24
basementman14-Jan-05 4:24 
GeneralRe: Weird <= operation Pin
Malcolm Smart14-Jan-05 4:39
Malcolm Smart14-Jan-05 4:39 
GeneralRe: Weird <= operation Pin
Ravi Bhavnani14-Jan-05 6:11
professionalRavi Bhavnani14-Jan-05 6:11 
GeneralRe: Weird <= operation Pin
Malcolm Smart14-Jan-05 13:00
Malcolm Smart14-Jan-05 13:00 
GeneralRe: Weird <= operation Pin
Ravi Bhavnani14-Jan-05 14:52
professionalRavi Bhavnani14-Jan-05 14:52 
GeneralRe: Weird <= operation Pin
Anonymous17-Jan-05 15:26
Anonymous17-Jan-05 15:26 
GeneralRe: Weird <= operation Pin
peterchen16-Jan-05 19:03
peterchen16-Jan-05 19:03 
Is this your actual code? What cmpiler, what settings do you use?

While it is true what was said - floats and doubles are not accurate representations - a simple assignment like yours typically is ok.
(And your ode with default debug/release settings outputs "TRUE" for me).

float and double both use a limited number of digits, certain numbers e.g 1/3, cannot berepresented accurately this way. Also, during calculations, final digits simply get lost. So comparing *results* as replied is a must.

However, you should also consider the alternative:

bool IsEqualRel(double a, double b, double eps = 1e-5)
{
  _ASSERTE(a!= 0 && b != 0);
  if (a==b) return true;
  if (a<0 != b<0) return false;
  return fabs((a-b)/a+b)) < eps;
}

bool IsZero(double a, double eps = 1e-5)
{
  return a==0 || fabs(a) < eps;
}

which works for all magnitudes except comparison to zero (that's why the separate IsZero function).

With the absolute posted by the other guy, 1e-27 == 100e-27 and 10000000000000 != 10000000000001 which is often not what you need when working with numbers in this range.



I never really know a killer from a savior
boost your code || Fold With Us! || sighist | doxygen

QuestionHow to export Symbol from Win Static Library Pin
ashutosh_tripathi14-Jan-05 3:18
ashutosh_tripathi14-Jan-05 3:18 
AnswerRe: How to export Symbol from Win Static Library Pin
Martin Koorts14-Jan-05 3:44
Martin Koorts14-Jan-05 3:44 
GeneralRe: How to export Symbol from Win Static Library Pin
ashutosh_tripathi14-Jan-05 17:49
ashutosh_tripathi14-Jan-05 17:49 
GeneralRe: How to export Symbol from Win Static Library Pin
Martin Koorts16-Jan-05 22:53
Martin Koorts16-Jan-05 22:53 
GeneralOnPaint and CPaintDC Pin
Malcolm Smart14-Jan-05 3:02
Malcolm Smart14-Jan-05 3:02 
GeneralRe: OnPaint and CPaintDC Pin
Ryan Binns14-Jan-05 3:40
Ryan Binns14-Jan-05 3:40 
GeneralRe: OnPaint and CPaintDC Pin
Mike Dimmick14-Jan-05 3:40
Mike Dimmick14-Jan-05 3:40 
GeneralRe: OnPaint and CPaintDC Pin
Malcolm Smart14-Jan-05 4:37
Malcolm Smart14-Jan-05 4:37 
GeneralLoading HTML documents Pin
Hans Ruck14-Jan-05 2:00
Hans Ruck14-Jan-05 2:00 
GeneralPls Help with CMetaFileDC and CScrollView Pin
Dimitris Vikeloudas14-Jan-05 0:41
Dimitris Vikeloudas14-Jan-05 0:41 
QuestionVC6 - bug? Could you try on your Box? Pin
peterchen14-Jan-05 0:24
peterchen14-Jan-05 0:24 
AnswerRe: VC6 - bug? Could you try on your Box? Pin
peterchen14-Jan-05 0:29
peterchen14-Jan-05 0:29 
AnswerRe: VC6 - bug? Could you try on your Box? Pin
Aamir Butt14-Jan-05 0:38
Aamir Butt14-Jan-05 0:38 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
peterchen14-Jan-05 1:24
peterchen14-Jan-05 1:24 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
Aamir Butt16-Jan-05 17:31
Aamir Butt16-Jan-05 17:31 
GeneralRe: VC6 - bug? Could you try on your Box? Pin
peterchen16-Jan-05 18:42
peterchen16-Jan-05 18:42 
AnswerRe: VC6 - bug? Could you try on your Box? Pin
KaЯl14-Jan-05 1:37
KaЯl14-Jan-05 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.