This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bizarre output.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]