Skip to content

Commit 6bcc51a

Browse files
committed
imag and real getters
1 parent d90519b commit 6bcc51a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

quaddtype/numpy_quaddtype/src/scalar.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,26 @@ QuadPrecision_dealloc(QuadPrecisionObject *self)
315315
Py_TYPE(self)->tp_free((PyObject *)self);
316316
}
317317

318+
static PyObject *
319+
QuadPrecision_get_real(QuadPrecisionObject *self, void *closure)
320+
{
321+
Py_INCREF(self);
322+
return (PyObject *)self;
323+
}
324+
325+
static PyObject *
326+
QuadPrecision_get_imag(QuadPrecisionObject *self, void *closure)
327+
{
328+
// For real floating-point types, the imaginary part is always 0
329+
return (PyObject *)QuadPrecision_raw_new(self->backend);
330+
}
331+
332+
static PyGetSetDef QuadPrecision_getset[] = {
333+
{"real", (getter)QuadPrecision_get_real, NULL, "Real part of the scalar", NULL},
334+
{"imag", (getter)QuadPrecision_get_imag, NULL, "Imaginary part of the scalar (always 0 for real types)", NULL},
335+
{NULL} /* Sentinel */
336+
};
337+
318338
PyTypeObject QuadPrecision_Type = {
319339
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "numpy_quaddtype.QuadPrecision",
320340
.tp_basicsize = sizeof(QuadPrecisionObject),
@@ -325,6 +345,7 @@ PyTypeObject QuadPrecision_Type = {
325345
.tp_str = (reprfunc)QuadPrecision_str_dragon4,
326346
.tp_as_number = &quad_as_scalar,
327347
.tp_richcompare = (richcmpfunc)quad_richcompare,
348+
.tp_getset = QuadPrecision_getset,
328349
};
329350

330351
int

0 commit comments

Comments
 (0)