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

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


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

--- Comment #20 from Jonathan M Davis <jmdavisProg at gmx.com> ---
But honestly, is it really all that hard to just write a wrapper function?

auto floatDur(string units)(real value)
    if(is(typeof(convert!(units, "hnsecs")(1))))
{
    enum hnsecsPer = convert!(units, "hnsecs")(1);
    return hnsecs(cast(long)(value * hnsecsPer));
}

If you really want that, you can just put it in your own code without needing
to make any adjustments to core.time and without making it so that we have to
support (and therefore potentially encourage) the use of floating point values
for time. And it avoids all of the ugliness in the previous examples. You just
have to do floatDur(1.5001), and you have what you want except that the name of
the function is slightly different, and you have to put that function in your
own code somewhere.

I can understand wanting this functionality in core.time, but I really think
that we shouldn't be supporting or encouraging the use of floating point values
for time as it's generally bad practice. We can't stop anyone from doing it, as
shown above, so anyone who wants to do it, can do it, but we don't have to
directly support it either.

--


More information about the Digitalmars-d-bugs mailing list