approxEqual() has fooled me for a long time...

Basile B. via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 1 12:43:57 PDT 2016


On Wednesday, 20 October 2010 at 10:32:06 UTC, Lars T. 
Kyllingstad wrote:
> (This message was originally meant for the Phobos mailing list, 
> but for some reason I am currently unable to send messages to 
> it*.  Anyway, it's probably worth making others aware of this 
> as well.)
>
> In my code, and in unittests in particular, I use 
> std.math.approxEqual() a lot to check the results of various 
> computations.  If I expect my result to be correct to within 
> ten significant digits, say, I'd write
>
>   assert (approxEqual(result, expected, 1e-10));
>
> Since results often span several orders of magnitude, I usually 
> don't care about the absolute error, so I just leave it 
> unspecified.  So far, so good, right?
>
> NO!
>
> I just discovered today that the default value for 
> approxEqual's default absolute tolerance is 1e-5, and not zero 
> as one would expect.  This means that the following, quite 
> unexpectedly, succeeds:
>
>   assert (approxEqual(1e-10, 1e-20, 0.1));
>
> This seems completely illogical to me, and I think it should be 
> fixed ASAP.  Any objections?
>
>
> Changing it to zero turned up fifteen failing unittests in 
> SciD. :(
>
> -Lars
>
>
> * Regarding the mailing list problem, Thunderbird is giving me 
> the following message:
>
>   RCPT TO <phobos at puremagic.com> failed:
>   <phobos at puremagic.com>: Recipient address rejected:
>   User unknown in relay recipient table
>
> Are anyone else on the lists seeing this, or is the problem 
> with my mail server?

Just a hint don't use approxEqual() to compare GUI object 
coordinates >!<


More information about the Digitalmars-d mailing list