Skip to content

Commit d711b97

Browse files
gengjiawenrefack
authored andcommitted
src: apply clang-tidy rule bugprone-incorrect-roundings
PR-URL: #26885 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 5c2ee4e commit d711b97

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/node_platform.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "debug_utils.h"
66
#include "util.h"
77
#include <algorithm>
8+
#include <cmath>
89
#include <memory>
910

1011
namespace node {
@@ -126,8 +127,7 @@ class WorkerThreadsTaskRunner::DelayedTaskScheduler {
126127
delay_in_seconds_(delay_in_seconds) {}
127128

128129
void Run() override {
129-
uint64_t delay_millis =
130-
static_cast<uint64_t>(delay_in_seconds_ + 0.5) * 1000;
130+
uint64_t delay_millis = llround(delay_in_seconds_ * 1000);
131131
std::unique_ptr<uv_timer_t> timer(new uv_timer_t());
132132
CHECK_EQ(0, uv_timer_init(&scheduler_->loop_, timer.get()));
133133
timer->data = task_.release();
@@ -387,8 +387,8 @@ bool PerIsolatePlatformData::FlushForegroundTasksInternal() {
387387
while (std::unique_ptr<DelayedTask> delayed =
388388
foreground_delayed_tasks_.Pop()) {
389389
did_work = true;
390-
uint64_t delay_millis =
391-
static_cast<uint64_t>(delayed->timeout + 0.5) * 1000;
390+
uint64_t delay_millis = llround(delayed->timeout * 1000);
391+
392392
delayed->timer.data = static_cast<void*>(delayed.get());
393393
uv_timer_init(loop_, &delayed->timer);
394394
// Timers may not guarantee queue ordering of events with the same delay if

0 commit comments

Comments
 (0)