Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Walter, I'll take any chance I can get to say: thank you for creating D! One thing I was wondering about is the limits of compile time execution.

How does the D compiler ensure correctness if the machine the compiler runs on is different from the machine the program will execute on?

For example, how does the compiler know that "int s = sum(100000, 1000000)" is the same value on every x86 machine?

I'm thinking there could be subtle differences between generations of CPU, how can a compiler guarantee that a computation on the host machine will result in the same value on the target machine in practice, or is it assuming that host and target are sufficiently similar, as long as the architecture matches? (which is fine, I'm wondering as to what approaches exist)



> thank you for creating D!

My pleasure!

> is the same value on every x86 machine?

It's the same value on all machines, because integer types are fixed size (not implementation dependent) and 2's complement arithmetic is mandated.

Floating point results can vary, however, due to different orders in which constants are evaluated. The x87, for example, evaluates to a higher precision and then rounds it only when writing to memory.


I'll second thanking you for making D. I still haven't found a language with more compile time capabilities that I can/would actually use. So I'm still using D.

Any thoughts on adding something like Zig's setFloatMode(strict)? I have a project idea or 2 where for some of the computation I need determinism then performance. But very much still need the performance floating point can provide.


Thanks for the kind words!

Your best bet for floating point determinism is to stick with doubles. Then, in 64 bit code, the double math will be done with the XMM registers and instructions, which will stick with 64 bit arithmetic.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: