Commit 5a9b1bb0 authored by Nathan Lanza's avatar Nathan Lanza Committed by Facebook GitHub Bot

Convert implicit cast from `long` to `double` to a `static_cast`

Summary:
This code implicitly casts a `long` to `double` but a `double`
can not accurately represent an integer above `2^53` as
the mantissa only stores that many digits. At `2^53 + 1`
`double`s increment by `2`. Thus this cast is lossy. Though,
casting a single value `LONG_MAX` to a `double` is and
being off by one doesn't cause any harm here.

Reviewed By: ispeters

Differential Revision: D25654006

fbshipit-source-id: 3d84092f1786d7879dd48d73af8edbbc80bb3585
parent 8f2210a5
...@@ -207,7 +207,7 @@ Duration retryingJitteredExponentialBackoffDur( ...@@ -207,7 +207,7 @@ Duration retryingJitteredExponentialBackoffDur(
auto dist = std::normal_distribution<double>(0.0, jitter_param); auto dist = std::normal_distribution<double>(0.0, jitter_param);
auto jitter = std::exp(dist(rng)); auto jitter = std::exp(dist(rng));
auto backoff_rep = jitter * backoff_min.count() * std::pow(2, n - 1); auto backoff_rep = jitter * backoff_min.count() * std::pow(2, n - 1);
if (UNLIKELY(backoff_rep >= std::numeric_limits<Duration::rep>::max())) { if (UNLIKELY(backoff_rep >= static_cast<double>(backoff_max.count()))) {
return std::max(backoff_min, backoff_max); return std::max(backoff_min, backoff_max);
} }
auto backoff = Duration(Duration::rep(backoff_rep)); auto backoff = Duration(Duration::rep(backoff_rep));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment