summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-11-01 20:09:42 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-11-01 20:09:42 (GMT)
commitd2364e8e2dee675526fb35b07dab0e8f84268ec3 (patch)
tree523ad16394ad3f130d776e44bf2ac0114e0147aa /Objects/floatobject.c
parent3808045d00f7296b71ca598f9f4156406bc365eb (diff)
downloadcpython-d2364e8e2dee675526fb35b07dab0e8f84268ec3.zip
cpython-d2364e8e2dee675526fb35b07dab0e8f84268ec3.tar.gz
cpython-d2364e8e2dee675526fb35b07dab0e8f84268ec3.tar.bz2
SF bug #477221: abs and divmod act oddly with -0.0.
Partial fix. float_abs(): ensure abs(-0.0) returns +0.0. Bugfix candidate.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index b8c3772..82aa963 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -114,7 +114,7 @@ PyFloat_FromString(PyObject *v, char **pend)
}
if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v),
PyUnicode_GET_SIZE(v),
- s_buffer,
+ s_buffer,
NULL))
return NULL;
s = s_buffer;
@@ -196,16 +196,16 @@ PyFloat_AsDouble(PyObject *op)
PyNumberMethods *nb;
PyFloatObject *fo;
double val;
-
+
if (op && PyFloat_Check(op))
return PyFloat_AS_DOUBLE((PyFloatObject*) op);
-
+
if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
nb->nb_float == NULL) {
PyErr_BadArgument();
return -1;
}
-
+
fo = (PyFloatObject*) (*nb->nb_float) (op);
if (fo == NULL)
return -1;
@@ -214,10 +214,10 @@ PyFloat_AsDouble(PyObject *op)
"nb_float should return float object");
return -1;
}
-
+
val = PyFloat_AS_DOUBLE(fo);
Py_DECREF(fo);
-
+
return val;
}
@@ -505,7 +505,7 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
else
ix = 1.0;
PyFPE_END_PROTECT(ix)
- return PyFloat_FromDouble(ix);
+ return PyFloat_FromDouble(ix);
}
if (iv == 0.0) { /* 0**w is error if w<0, else 1 */
if (iw < 0.0) {
@@ -537,7 +537,7 @@ static PyObject *
float_int_div(PyObject *v, PyObject *w)
{
PyObject *t, *r;
-
+
t = float_divmod(v, w);
if (t != NULL) {
r = PyTuple_GET_ITEM(t, 0);
@@ -570,8 +570,10 @@ float_abs(PyFloatObject *v)
{
if (v->ob_fval < 0)
return float_neg(v);
- else
+ else if (v->ob_fval > 0)
return float_pos(v);
+ else /* ensure abs(-0) is +0 */
+ return PyFloat_FromDouble(+0.0);
}
static int