[Issue 6725] core.time.dur should accept floating point

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jul 21 15:02:25 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=6725

--- Comment #19 from Vladimir Panteleev <thecybershadow at gmail.com> ---
>  However, it's definitely more palatable than supporting floating point values
> directly, because that would just encourage bad practices.

Honestly, I think this is a poor argument. People who are in the mindset of
doing *calculations* with floating-point values are likely going to do that
anyway, using casts or using inferior precision (Walter stepped into this one
already) or creating their own wrappers if they are so bent on it. Not
accepting floating-point types for Duration conversions goes only a little way
of stopping such misuse, and a long way towards annoying D users who have a
valid use case for it, and forcing them to risk writing incorrect code because
doing so correctly is not exactly trivial.

To reiterate, not all uses of Duration involve precise calculations. If the
initial data comes from time measurements collected by the program, or
ultimately the results are going to be used for timers or delays, minute errors
will be negligible compared to computers' actual clock/timer resolutions.

I think that going as far as rejecting floating-point values because someone
*might* mis-use them is an over-reaction. I think the problem can be placated
by adding a reminder to the documentation that performing *calculations* with
floating-point values can result in rounding errors.

--


More information about the Digitalmars-d-bugs mailing list