Raise exception instead of dropping imag part for conversion to int,

long, float.

Raise exception instead of dumping core for remainder and divmod.
This commit is contained in:
Guido van Rossum 1996-09-11 22:54:37 +00:00
parent 22a85e5308
commit d4ab3cde8e
1 changed files with 9 additions and 11 deletions

View File

@ -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;
}