summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-08-14 12:06:52 (GMT)
committerGuido van Rossum <guido@python.org>1992-08-14 12:06:52 (GMT)
commite6eefc22313e7f2da5918ecd608fbb0b7a7a1610 (patch)
tree2896ab6358835d67083251ca911ff6d29a1138bf /Objects/floatobject.c
parent70d7a310a9844d1a3f80c110f1acd3d6059939b4 (diff)
downloadcpython-e6eefc22313e7f2da5918ecd608fbb0b7a7a1610.zip
cpython-e6eefc22313e7f2da5918ecd608fbb0b7a7a1610.tar.gz
cpython-e6eefc22313e7f2da5918ecd608fbb0b7a7a1610.tar.bz2
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
coercion is now completely generic. * ceval.c: for instances, don't coerce for + and *; * reverses arguments if left one is non-instance numeric and right one sequence.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index d154cab..5ce6202 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -299,6 +299,25 @@ float_nonzero(v)
return v->ob_fval != 0.0;
}
+int
+float_coerce(pv, pw)
+ object **pv;
+ object **pw;
+{
+ if (is_intobject(*pw)) {
+ long x = getintvalue(*pw);
+ *pw = newfloatobject((double)x);
+ INCREF(*pv);
+ return 0;
+ }
+ else if (is_longobject(*pw)) {
+ *pw = newfloatobject(dgetlongvalue(*pw));
+ INCREF(*pv);
+ return 0;
+ }
+ return 1; /* Can't do it */
+}
+
static number_methods float_as_number = {
float_add, /*nb_add*/
float_sub, /*nb_subtract*/
@@ -317,6 +336,7 @@ static number_methods float_as_number = {
0, /*nb_and*/
0, /*nb_xor*/
0, /*nb_or*/
+ float_coerce, /*nb_coerce*/
};
typeobject Floattype = {