From: Finn B. <bc...@us...> - 2000-12-11 18:39:48
|
Update of /cvsroot/jython/jython/org/python/core In directory slayer.i.sourceforge.net:/tmp/cvs-serv30534 Modified Files: PyFloat.java PyInteger.java PyLong.java Log Message: __pow__(): Fixed differences with CPython. Allow the test_pow test suite to run with jython. Index: PyFloat.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFloat.java,v retrieving revision 2.2 retrieving revision 2.3 diff -C2 -r2.2 -r2.3 *** PyFloat.java 1999/10/04 22:21:46 2.2 --- PyFloat.java 2000/12/11 18:39:45 2.3 *************** *** 135,139 **** public PyObject __pow__(PyObject right, PyObject modulo) { // Rely completely on Java's pow function ! double ret = Math.pow(value, ((PyFloat)right).value); if (modulo == null) { return new PyFloat(ret); --- 135,152 ---- public PyObject __pow__(PyObject right, PyObject modulo) { // Rely completely on Java's pow function ! ! double iw = ((PyFloat)right).value; ! if (iw == 0) { ! if (modulo != null) ! return new PyFloat(modulo(1.0, ((PyFloat)modulo).value)); ! return new PyFloat(1.0); ! } ! if (value == 0.0) { ! if (iw < 0.0) ! throw Py.ZeroDivisionError("0.0 cannot be raised to a negative power"); ! return new PyFloat(0); ! } ! ! double ret = Math.pow(value, iw); if (modulo == null) { return new PyFloat(ret); Index: PyInteger.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyInteger.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -r2.4 -r2.5 *** PyInteger.java 2000/11/30 09:01:43 2.4 --- PyInteger.java 2000/12/11 18:39:45 2.5 *************** *** 145,149 **** if (pow < 0) { ! throw Py.ValueError("integer to the negative power"); } --- 145,152 ---- if (pow < 0) { ! if (value != 0) ! throw Py.ValueError("cannot raise integer to a negative power"); ! else ! throw Py.ZeroDivisionError("cannot raise 0 to a negative power"); } Index: PyLong.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyLong.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -r2.4 -r2.5 *** PyLong.java 2000/09/30 13:32:02 2.4 --- PyLong.java 2000/12/11 18:39:45 2.5 *************** *** 163,167 **** BigInteger y = ((PyLong)right).value; if (y.compareTo(BigInteger.valueOf(0)) < 0) { ! throw Py.ValueError("long to negative power"); } if (modulo == null) --- 163,170 ---- BigInteger y = ((PyLong)right).value; if (y.compareTo(BigInteger.valueOf(0)) < 0) { ! if (value.compareTo(BigInteger.valueOf(0)) != 0) ! throw Py.ValueError("long integer to a negative power"); ! else ! throw Py.ZeroDivisionError("zero to a negative power"); } if (modulo == null) |