Round floats using round(x), not static_cast<int>(x + 0.5)
authorBenjamin Barenblat <bbaren@google.com>
Fri, 27 May 2022 20:58:38 +0000 (21:58 +0100)
committerBenjamin Barenblat <bbaren@debian.org>
Fri, 27 May 2022 20:58:38 +0000 (21:58 +0100)
commit094927457bd3a844f3599f5ad39d6c2cb90cc372
treee0d8a0010fc252c5453e1aa93c9ffe10540426b7
parent3755ab5eda51f22d3c35cf34b287e9e3f809a1ea
Round floats using round(x), not static_cast<int>(x + 0.5)

Forwarded: yes
Applied-Upstream: https://github.com/abseil/abseil-cpp/commit/d96e287417766deddbff2d01b96321288c59491e

Adding 0.5 to an IEEE float may cause one bit of precision loss, which
is enough to change the result in certain cases. For example,

    static_cast<int>(std::round(0.49999999999999994)) == 0
    static_cast<int>(0.49999999999999994 + 0.5) == 1

The author works at Google. Upstream applied this patch as Piper
revision 369926519 and exported it to GitHub; the Applied-Upstream URL
above points to the exported commit.

Gbp-Pq: Name float-rounding.diff
absl/time/duration_test.cc
absl/time/time.h