[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue-common/src/external fixedpoint.py
From: |
James Thompson |
Subject: |
gnue-common/src/external fixedpoint.py |
Date: |
Thu, 02 Oct 2003 21:07:58 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue-common
Branch:
Changes by: James Thompson <address@hidden> 03/10/02 21:07:58
Modified files:
src/external : fixedpoint.py
Log message:
switch type(self) to self.__class__ in external FixedPoint library so
it'd play nice with python 2.1 in woody
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/external/fixedpoint.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: gnue-common/src/external/fixedpoint.py
diff -c gnue-common/src/external/fixedpoint.py:1.1
gnue-common/src/external/fixedpoint.py:1.2
*** gnue-common/src/external/fixedpoint.py:1.1 Mon Sep 15 15:02:49 2003
--- gnue-common/src/external/fixedpoint.py Thu Oct 2 21:07:58 2003
***************
*** 187,193 ****
self.n = long(value) * _tento(p)
return
! if isinstance(value, type(self)):
temp = value.copy()
temp.set_precision(p)
self.n, self.p = temp.n, temp.p
--- 187,193 ----
self.n = long(value) * _tento(p)
return
! if isinstance(value, self.__class__):
temp = value.copy()
temp.set_precision(p)
self.n, self.p = temp.n, temp.p
***************
*** 305,311 ****
return "FixedPoint" + `(str(self), self.p)`
def copy(self):
! return _mkFP(self.n, self.p, type(self))
__copy__ = copy
--- 305,311 ----
return "FixedPoint" + `(str(self), self.p)`
def copy(self):
! return _mkFP(self.n, self.p, self.__class__)
__copy__ = copy
***************
*** 313,319 ****
return self.copy()
def __cmp__(self, other):
! xn, yn, p = _norm(self, other, FixedPoint=type(self))
return cmp(xn, yn)
def __hash__(self):
--- 313,319 ----
return self.copy()
def __cmp__(self, other):
! xn, yn, p = _norm(self, other, FixedPoint=self.__class__)
return cmp(xn, yn)
def __hash__(self):
***************
*** 338,344 ****
return self.n != 0
def __neg__(self):
! return _mkFP(-self.n, self.p, type(self))
def __abs__(self):
""" Returns new FixedPoint containing the absolute value of this
FixedPoint"""
--- 338,344 ----
return self.n != 0
def __neg__(self):
! return _mkFP(-self.n, self.p, self.__class__)
def __abs__(self):
""" Returns new FixedPoint containing the absolute value of this
FixedPoint"""
***************
*** 348,406 ****
return -self
def __add__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=type(self))
# n1/10**p + n2/10**p = (n1+n2)/10**p
! return _mkFP(n1 + n2, p, type(self))
__radd__ = __add__
def __sub__(self, other):
! if not isinstance(other, type(self)):
! other = type(self)(other, self.p)
return self.__add__(-other)
def __rsub__(self, other):
return (-self) + other
def __mul__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=type(self))
# n1/10**p * n2/10**p = (n1*n2/10**p)/10**p
! return _mkFP(self._roundquotient(n1 * n2, _tento(p)), p, type(self))
__rmul__ = __mul__
def __div__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=type(self))
if n2 == 0:
raise ZeroDivisionError("FixedPoint division")
if n2 < 0:
n1, n2 = -n1, -n2
# n1/10**p / (n2/10**p) = n1/n2 = (n1*10**p/n2)/10**p
! return _mkFP(self._roundquotient(n1 * _tento(p), n2), p, type(self))
def __rdiv__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=type(self))
! return _mkFP(n2, p, FixedPoint=type(self)) / self
def __divmod__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=type(self))
if n2 == 0:
raise ZeroDivisionError("FixedPoint modulo")
# floor((n1/10**p)/(n2*10**p)) = floor(n1/n2)
q = n1 / n2
# n1/10**p - q * n2/10**p = (n1 - q * n2)/10**p
! return q, _mkFP(n1 - q * n2, p, type(self))
def __rdivmod__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=type(self))
return divmod(_mkFP(n2, p), self)
def __mod__(self, other):
return self.__divmod__(other)[1]
def __rmod__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=type(self))
! return _mkFP(n2, p, type(self)).__mod__(self)
def __float__(self):
"""Return the floating point representation of this FixedPoint.
--- 348,406 ----
return -self
def __add__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=self.__class__)
# n1/10**p + n2/10**p = (n1+n2)/10**p
! return _mkFP(n1 + n2, p, self.__class__)
__radd__ = __add__
def __sub__(self, other):
! if not isinstance(other, self.__class__):
! other = self.__class__(other, self.p)
return self.__add__(-other)
def __rsub__(self, other):
return (-self) + other
def __mul__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=self.__class__)
# n1/10**p * n2/10**p = (n1*n2/10**p)/10**p
! return _mkFP(self._roundquotient(n1 * n2, _tento(p)), p,
self.__class__)
__rmul__ = __mul__
def __div__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=self.__class__)
if n2 == 0:
raise ZeroDivisionError("FixedPoint division")
if n2 < 0:
n1, n2 = -n1, -n2
# n1/10**p / (n2/10**p) = n1/n2 = (n1*10**p/n2)/10**p
! return _mkFP(self._roundquotient(n1 * _tento(p), n2), p,
self.__class__)
def __rdiv__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=self.__class__)
! return _mkFP(n2, p, FixedPoint=self.__class__) / self
def __divmod__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=self.__class__)
if n2 == 0:
raise ZeroDivisionError("FixedPoint modulo")
# floor((n1/10**p)/(n2*10**p)) = floor(n1/n2)
q = n1 / n2
# n1/10**p - q * n2/10**p = (n1 - q * n2)/10**p
! return q, _mkFP(n1 - q * n2, p, self.__class__)
def __rdivmod__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=self.__class__)
return divmod(_mkFP(n2, p), self)
def __mod__(self, other):
return self.__divmod__(other)[1]
def __rmod__(self, other):
! n1, n2, p = _norm(self, other, FixedPoint=self.__class__)
! return _mkFP(n2, p, self.__class__).__mod__(self)
def __float__(self):
"""Return the floating point representation of this FixedPoint.
- gnue-common/src/external fixedpoint.py,
James Thompson <=