Skip to content

Commit c537daf

Browse files
gengjiawenBethGriggs
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]> Signed-off-by: Beth Griggs <[email protected]>
1 parent 247700f commit c537daf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/node_platform.cc

+4-4
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();
@@ -378,8 +378,8 @@ bool PerIsolatePlatformData::FlushForegroundTasksInternal() {
378378
while (std::unique_ptr<DelayedTask> delayed =
379379
foreground_delayed_tasks_.Pop()) {
380380
did_work = true;
381-
uint64_t delay_millis =
382-
static_cast<uint64_t>(delayed->timeout + 0.5) * 1000;
381+
uint64_t delay_millis = llround(delayed->timeout * 1000);
382+
383383
delayed->timer.data = static_cast<void*>(delayed.get());
384384
uv_timer_init(loop_, &delayed->timer);
385385
// Timers may not guarantee queue ordering of events with the same delay if

0 commit comments

Comments
 (0)