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.

Author zooko
Recipients eric.smith, mark.dickinson, zooko
Date 2009-12-04.05:22:02
SpamBayes Score 0.0010701164
Marked as misclassified No
Message-id <1259904124.88.0.924866320967.issue7406@psf.upfronthosting.co.za>
In-reply-to
Content
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);
}
History
Date User Action Args
2009-12-04 05:22:05zookosetrecipients: + zooko, mark.dickinson, eric.smith
2009-12-04 05:22:04zookosetmessageid: <1259904124.88.0.924866320967.issue7406@psf.upfronthosting.co.za>
2009-12-04 05:22:02zookolinkissue7406 messages
2009-12-04 05:22:02zookocreate