D float types operations vs C++ ones

Guillaume Piolat via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 17 12:35:37 PST 2015


On Thursday, 17 December 2015 at 11:50:02 UTC, drug wrote:
> I have two implementation of the same algorithm - D and C++ 
> (that is port of D version). I assume that running these 
> implementations on the same data should give the same results 
> from both. But with some data the results differ (5th decimal 
> digit after point). For my purpose it isn't important and I can 
> ignore this difference. But I'd like to have the same results 
> totally (I mean bit to bit) to easy maintanence of the 
> implementations. Question is - can I rely that D and C++ float 
> types operations should give the same result because D and C 
> are similar or no and I should use more portable way and 
> compare floats with some epsilon?

If you aim for float reproducibility, you will get trouble in 
32-bit vs 64-bit mode, depending on whether the FPU is used or 
not. The FPU promotes to 80-bits code that uses float or double, 
and may get you more precision thus changing the results.


More information about the Digitalmars-d-learn mailing list