nzmath.rational

Integer class

Integer is a class of integer. Since 'int' and 'long' do not return rational for division, it is needed to create a new class.

Ths class is a subclass of nzmath.ring.CommutativeRingElement and long.

constructor

Integer([integer])

Construct a Integer object. If argument is ommited, the value becomes 0.

methods

actAdditive(other)

Act on other additively, i.e. n is expanded to n time additions of other. Naively, it is:

return sum([+'''other''' for _ in range(self)])

but, here we use a binary addition chain.

actMultiplicative(other)

Act on other multiplicatively, i.e. n is expanded to n time multiplications of other. Naively, it is:

return reduce(lambda x,y: x*y, [+'''other''' for _ in range(self)])

but, here we use a binary addition chain.

getRing(self)

Return an IntegerRing object.

operators

Divisions are redefined. Other operations as a mathematical number are also overridden in order to return Integer instance instead of long object.

Bit operations, and other miscellaneous operators are inherited from long.


Last-modified: 2005-09-28 (¿å) 13:50:47