[Issue 3165] What kind of integer division does D use?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 12 14:11:53 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3165
--- Comment #1 from Michiel Helvensteijn <m.helvensteijn at gmail.com> 2009-07-12 14:11:52 PDT ---
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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list