[D-runtime] FPU in core.time

Martin Nowak dawg at dawgfoto.de
Mon Jan 16 08:09:26 PST 2012


On Mon, 16 Jan 2012 08:52:06 +0100, Jonathan M Davis <jmdavisProg at gmx.com>  
wrote:

> On Monday, January 16, 2012 06:00:24 Martin Nowak wrote:
>> 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);
>>      }
>
> So, how far off can they be? Only by 1? Or can it be more? I'd think  
> that it
> would just be 1 at the most, but given that it's a multiple of 2, I  
> really
> would have thought that it would have been fine in the first place. So I  
> don't
> know. But the normal trick of checking against something like 1e-5  
> doesn't
> make sense here, since TickDuration holds a long, not a floating point  
> value.
>
The intermediate calculation is done with 64-bit wide floats.
The mantissa has 53-bits so your integral gets rounded to that precision.
How much off your value is depends on how big you value is.
At maximum for long it is (2 ^^ (63 - 53)) / 2 = 512.

> - Jonath
> _______________________________________________
> D-runtime mailing list
> D-runtime at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/d-runtime


More information about the D-runtime mailing list