mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
SF bug #477221: abs and divmod act oddly with -0.0.
Partial fix. float_abs(): ensure abs(-0.0) returns +0.0. Bugfix candidate.
This commit is contained in:
parent
3808045d00
commit
d2364e8e2d
1 changed files with 11 additions and 9 deletions
|
@ -114,7 +114,7 @@ PyFloat_FromString(PyObject *v, char **pend)
|
||||||
}
|
}
|
||||||
if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v),
|
if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v),
|
||||||
PyUnicode_GET_SIZE(v),
|
PyUnicode_GET_SIZE(v),
|
||||||
s_buffer,
|
s_buffer,
|
||||||
NULL))
|
NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
s = s_buffer;
|
s = s_buffer;
|
||||||
|
@ -196,16 +196,16 @@ PyFloat_AsDouble(PyObject *op)
|
||||||
PyNumberMethods *nb;
|
PyNumberMethods *nb;
|
||||||
PyFloatObject *fo;
|
PyFloatObject *fo;
|
||||||
double val;
|
double val;
|
||||||
|
|
||||||
if (op && PyFloat_Check(op))
|
if (op && PyFloat_Check(op))
|
||||||
return PyFloat_AS_DOUBLE((PyFloatObject*) op);
|
return PyFloat_AS_DOUBLE((PyFloatObject*) op);
|
||||||
|
|
||||||
if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
|
if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
|
||||||
nb->nb_float == NULL) {
|
nb->nb_float == NULL) {
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fo = (PyFloatObject*) (*nb->nb_float) (op);
|
fo = (PyFloatObject*) (*nb->nb_float) (op);
|
||||||
if (fo == NULL)
|
if (fo == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -214,10 +214,10 @@ PyFloat_AsDouble(PyObject *op)
|
||||||
"nb_float should return float object");
|
"nb_float should return float object");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
val = PyFloat_AS_DOUBLE(fo);
|
val = PyFloat_AS_DOUBLE(fo);
|
||||||
Py_DECREF(fo);
|
Py_DECREF(fo);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +505,7 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
|
||||||
else
|
else
|
||||||
ix = 1.0;
|
ix = 1.0;
|
||||||
PyFPE_END_PROTECT(ix)
|
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 (iv == 0.0) { /* 0**w is error if w<0, else 1 */
|
||||||
if (iw < 0.0) {
|
if (iw < 0.0) {
|
||||||
|
@ -537,7 +537,7 @@ static PyObject *
|
||||||
float_int_div(PyObject *v, PyObject *w)
|
float_int_div(PyObject *v, PyObject *w)
|
||||||
{
|
{
|
||||||
PyObject *t, *r;
|
PyObject *t, *r;
|
||||||
|
|
||||||
t = float_divmod(v, w);
|
t = float_divmod(v, w);
|
||||||
if (t != NULL) {
|
if (t != NULL) {
|
||||||
r = PyTuple_GET_ITEM(t, 0);
|
r = PyTuple_GET_ITEM(t, 0);
|
||||||
|
@ -570,8 +570,10 @@ float_abs(PyFloatObject *v)
|
||||||
{
|
{
|
||||||
if (v->ob_fval < 0)
|
if (v->ob_fval < 0)
|
||||||
return float_neg(v);
|
return float_neg(v);
|
||||||
else
|
else if (v->ob_fval > 0)
|
||||||
return float_pos(v);
|
return float_pos(v);
|
||||||
|
else /* ensure abs(-0) is +0 */
|
||||||
|
return PyFloat_FromDouble(+0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue