Should % ever "overflow"?
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jun 26 00:09:29 PDT 2016
On Sunday, 26 June 2016 at 05:44:53 UTC, deadalnix wrote:
> Except for mathematica, these are all irrelevant. The claim is
> that programming languages and CPU define % in some way, not
> that mathematician do it the same way.
Well, the CPU does not define it. It is just that C botchered it
by leaving "%" implementation defined up til 1999, where they
went with the truncated reminder and not the floored modulo
operator. In system level programming you usually need the modulo
(reminder for floored division) and not the C-style reminder
(reminder from truncated division):
https://en.wikipedia.org/wiki/Modulo_operation
Interestingly Simula, Ada, Fortran, Common Lisp and other high
level languages provids both "rem(x,y)" and "mod(x,y)", which is
the right thing to do.
More information about the Digitalmars-d
mailing list