Bug 4682 – [CTFE] Run-time Vs Compile-time of int.min % -1
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-08-19T14:34:00Z
Last change time
2017-02-24T20:34:39Z
Keywords
wrong-code
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-08-19T14:34:54Z
With dmd 2.048 this program gives (on Windows) a runtime error:
int foo(int x, int y) {
return x % y;
}
void main() {
int r = foo(int.min, -1);
}
But the same operation done at compile time gives no errors, and foo returns 0:
int foo(int x, int y) {
return x % y;
}
static assert(foo(int.min, -1) == 0);
void main() {}
So one of the two cases is wrong (or both).
While floating point operations done at compile-time may give slightly different results, I'd like integral operations to give the same results at compile-time and run-time.