diff options
author | Guido van Rossum <guido@python.org> | 1992-09-12 11:09:23 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-09-12 11:09:23 (GMT) |
commit | 1899c2e0550fa025080e35bb3ec25aeff0118dc7 (patch) | |
tree | 46cf91828dd59c33ef396e1cdb93ce4ada5c8d9e /Objects/longobject.c | |
parent | 5c85062e1ce4c7e51daaad1a4eb3f66f6b5a0ea8 (diff) | |
download | cpython-1899c2e0550fa025080e35bb3ec25aeff0118dc7.zip cpython-1899c2e0550fa025080e35bb3ec25aeff0118dc7.tar.gz cpython-1899c2e0550fa025080e35bb3ec25aeff0118dc7.tar.bz2 |
Made builtins int(), long(), float(), oct() and hex() more generic.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r-- | Objects/longobject.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 7ede30c..25b4c64 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1268,6 +1268,47 @@ long_coerce(pv, pw) return 1; /* Can't do it */ } +static object * +long_int(v) + object *v; +{ + long x; + x = getlongvalue(v); + if (err_occurred()) + return NULL; + return newintobject(x); +} + +static object * +long_long(v) + object *v; +{ + INCREF(v); + return v; +} + +static object * +long_float(v) + object *v; +{ + return newfloatobject(dgetlongvalue(v)); +} + +static object * +long_oct(v) + object *v; +{ + return long_format(v, 8); +} + +static object * +long_hex(v) + object *v; +{ + return long_format(v, 16); +} + + #define UF (object* (*) FPROTO((object *))) /* Unary function */ #define BF (object* (*) FPROTO((object *, object *))) /* Binary function */ #define IF (int (*) FPROTO((object *))) /* Int function */ @@ -1292,6 +1333,11 @@ static number_methods long_as_number = { BF long_or, /*nb_or*/ (int (*) FPROTO((object **, object **))) long_coerce, /*nb_coerce*/ + UF long_int, /*nb_int*/ + UF long_long, /*nb_long*/ + UF long_float, /*nb_float*/ + UF long_oct, /*nb_oct*/ + UF long_hex, /*nb_hex*/ }; typeobject Longtype = { |