| GNU Scientific Library Reference Manual - Revised Second Edition (v1.8) by M. Galassi, J. Davies, J. Theiler, B. Gough, G. Jungman, M. Booth, F. Rossi Paperback (6"x9"), 636 pages, 60 figures ISBN 0954161734 RRP £24.99 ($39.99) |
4.8 Approximate Comparison of Floating Point Numbers
It is sometimes useful to be able to compare two floating point numbers approximately, to allow for rounding and truncation errors. The following function implements the approximate floating-point comparison algorithm proposed by D.E. Knuth in Section 4.2.2 of Seminumerical Algorithms (3rd edition).
- Function: int gsl_fcmp (double x, double y, double epsilon)
- This function determines whether x and y are approximately
equal to a relative accuracy epsilon.
The relative accuracy is measured using an interval of size 2 \delta, where \delta = 2^k \epsilon and k is the maximum base-2 exponent of x and y as computed by the function
frexp.If x and y lie within this interval, they are considered approximately equal and the function returns 0. Otherwise if x < y, the function returns -1, or if x > y, the function returns +1.
The implementation is based on the package
fcmpby T.C. Belding.
| ISBN 0954161734 | GNU Scientific Library Reference Manual - Revised Second Edition (v1.8) | See the print edition |