Mercurial > cpython-lru_cache-weakref
diff Objects/floatobject.c @ 955:03de67080c95 legacy-trunk
* 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.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 14 Aug 1992 12:06:52 +0000 |
| parents | 0cd197947d81 |
| children | 2ed511171809 |
line wrap: on
line diff
--- a/Objects/floatobject.c Fri Aug 14 12:04:19 1992 +0000 +++ b/Objects/floatobject.c Fri Aug 14 12:06:52 1992 +0000 @@ -299,6 +299,25 @@ 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 @@ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ + float_coerce, /*nb_coerce*/ }; typeobject Floattype = {
