Mail Archives: djgpp/1999/05/31/14:20:25
El día Sat, 29 May 1999 22:13:07 +0200, Christian Hofrichter
<ChristianHofrichter AT gmx DOT de> escribió:
>Another problem is the limited precision. Let's say some fp-operations
>should return 100.0 but return 99.9999998 due to precision problems. If
>I must compare this value (e.g in a loop) to define an end-condition I
>need a comparing methode which says that 99.9999998 is equal to 100.0
>and aborts the loop. Is this possible ? Otherwise testing if the
>variable is greater or equal to 100.0 would fail and the loop would be
>continued.
/* Assuming that you are using doubles, use a multiple of DBL_EPSILON.
The factor should be similar to the absolute value of the numbers you
are working with. There are other XXX_EPSILON constants defined for
other data types */
/* comparisons should look like this */
if (fabs(value - 100.0) < (100.0 * DBL_EPSILON)) { ... }
Regards,
GUILLE
----
Guillermo Rodriguez Garcia
XXguille AT XXiies DOT XXes (ya sabes :-)
- Raw text -