Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@

/* $Id$ */

#include <limits>

#include "timing.h"
#include "NmapOps.h"
#include "utils.h"
Expand Down Expand Up @@ -437,7 +439,7 @@ void RateMeter::update(double amount, const struct timeval *now) {
interval = MAX(current_rate_history, diff);
else
interval = TIMEVAL_SUBTRACT(*now, start_tv) / 1000000.0;
assert(diff <= interval);
assert(diff <= interval + std::numeric_limits<double>::epsilon());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

/* If we record an amount in the very same instant that the timer is started,
there's no way to calculate meaningful rates. Ignore it. */
if (interval == 0.0)
Expand Down