Floating point comparisons
[Utilities]


Detailed Description

Macros for comparing floating point numbers. It's a troublesome limitation of C and C++ that floating point comparisons are not very accurate. These macros multiply their arguments by a large number before comparing them, to improve resolution.


Defines

#define EQ(A, B)   ((lrint(A*PRECISION))==(lrint(B*PRECISION)))
#define GT(A, B)   ((lrint(A*PRECISION))>(lrint(B*PRECISION)))
#define GTE(A, B)   ((lrint(A*PRECISION))>=(lrint(B*PRECISION)))
#define LT(A, B)   ((lrint(A*PRECISION))<(lrint(B*PRECISION)))
#define LTE(A, B)   ((lrint(A*PRECISION))<=(lrint(B*PRECISION)))
#define PRECISION   100000.0

Define Documentation

#define EQ A,
 )     ((lrint(A*PRECISION))==(lrint(B*PRECISION)))
 

TRUE iff A and B are equal to within PRECISION

#define GT A,
 )     ((lrint(A*PRECISION))>(lrint(B*PRECISION)))
 

TRUE iff A is greater than B, subject to PRECISION

#define GTE A,
 )     ((lrint(A*PRECISION))>=(lrint(B*PRECISION)))
 

TRUE iff A is greater than or equal B, subject to PRECISION

#define LT A,
 )     ((lrint(A*PRECISION))<(lrint(B*PRECISION)))
 

TRUE iff A is less than B, subject to PRECISION

#define LTE A,
 )     ((lrint(A*PRECISION))<=(lrint(B*PRECISION)))
 

TRUE iff A is less than or equal to B, subject to PRECISION

#define PRECISION   100000.0
 

Precision of comparison. The number of zeros to the left of the decimal point determines the accuracy of the comparison in decimal places to the right of the point. E.g. precision of 100000.0 gives a comparison precision of within 0.000001


Generated on Thu Dec 13 13:55:22 2007 for Stage by  doxygen 1.4.6