lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Aug 17, 2021 at 9:17 PM Viacheslav Usov <via.usov@gmail.com> wrote:

> Fortran was made for IBM 704, whose fixed point division had a
> different rule, viz., "the sign of the remainder always agrees with
> the sign of the dividend"

This is wrong, and it is actually the same rule. I made a mistake here:

> 3 div -2 = -2 (rem 2)

Obviously (-2) * (-2) + 2 = 6, not 3. The correct operation is

3 div -2 = -1 (rem 1)

so that (-1) * (-2) + 1 = 3.

Thus the Fortran rule followed the IBM 701/704 CPU rule. And so did C,
half a century later.

Cheers,
V.