Get Time
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Absolute Error and Relative Error | Reply
I have problems understanding the deference between these two types of errors. Actually I do understand the reasons for the difference but I can't get why the two functions solve these cases. I believe 1e-9 is the EPS to use since misof used it in his latest code
for SRM 283:
#define EPS (1e-9)

then he did:
if (abs(X[i]-(*it)) <= D + EPS) now++;

I think this is only a test for absolute error. Why he didn't used the other test too?
And if you can please give me some source code I can trust when comparing doubles...

Before I saw the article I used:
#define EQ(a,b) ((fabs(a-b)<DBL_EPSILON)?(1):(0))
Unfortunately DBL_EPSILON (defined in float.h) is 1e-16 which coused my SRM 283 600p to fail. Then when I changed it to 1e-9 it was fine. However I still don't get why misof didn't use testig for a relative error?

Re: Absolute Error and Relative Error (response to post by vesko) | Reply
If the values you compare are greater than one, then an absolute error of 1e-9 is smaller than a relative error of 1e-9. In other words, if a,b>1 and abs(a-b)<1e-9, there is no need to check whether b is between a*(1-1e-9) and a*(1+1e-9), it will always be true.

The numbers I was comparing in this task were between sqrt(2)/2 and 1000000*sqrt(2), and they were almost exact. Thus I decided that testing for an absolute error 1e-9 will always be accurate enough. (Note that for these numbers, adding/subtracting 1e-9 changes the value of the variable.)