Re: problem assigning double as defaultvalue

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Kirill Stoimenov (kirill_stoimenov_at_yahoo.com)
Date: 04/27/04


Date: 27 Apr 2004 14:09:13 -0700

Hi,

I feel like the word ignorance is used a bit strong here. I know that
some people know more than others, but I think we all deserve respect
and people come to this newsgroup not to be treaded as lower form of
life but to get help...

Kirill

"Alexander Nickolov" <agnickolov@mvps.org> wrote in message news:<OIpVdVcKEHA.3916@TK2MSFTNGP10.phx.gbl>...
> It's more like ignorance on you part really... This behavior is
> by design - floating point arithmetics is imprecise. You should
> never compare floating point numbers directly (especially the
> results of computations). Have you studied interval arithmetics?
> What about computational methods? You should have studied
> about error accumulation... Anyway, the point is, you should
> compare two floating point numbers by subtracting them and
> comparing the absolute of the difference against your precision
> threshold. If it is under the threshold, the numbers are the same,
> otherwise they differ.
>
> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD
> email: agnickolov@mvps.org
> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================
> "Sascha Herpers" <formefromnews@brainpowered.de> wrote in message
> news:c6bavj$a8mkg$1@ID-144102.news.uni-berlin.de...
> > > Looks like it gets stored as float somewhere along the line, either in
> > > the TLB or in MIDL internal structures. Or, MIDL has problem accurately
> > > parsing floating point literals. You see, double gives you precision to
> > > about 15 decimal digits, and float provides only 7-8. The number you get
> > > from default value is accurate to 7 decimal digits.
> > I see. That's probably the reason why casting it to double like this:
> > defaultvalue((double) 0.00001)
> > gave a totally different result. MIDL seems to somehow misinterprete the
> > constant...
> >
> > Oh well...just another thing I will mark as "don't worry about it, you
> > can't change it anyways" kind of thing... :(
> >
> > Thanks Igor.
> > Sash



Relevant Pages

  • Re: Comparing floating point values in Java
    ... when comparing floating point values in computers. ... In Java, will unchanged values compare strictly true if equal? ... In strictfp mode, the exact, bit-by-bit, result is predictable from the ...
    (comp.lang.java.programmer)
  • Re: Comparing floating point values in Java
    ... when comparing floating point values in computers. ... In Java, will unchanged values compare strictly true if equal? ... In strictfp mode, the exact, bit-by-bit, result is predictable from the ...
    (comp.lang.java.programmer)
  • Re: addition of 0.7 and 0.1 is not 0.8 CDbl / CStr vbs problem
    ... Comparing floating point values should be done using a tolerance:- ... In other cases the resulting 'near enough' value stored after a calculation ... the situation using CDbl) than to compare with "almost near ... CStr may no longer be what you want. ...
    (microsoft.public.scripting.vbscript)
  • Re: Can anyone repeat this?
    ... incrementing and decrementing by .01 (as represented by the compiler), ... Not a good idea to compare floating points like this though. ...
    (microsoft.public.vc.mfc)
  • Re: Strange basic problem with comparision of two varialbes defined as double
    ... > My application does need to compare a lot of values for accounting purposes. ... store data in floating point format to simplify the problem. ... those fractions representable by binary fractions are ... Your alternatives are to either use a representation that deals with the ...
    (microsoft.public.vstudio.development)