summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-09-12 11:09:23 (GMT)
committerGuido van Rossum <guido@python.org>1992-09-12 11:09:23 (GMT)
commit1899c2e0550fa025080e35bb3ec25aeff0118dc7 (patch)
tree46cf91828dd59c33ef396e1cdb93ce4ada5c8d9e /Objects/floatobject.c
parent5c85062e1ce4c7e51daaad1a4eb3f66f6b5a0ea8 (diff)
downloadcpython-1899c2e0550fa025080e35bb3ec25aeff0118dc7.zip
cpython-1899c2e0550fa025080e35bb3ec25aeff0118dc7.tar.gz
cpython-1899c2e0550fa025080e35bb3ec25aeff0118dc7.tar.bz2
Made builtins int(), long(), float(), oct() and hex() more generic.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 5ce6202..1a1598c 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -318,6 +318,33 @@ float_coerce(pv, pw)
return 1; /* Can't do it */
}
+static object *
+float_int(v)
+ object *v;
+{
+ double x = getfloatvalue(v);
+ /* XXX should check for overflow */
+ /* XXX should define how we round */
+ return newintobject((long)x);
+}
+
+static object *
+float_long(v)
+ object *v;
+{
+ double x = getfloatvalue(v);
+ return dnewlongobject(x);
+}
+
+static object *
+float_float(v)
+ object *v;
+{
+ INCREF(v);
+ return v;
+}
+
+
static number_methods float_as_number = {
float_add, /*nb_add*/
float_sub, /*nb_subtract*/
@@ -337,6 +364,11 @@ static number_methods float_as_number = {
0, /*nb_xor*/
0, /*nb_or*/
float_coerce, /*nb_coerce*/
+ float_int, /*nb_int*/
+ float_long, /*nb_long*/
+ float_float, /*nb_float*/
+ 0, /*nb_oct*/
+ 0, /*nb_hex*/
};
typeobject Floattype = {