getfloatvalue()

spm2d@wilbury.cs.Virginia.EDU
Sat, 22 Feb 92 21:59:02 EST

I "fixed" a minor problem with Python and the C extensions. If you
attempt to read a float and it's actually an int, it doesn't get
converted; instead, it returns an error.

I've fixed it so that it automatically converts it for you.
Here is the new version of getfloatdouble(), located in floatobject.c:

double
getfloatvalue(op)
object *op;
{
if (!is_floatobject(op)) {
if(!is_intobject(op)) {
err_badarg();
return -1;
} else return (double)((intobject *)op) -> ob_ival;
}
else
return ((floatobject *)op) -> ob_fval;
}

What the old version did was to see if the parameter being passed was
a float; if not, it returned an error. What I do now is before I
return, I see if it is an integer, and if it is, I convert it;
otherwise, there is still an error.

This could logically be extended to automatically convert strings,
etc.

Steve