From 256cc61a2d3a6f6dbc9f71d1f976fb9ca9306da5 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 15 Mar 2023 21:34:44 -0700 Subject: Enhance documentation about absl::Duration integer division, which truncates, and floating-point multiplication/division, which rounds. PiperOrigin-RevId: 517016481 Change-Id: I3b0c357ea7236f2c0231df5e6b47c742c3f40047 --- absl/time/time.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'absl/time') 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 = 0> Duration& operator*=(T r) { int64_t x = r; -- cgit v1.2.3