➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 zooko
收信人 eric.smith, mark.dickinson, zooko
日期 2009-12-04.05:22:02
SpamBayes Score 0.0010701164
Marked as misclassified 否
Message-id <1259904124.88.0.924866320967.issue7406@psf.upfronthosting.co.za>
In-reply-to
内容
Here is a way to test for overflow which is correct for any C implementation:

static PyObject *
int_add(PyIntObject *v, PyIntObject *w)
{
	register long a, b;
	CONVERT_TO_LONG(v, a);
	CONVERT_TO_LONG(w, b);
	if (((a>0)&&(b>0)&&((LONG_MAX-a)<b))
		||((a<0)&&(b<0)&&((LONG_MIN-a)>b))) {
		/* would overflow the long type */
	    return PyLong_Type.tp_as_number->nb_add((PyObject *)v, (PyObject *)w);
	}
	
	return PyInt_FromLong(a+b);
}
历史
日期 用户 动作 参数
2009-12-04 05:22:05zooko修改recipients: + zooko, mark.dickinson, eric.smith
2009-12-04 05:22:04zooko修改messageid: <1259904124.88.0.924866320967.issue7406@psf.upfronthosting.co.za>
2009-12-04 05:22:02zooko链接issue7406 messages
2009-12-04 05:22:02zooko创建