|
|
The fixed point arithmetic operations permit (1) two Durations to be added or subtracted, and (2) a Duration to be multiplied by an integer. These operations yield exact results because Durations are represented internally as fixed point values. Fixed point computation is essential when an action must be performed at precise intervals. For example:
Duration start = Duration(0); Duration end = Duration::days(100) + Duration::seconds(100); Duration delta = Duration::days(1) + Duration::seconds(1); for(Duration d = start; d < end; d += delta){ ... }
will execute exactly 100 times at precise intervals of 86401 second, with no drift occurring due to roundoff.
Two fixed point operations affect the sign of a Duration (but not its magnitude): abs() and unary minus.