[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Bug modulo operator on negative numbers
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 17 Aug 2021 08:57:06 -0300
> Then you are in for a lot of pain ;-> as it seems C99 mandates
> rounding division towards zero ( previously it was imp-def-beh ).
C does that mainly because that is what most (all?) CPUs do. CPUs do
that because that division is the only one that respects the law
(-a)/b == a/(-b) == -(a/b), which simplifies the hardware. (It can
always divide positive integers and apply the proper signal to the
result.)
-- Roberto