Charles McAnany Wrote:

> I noticed that one of the guarantees in TDPL is that any code that is valid 
> in both C
> and D should compile with the same result.

This is almost true (there are few differences, in D fixed-size arrays are 
managed by value instead of by pointer, and global floating point variables are 
initialized to NaN instead of 0), but only where all C compilers themselves 
give the same results.

Floating point operations are based on a standard implementation, but I think 
in practice different optimizations cause different C compilers to not give 
exactly the same result when floating point values are used (even the same CPU 
gives different results if you use the FP stack with 80 bit reals or if you use 
64 bit doubles in SSE registers). So small differences are expected. Your 
program is designed to blow up those small differences.


> It seems D is implicitly converting double to real. Is this the usual 
> behavior?

DMD compiler sometimes uses real values for intermediate values, so such 
differences are not so unexpected.

Bye,
bearophile

Reply via email to