# [MATRIX-SIG] Inconsistent mod behaviour

**Konrad Hinsen
**
hinsen@ibs.ibs.fr

*Tue, 3 Mar 1998 10:41:20 +0100*

A colleague made me aware of an inconsistency in the modulo operation
for arrays and scalars:
>>>* from Numeric import *
*>>>* -15%2
*1
>>>* array([-15])%2
*array([-1])
Some further investigation shows that this is the result of different
truncation rules for integer division, i.e. division and modulo are
consistent in both cases:
>>>* -15/2
*-8
>>>* array(-15)/2
*-7
Nevertheless, it is an annoying problem. However, it was not really
introduced by NumPy. NumPy uses fmod() and therefore inherits its
documented behaviour. The same is true for math.fmod and Numeric.fmod.
I am not sure what to do about this. It seems reasonable to let arrays
behave like scalars for consistency, but of course leave the explicit
function fmod() as it is. Does anyone see a problem with that solution?
Konrad.
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale | Fax: +33-4.76.88.54.94
41, av. des Martyrs | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France | Nederlands/Francais
-------------------------------------------------------------------------------
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________