diff options
author | Abseil Team <absl-team@google.com> | 2023-03-15 21:34:44 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-03-15 21:35:33 -0700 |
commit | 256cc61a2d3a6f6dbc9f71d1f976fb9ca9306da5 (patch) | |
tree | 5535f00aee71f28a116ccb2fd907ecf7f8edda5f /absl | |
parent | ab0e3e8e1fe0d71c2675b9e8c5aa48f19a1f716a (diff) |
Enhance documentation about absl::Duration integer division, which
truncates, and floating-point multiplication/division, which rounds.
PiperOrigin-RevId: 517016481
Change-Id: I3b0c357ea7236f2c0231df5e6b47c742c3f40047
Diffstat (limited to 'absl')
-rw-r--r-- | absl/time/time.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/absl/time/time.h b/absl/time/time.h index 01b55322..89b1b2af 100644 --- a/absl/time/time.h +++ b/absl/time/time.h @@ -187,7 +187,12 @@ class Duration { Duration& operator%=(Duration rhs); // Overloads that forward to either the int64_t or double overloads above. - // Integer operands must be representable as int64_t. + // Integer operands must be representable as int64_t. Integer division is + // truncating, so values less than the resolution will be returned as zero. + // Floating-point multiplication and division is rounding (halfway cases + // rounding away from zero), so values less than the resolution may be + // returned as either the resolution or zero. In particular, `d / 2.0` + // can produce `d` when it is the resolution and "even". template <typename T, time_internal::EnableIfIntegral<T> = 0> Duration& operator*=(T r) { int64_t x = r; |