diff options
author | Guido van Rossum <guido@python.org> | 2007-08-01 18:08:08 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-01 18:08:08 (GMT) |
commit | b43daf709600f5b734fb1a647666c2f4c0626519 (patch) | |
tree | 22989fadb044796cc3533d1f0ba975d8a6f02f22 /Objects/floatobject.c | |
parent | a6bcefca8128d2eb1dff46037f23c111d4a44297 (diff) | |
download | cpython-b43daf709600f5b734fb1a647666c2f4c0626519.zip cpython-b43daf709600f5b734fb1a647666c2f4c0626519.tar.gz cpython-b43daf709600f5b734fb1a647666c2f4c0626519.tar.bz2 |
Changes to long and float by Jeffrey Jasskin to conform to PEP 3141.
In particular, add trivial implementations of .real, .imag and .conjugate()
to both, and add .numerator and .denominator to long.
Also some small optimizations (e.g. remove long_pos in favor of long_long).
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index f2f53ba..bf65541 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -742,17 +742,6 @@ float_neg(PyFloatObject *v) } static PyObject * -float_pos(PyFloatObject *v) -{ - if (PyFloat_CheckExact(v)) { - Py_INCREF(v); - return (PyObject *)v; - } - else - return PyFloat_FromDouble(v->ob_fval); -} - -static PyObject * float_abs(PyFloatObject *v) { return PyFloat_FromDouble(fabs(v->ob_fval)); @@ -989,7 +978,15 @@ PyDoc_STRVAR(float_setformat_doc, "Overrides the automatic determination of C-level floating point type.\n" "This affects how floats are converted to and from binary strings."); +static PyObject * +float_getzero(PyObject *v, void *closure) +{ + return PyFloat_FromDouble(0.0); +} + static PyMethodDef float_methods[] = { + {"conjugate", (PyCFunction)float_float, METH_NOARGS, + "Returns self, the complex conjugate of any float."}, {"__getnewargs__", (PyCFunction)float_getnewargs, METH_NOARGS}, {"__getformat__", (PyCFunction)float_getformat, METH_O|METH_CLASS, float_getformat_doc}, @@ -998,6 +995,18 @@ static PyMethodDef float_methods[] = { {NULL, NULL} /* sentinel */ }; +static PyGetSetDef float_getset[] = { + {"real", + (getter)float_float, (setter)NULL, + "the real part of a complex number", + NULL}, + {"imag", + (getter)float_getzero, (setter)NULL, + "the imaginary part of a complex number", + NULL}, + {NULL} /* Sentinel */ +}; + PyDoc_STRVAR(float_doc, "float(x) -> floating point number\n\ \n\ @@ -1012,7 +1021,7 @@ static PyNumberMethods float_as_number = { float_divmod, /*nb_divmod*/ float_pow, /*nb_power*/ (unaryfunc)float_neg, /*nb_negative*/ - (unaryfunc)float_pos, /*nb_positive*/ + (unaryfunc)float_float, /*nb_positive*/ (unaryfunc)float_abs, /*nb_absolute*/ (inquiry)float_bool, /*nb_bool*/ 0, /*nb_invert*/ @@ -1073,7 +1082,7 @@ PyTypeObject PyFloat_Type = { 0, /* tp_iternext */ float_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + float_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ |