approxEqual() has fooled me for a long time...
Don
nospam at nospam.com
Wed Oct 20 11:53:19 PDT 2010
Andrei Alexandrescu wrote:
> On 10/20/10 10:52 CDT, Don wrote:
>> I don't think it's possible to have a sensible default for absolute
>> tolerance, because you never know what scale is important. You can do a
>> default for relative tolerance, because floating point numbers work that
>> way (eg, you can say they're equal if they differ in only the last 4
>> bits, or if half of the mantissa bits are equal).
>>
>> I would even think that the acceptable relative error is almost always
>> known at compile time, but the absolute error may not be.
>
> I wonder if it could work to set either number, if zero, to the smallest
> normalized value. Then proceed with the feqrel algorithm. Would that work?
>
> Andrei
feqrel actually treats zero fairly. There are exactly as many possible
values almost equal to zero, as there are near any other number.
So in terms of the floating point number representation, the behaviour
is perfect.
Thinking out loud here...
I think that you use absolute error to deal with the difference between
the computer's representation, and the real world. You're almost
pretending that they are fixed point numbers.
Pretty much any real-world data set has a characteristic magnitude, and
anything which is more than (say) 10^^50 times smaller than the average
is probably equivalent to zero.
More information about the Digitalmars-d
mailing list