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

Austin Hastings ah08010-d at yahoo.com
Wed Oct 20 05:33:13 PDT 2010


On 10/20/2010 6:57 AM, Don wrote:
>
> I'm personally pretty upset about the existence of that function at all.
> My very first contribution to D was a function for floating point
> approximate equality, which I called approxEqual.
> It gives equality in terms of number of bits. It gives correct results
> in all the tricky special cases. Unlike a naive relative equality test
> involving divisions, it doesn't fail for values near zero. (I _think_
> that's the reason why people think you need an absolute equality test as
> well).
> And it's fast. No divisions, no poorly predictable branches.
>
> Unfortunately, somebody on the ng insisted that it should be called
> feqrel(). Stupidly, I listened. And now nobody uses my masterpiece
> because it has a totally sucky name.
>

So here I am, needing to get some test cases passing with floating 
comparison, and how fortuitous that you mentioned writing this already.

Naturally, I tried it, with floats as my default type:

d:\Devel\D\dmd2\windows\bin\..\..\src\phobos\std\math.d(3286): Error: 
function std.math.feqrel!(const(float)).feqrel has no return statement, 
but is expected to return a value of type int

Is there a patch?

=Austin


More information about the Digitalmars-d mailing list