Login  Register

Re: comparison.hpp close and close_enough

Posted by Ferdinando M. Ametrano-3 on Jun 11, 2008; 4:02pm
URL: http://quantlib.414.s1.nabble.com/comparison-hpp-close-and-close-enough-tp6105p6106.html

On Mon, Jun 9, 2008 at 5:20 PM, xinonnet <[hidden email]> wrote:
> The close functions return false even for two VERY close numbers
> [...]
> It only returns true for identical numbers, which defeats the purpose of
> these functions.

the purpose of the close function is to be a _robust_ substitute for
the == comparison operator. Even if two numbers are "equal" from an
end-user point of view == might return false because of machine
precision issues. In order to solve this problem Knuth has provided
some advice which Luigi implemented in the close function.

> close( 0, QL_EPSILON ) returns false
> close( QL_EPSILON, QL_EPSILON * 10 ) returns false

With the above explanation in mind it should be clear that zero and
QL_EPSILON are not equal, and the same apply to QL_EPSILON and
QL_EPSILON * 10

Naming the function "close" might have been not ideal, but your
mileage might vary. I'll leave to Luigi when he's back to add more
info and/or rename the functions.

ciao -- Nando

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users