Richard R wrote:
> Hi. I am developing plugins for Caligari Truespace software.
> The plugins are DLL's and use MFC. Primitive Itch developed a
> Delphi wrapper, and I helped provide translations from the
> vc++ header files. The wrapper contains exports from the
> tsxapi.dll which the Truespace application uses for plugins.
> Using this wrapper, I can create DLL's for the extension of
> the Truespace application. The problem I am having is with the
> floating point values in the type float. They are making it
> hard to do checks. An example, I get a value from a dll
> function that supposed to return 4.47 for a specific setting
> in the application. Well when I read this value, it reads like
> 4.46999999999997 and I get many similar problems like this. I
> have tried doing variable:= StrToFloat(Format('%.2f',
> [variable])); however it returns the same value. What can I do
> about this? I need to check for 4.47 yet its always returning
> false because of the inaccuracy. Thanks,

There's nothing "bad" or "inaccurate" per se about the values 
you're getting; they're perfectly normal results for floating 
point operations which are inherently imprecise for many values.

In general you cannot expect floating point values to compare 
exactly, so the typical approach is to check whether the values 
are "sufficiently close" to be considered equal for practical 
purposes.

This is often done by subtracting one of the numbers from the 
other and seeing whether or not the result is less than or equal 
to some predetermined "closeness value", usually called "epsilon".

What constitutes "sufficiently close" will depend on your 
situation and applications.

Read more here:

http://en.wikipedia.org/wiki/IEEE_floating-point_standard
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
http://docs.hp.com/en/B3906-90005/ch02s05.html
http://blogs.msdn.com/ericlippert/archive/2005/01/20/357407.aspx


HTH

Stephen Posey
[EMAIL PROTECTED]
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to