Comment #0 by m.helvensteijn — 2009-07-12T01:33:00Z
Specify what kind of integer division D uses. The description is ambiguous when one or both operands of / are negative. So, in other words, what does D return from:
3 / 2
3 / -2
-3 / 2
-3 / -2
Such information should be part of the language specification.
Comment #1 by m.helvensteijn — 2009-07-12T14:11:52Z
I've ran the following test:
----------------------------------
import std.stdio;
int main() {
writefln(8/3);
writefln(8/(-3));
writefln((-8)/3);
writefln((-8)/(-3));
writefln(8%3);
writefln(8%(-3));
writefln((-8)%3);
writefln((-8)%(-3));
return 0;
}
----------------------------------
outputs the following
----------
2
-2
-2
2
2
2
-2
-2
----------
So DMD uses truncated division. The quotient rounds towards zero and the remainder has the same sign as the dividend.
Comment #2 by smjg — 2009-07-14T16:30:04Z
Changing URL since this is a D1 spec issue just the same.
But you could well ask why it defines it as undefined for % but makes no comment at all (even on whether it's rounded up, down or off for +ve operands) for /.
I've felt for ages that the programmer ought to have the choice between trunc and floor versions for both
http://www.digitalmars.com/d/archives/digitalmars/D/13125.html
but that's another matter.