For the integer division, there is often a difference between the computer implementation and the generally accepted definition in math. See https://en.wikipedia.org/wiki/Modular_arithmetic for the definition of modulo and congruence : the result of modulo is always positive. 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 !! I'm afraid Fortran misses a floored division (?) This could be a long discussion about math, computer implementation, etc ... But my point is far more practical : I define some geographical areas with mask from latitude and longitude values. The work would be simpler if I could use a MOD (or MODULO or whatever) function that return a number in [0,360[, and not in ]-360,360[ For instance : I have data with longitude in [0,360]. I want to mask some of them, and plot them for longitude -30:110. This is possible because the longitude is properly defined as modulo in the NetCDF file. I need to define the mask as : LET m1 = IF lat LT 63 AND ( lon GT 330 OR (lon LT 0 AND lon GT -30) ) THEN 0 ELSE 1 this would be simpler if I could write : LET m1 = IF lat LT 63 AND MODULO(lon,360) LT 330 THEN 0 ELSE 1 A floored division could also be useful :-) Olivier
— Olivier Marti - LSCE Bât 714 p. 1049 MERMAID Team Normal situation : +33 1 69 08 77 27 Corona lockdown : +33 6 45 36 43 74 |
Attachment:
smime.p7s
Description: S/MIME cryptographic signature