[Issue 350] Modulo for negative values is undefined
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Sep 16 23:35:52 PDT 2006
http://d.puremagic.com/issues/show_bug.cgi?id=350
------- Comment #2 from deewiant at gmail.com 2006-09-17 01:35 -------
import std.stdio : writefln;
import std.stdio : writefln;
void main() {
writefln(-1 % 10);
writefln(-1 % 5);
writefln(-1 % 3);
writefln(-1 % 2);
writefln(-2 % 8);
writefln(-28 % 7);
writefln(-1 % -1);
writefln(-2 % -2);
writefln(-9 % -2);
writefln(8 % -2);
writefln(16 % -2);
writefln(9 % -2);
writefln(5 % -4);
}
--
Where both values are negative, it gives the correct answer.
Where only the dividend or divisor is negative, it appears to return
(remainder-divisor) instead of just the remainder. Following your link, it
seems that this is the so-called "trunc-mod", common in many other programming
languages.
I'm sorry, I was in a bit of a hurry when I posted this report and couldn't be
bothered to take a detailed look at the issue.
Anyhoo, a mention in the spec would be nice.
--
More information about the Digitalmars-d-bugs
mailing list