diff options
author | Abseil Team <absl-team@google.com> | 2021-04-23 05:02:23 -0700 |
---|---|---|
committer | Dino Radaković <dinor@google.com> | 2021-04-23 08:49:16 -0700 |
commit | d96e287417766deddbff2d01b96321288c59491e (patch) | |
tree | 2a5aa297bf5be0f749db6368675ef723d5b4322a /absl/time | |
parent | e38e1aae3866a4ae3a41ccb38d3f05618ea30ca4 (diff) |
Export of internal Abseil changes
--
f825cf3feb6db06522b2b4ee785de7dfa325780d by Martijn Vels <mvels@google.com>:
Move Cordz test helpers to cordz_test_helpers library
PiperOrigin-RevId: 370059941
--
5080249da6a4f5cc2b546aed48503fd028670379 by Martijn Vels <mvels@google.com>:
Add new Cordz instrumentation on AppendTree.
PiperOrigin-RevId: 369968167
--
21092b889fad34ec605894e311b436d5f417456f by Benjamin Barenblat <bbaren@google.com>:
Round floats using round(x), not static_cast<int>(x + 0.5)
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
PiperOrigin-RevId: 369926519
GitOrigin-RevId: f825cf3feb6db06522b2b4ee785de7dfa325780d
Change-Id: Ib78ce1faec79f06578933db5dc6fc05de043ead1
Diffstat (limited to 'absl/time')
-rw-r--r-- | absl/time/duration_test.cc | 4 | ||||
-rw-r--r-- | absl/time/time.h | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/absl/time/duration_test.cc b/absl/time/duration_test.cc index fb28fa98..a3617e74 100644 --- a/absl/time/duration_test.cc +++ b/absl/time/duration_test.cc @@ -1320,7 +1320,7 @@ TEST(Duration, SmallConversions) { EXPECT_EQ(absl::ZeroDuration(), absl::Seconds(0)); // TODO(bww): Is the next one OK? - EXPECT_EQ(absl::ZeroDuration(), absl::Seconds(0.124999999e-9)); + EXPECT_EQ(absl::ZeroDuration(), absl::Seconds(std::nextafter(0.125e-9, 0))); EXPECT_EQ(absl::Nanoseconds(1) / 4, absl::Seconds(0.125e-9)); EXPECT_EQ(absl::Nanoseconds(1) / 4, absl::Seconds(0.250e-9)); EXPECT_EQ(absl::Nanoseconds(1) / 2, absl::Seconds(0.375e-9)); @@ -1330,7 +1330,7 @@ TEST(Duration, SmallConversions) { EXPECT_EQ(absl::Nanoseconds(1), absl::Seconds(0.875e-9)); EXPECT_EQ(absl::Nanoseconds(1), absl::Seconds(1.000e-9)); - EXPECT_EQ(absl::ZeroDuration(), absl::Seconds(-0.124999999e-9)); + EXPECT_EQ(absl::ZeroDuration(), absl::Seconds(std::nextafter(-0.125e-9, 0))); EXPECT_EQ(-absl::Nanoseconds(1) / 4, absl::Seconds(-0.125e-9)); EXPECT_EQ(-absl::Nanoseconds(1) / 4, absl::Seconds(-0.250e-9)); EXPECT_EQ(-absl::Nanoseconds(1) / 2, absl::Seconds(-0.375e-9)); diff --git a/absl/time/time.h b/absl/time/time.h index 2df68581..48982df4 100644 --- a/absl/time/time.h +++ b/absl/time/time.h @@ -1352,7 +1352,7 @@ constexpr Duration MakeDuration(int64_t hi, int64_t lo) { inline Duration MakePosDoubleDuration(double n) { const int64_t int_secs = static_cast<int64_t>(n); const uint32_t ticks = static_cast<uint32_t>( - (n - static_cast<double>(int_secs)) * kTicksPerSecond + 0.5); + std::round((n - static_cast<double>(int_secs)) * kTicksPerSecond)); return ticks < kTicksPerSecond ? MakeDuration(int_secs, ticks) : MakeDuration(int_secs + 1, ticks - kTicksPerSecond); |