[Thread Prev][Thread Next][Index]

Re: [ferret_users] Function MOD : strange behavior



Hi Olivier,

On Thu, Aug 27, 2020 at 4:51 PM Olivier Marti <olivier.marti@xxxxxxxxxxxx> wrote:
[ . . . ]
In computer, there is a difference between the "truncated division" (also called "symmetric") and the "floored division". Most langage implement the truncated division, when the math definition is the "floored division". And I agree that modulo and integer division should be compatible to get (m div n) * n + (m mod n) == m

In Fortran, MOD and MODULO functions have different behaviour with negative numbers !!

Yes, and MOD is symmetric about 0 and MODULO is floored (left-biased). If I remember correctly, MODULO was added to the standard much later than MOD.  As you say, the integer division in most computer languages is the symmetric version and therefore, the "correct" MOD function in such languages is the symmetric one.  (An exception I've found is Haskell.  This language uses the floored div and mod.)
 
I'm afraid Fortran misses a floored division (?)

Floored division isn't hard to i
[Thread Prev][Thread Next][Index]