This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Bizarre output.
- From: Antonio Coralles <noche dot suapie at reflex dot at>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 30 Mar 2005 01:16:47 +0200
- Subject: Re: Bizarre output.
- References: <fc.3b9aca006b2d42243b9aca0024422d6b.428315a@reflex.at> <4249D2EA.4080500@reflex.at> <fc.3b9aca00f5c969e73b9aca0024422d6b.428332a@reflex.at>
corey taylor wrote:
> This is one method of fuzzy floating point equates using a
> magnitude-based epsilon.
>
> const double fuzzyEpsilon = 0.000001;
What value of fuzzyEpsilon is appropriate for float / long double ? I
guess there is somkind of mathematical law in calculating it's value
from sizeof(value_type) ... Or is 0.000001 just an educated guess ?
>
> /**
> Computes an appropriate epsilon for comparing a and b.
> */
> inline double eps(double a, double b) {
> // For a and b to be nearly equal, they must have nearly
> // the same magnitude. This means that we can ignore b
> // since it either has the same magnitude or the comparison
> // will fail anyway.
> (void)b;
If never seen this kind of cast before ... Is this statndard c/c++ or is
it an gcc extension ? What is the effect of it ?
> const double aa = abs(a) + 1;
> if (aa == inf()) {
> return fuzzyEpsilon;
> } else {
> return fuzzyEpsilon * aa;
> }
> }
>
> inline bool fuzzyEq(double a, double b) {
> return (a == b) || (abs(a - b) <= eps(a, b));
> }
>
> corey
>
antonio