[D-runtime] FPU in core.time

Martin Nowak dawg at dawgfoto.de
Sun Jan 15 21:00:24 PST 2012


There are some failing unittests in core.time.

core.time(1754):
     unittest
     {
         immutable curr = TickDuration.currSystemTick;
         TickDuration t1 = curr;
         immutable t2 = curr + curr;
         t1 *= 2;
         assert(t1 == t2);

         t1 = curr;
         t1 *= 2.0; //<- This relies on 80-bit arithmetic and might fail  
since it is done on SSE
         assert(t1 == t2);
     }


core.time(1523):
     {
         enum unitsPerSec = convert!("seconds", units)(1);

         if(ticksPerSec >= unitsPerSec)
             return TickDuration(cast(long)(length * (ticksPerSec /  
cast(real)unitsPerSec)));
         else
             return TickDuration(cast(long)(length / (unitsPerSec /  
cast(real)ticksPerSec)));
     }

This fails it's unittest on my Windows machine due to limited precision  
 from the double division.
The separate branches were originally used with integer arithmetic but it  
seems to me that they
are no longer needed since the calculation is done in floating point now.


More information about the D-runtime mailing list