Lead to inaccurate comparison, using EPSILON to correct.#350
Conversation
| else | ||
| interval = TIMEVAL_SUBTRACT(*now, start_tv) / 1000000.0; | ||
| assert(diff <= interval); | ||
| assert(diff <= interval + std::numeric_limits<double>::epsilon()); |
There was a problem hiding this comment.
After investigation it seems like this is not an accurate method for comparaison between doubles less than 1.0, and it is possible to obtain interval == 0.0 so it may not be accurate enough for this comparaison. At https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/, the author explains how float(pi)+sin(float(pi)) is more accurate than float(pi) to pi. I would suggest to compare double(interval)+sin(double(interval)) to double(diff)+sin(double(diff))... but I didn't check if the results would be in fact more accurate. What do you think?
|
Hello @devnexen, after some tests, it seems like your suggestion is the most accurate one among a few others. I will thus publish your commit soon by crediting it to you. Talk to you soon and thank you for the contribution! |
|
@W0naN0w Would you mind publishing as a gist and linking here the test code you used to determine what methods were accurate for comparison here? |
|
@dmiller-nmap Of course! Sorry for yesterday I had a rough day. Here is the test I used to come to this conclusion: Gist link. You can find the output of the tests at the same place: Gist output link. |
No description provided.