[Issue 5262] divide by 0 in std.datetime's Ticks.toMicroseconds()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Nov 23 20:12:07 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5262
Jonathan M Davis <jmdavisProg at gmx.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jmdavisProg at gmx.com
--- Comment #1 from Jonathan M Davis <jmdavisProg at gmx.com> 2010-11-23 20:10:42 PST ---
I'm pretty certain that the fix is to change toMicroseconds to
T toMicroseconds(T)() if (isIntegral!T && T.sizeof >= 4)
{
enum unitsPerSec = 1_000_000;
if(ticksPerSec >= unitsPerSec)
return value / (ticksPerSec / unitsPerSec);
else
return value * (unitsPerSec / ticksPerSec);
}
All of the toX() functions should be like this with differing unitsPerSec.
However, microseconds is probably the only one where it's actually an issue.
I did a templated version in my datetime code which is essentially the function
above, adjusted to take multiple units into account. Once my datetime code has
been put into Phobos, replacing the current std.datetime, this bug should be
fixed. But the above version of toMicroseconds should fix the problem for now.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list