summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-09-11 22:54:37 (GMT)
committerGuido van Rossum <guido@python.org>1996-09-11 22:54:37 (GMT)
commitd4ab3cde8e75015ccbf38274ea57830542f3f472 (patch)
tree62053371f639e2e9ad6c94bab5f5ad3101c4f544 /Objects/complexobject.c
parent22a85e5308499cef3dc6171b9697bbf43ef4f0f1 (diff)
downloadcpython-d4ab3cde8e75015ccbf38274ea57830542f3f472.zip
cpython-d4ab3cde8e75015ccbf38274ea57830542f3f472.tar.gz
cpython-d4ab3cde8e75015ccbf38274ea57830542f3f472.tar.bz2
Raise exception instead of dropping imag part for conversion to int,
long, float. Raise exception instead of dumping core for remainder and divmod.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r--Objects/complexobject.c20
1 files 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;
}