[D1] modulo on neg integer
bearophileHUGS at lycos.com
Thu Mar 18 05:19:02 PDT 2010
> If memory serves me right, module is undefined on negative integers.
I think it's defined in D (but it's defined badly).
> int i = -2;
> i%=10; // i=undefined?
> What should I use instead to get i definitely equal to 7?
D outputs -2, Python outputs 8. It's not easy to find a language that outputs 7 there, maybe Malborge language?
> On a sidenote, where can I read about operation order/definitions?
> Like i++, ++i and i%10 not changing i etc.
D acts like C, here. Even when C does something badly. So you can surely find info about ++ and % in C.
More information about the Digitalmars-d-learn