BigInt divMod is wrong for negative first argument
NonNull
non-null at use.startmail.com
Fri Aug 18 16:14:02 UTC 2023
On Friday, 18 August 2023 at 12:19:04 UTC, Timon Gehr wrote:
> Another issue is that `x % 0` crashes with a division by zero
> error, though naturally the result would be just `x`.
Yes, as the congruence class of x is just {x} in this case.
So leaving the / and % operators as they are for BigInt so as to
be consistent with the broken definition of / and % for int for
negative arguments inherited from C seems to be something D has
to be stuck with, so as not to half fix the problem.
But the divMod method could be made to do the right thing, and
the existing divMod method could be renamed divRem.
More information about the Digitalmars-d
mailing list