summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-08-01 11:34:53 (GMT)
committerGuido van Rossum <guido@python.org>1994-08-01 11:34:53 (GMT)
commitb6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af (patch)
tree9362939305b2d088b8f19a530c9015d886bc2801 /Objects/floatobject.c
parent2979b01ff88ac4c5b316d9bf98edbaaaffac8e24 (diff)
downloadcpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.zip
cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.gz
cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.bz2
Merge alpha100 branch back to main trunk
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c79
1 files changed, 54 insertions, 25 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index d3a2c77..5ff67db 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -47,7 +47,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define CHECK(x) /* Don't know how to check */
#endif
-#ifndef THINK_C
+#ifndef macintosh
extern double fmod PROTO((double, double));
extern double pow PROTO((double, double));
#endif
@@ -77,12 +77,31 @@ double
getfloatvalue(op)
object *op;
{
- if (!is_floatobject(op)) {
+ number_methods *nb;
+ floatobject *fo;
+ double val;
+
+ if (op && is_floatobject(op))
+ return GETFLOATVALUE((floatobject*) op);
+
+ if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
+ nb->nb_float == NULL) {
err_badarg();
return -1;
}
- else
- return ((floatobject *)op) -> ob_fval;
+
+ fo = (floatobject*) (*nb->nb_float) (op);
+ if (fo == NULL)
+ return -1;
+ if (!is_floatobject(fo)) {
+ err_setstr(TypeError, "nb_float should return float object");
+ return -1;
+ }
+
+ val = GETFLOATVALUE(fo);
+ DECREF(fo);
+
+ return val;
}
/* Methods */
@@ -156,7 +175,17 @@ float_hash(v)
/* This is designed so that Python numbers with the same
value hash to the same value, otherwise comparisons
of mapping keys will turn out weird */
+
+#ifdef MPW /* MPW C modf expects pointer to extended as second argument */
+{
+ extended e;
+ fractpart = modf(v->ob_fval, &e);
+ intpart = e;
+}
+#else
fractpart = modf(v->ob_fval, &intpart);
+#endif
+
if (fractpart == 0.0) {
if (intpart > 0x7fffffffL || -intpart > 0x7fffffffL) {
/* Convert to long int and use its hash... */
@@ -372,27 +401,27 @@ float_float(v)
static number_methods float_as_number = {
- float_add, /*nb_add*/
- float_sub, /*nb_subtract*/
- float_mul, /*nb_multiply*/
- float_div, /*nb_divide*/
- float_rem, /*nb_remainder*/
- float_divmod, /*nb_divmod*/
- float_pow, /*nb_power*/
- float_neg, /*nb_negative*/
- float_pos, /*nb_positive*/
- float_abs, /*nb_absolute*/
- float_nonzero, /*nb_nonzero*/
+ (binaryfunc)float_add, /*nb_add*/
+ (binaryfunc)float_sub, /*nb_subtract*/
+ (binaryfunc)float_mul, /*nb_multiply*/
+ (binaryfunc)float_div, /*nb_divide*/
+ (binaryfunc)float_rem, /*nb_remainder*/
+ (binaryfunc)float_divmod, /*nb_divmod*/
+ (binaryfunc)float_pow, /*nb_power*/
+ (unaryfunc)float_neg, /*nb_negative*/
+ (unaryfunc)float_pos, /*nb_positive*/
+ (unaryfunc)float_abs, /*nb_absolute*/
+ (inquiry)float_nonzero, /*nb_nonzero*/
0, /*nb_invert*/
0, /*nb_lshift*/
0, /*nb_rshift*/
0, /*nb_and*/
0, /*nb_xor*/
0, /*nb_or*/
- float_coerce, /*nb_coerce*/
- float_int, /*nb_int*/
- float_long, /*nb_long*/
- float_float, /*nb_float*/
+ (coercion)float_coerce, /*nb_coerce*/
+ (unaryfunc)float_int, /*nb_int*/
+ (unaryfunc)float_long, /*nb_long*/
+ (unaryfunc)float_float, /*nb_float*/
0, /*nb_oct*/
0, /*nb_hex*/
};
@@ -403,14 +432,14 @@ typeobject Floattype = {
"float",
sizeof(floatobject),
0,
- float_dealloc, /*tp_dealloc*/
- float_print, /*tp_print*/
+ (destructor)float_dealloc, /*tp_dealloc*/
+ (printfunc)float_print, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- float_compare, /*tp_compare*/
- float_repr, /*tp_repr*/
+ (cmpfunc)float_compare, /*tp_compare*/
+ (reprfunc)float_repr, /*tp_repr*/
&float_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
- float_hash, /*tp_hash */
+ (hashfunc)float_hash, /*tp_hash*/
};