From d4ab3cde8e75015ccbf38274ea57830542f3f472 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 11 Sep 1996 22:54:37 +0000 Subject: Raise exception instead of dropping imag part for conversion to int, long, float. Raise exception instead of dumping core for remainder and divmod. --- Objects/complexobject.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 063f3e0..d58ecd1 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -478,29 +478,27 @@ static object * complex_int(v) object *v; { - double x = ((complexobject *)v)->cval.real; - if (x < 0 ? (x = ceil(x)) < (double)LONG_MIN - : (x = floor(x)) > (double)LONG_MAX) { - err_setstr(OverflowError, "float too large to convert"); - return NULL; - } - return newintobject((long)x); + err_setstr(TypeError, + "can't convert complex to int; use e.g. int(abs(z))"); + return NULL; } static object * complex_long(v) object *v; { - double x = ((complexobject *)v)->cval.real; - return dnewlongobject(x); + err_setstr(TypeError, + "can't convert complex to long; use e.g. long(abs(z))"); + return NULL; } static object * complex_float(v) object *v; { - double x = ((complexobject *)v)->cval.real; - return newfloatobject(x); + err_setstr(TypeError, + "can't convert complex to float; use e.g. abs(z)"); + return NULL; } -- cgit v0.12