@@ -333,6 +333,26 @@ QuadPrecision_dealloc(QuadPrecisionObject *self)
333333 Py_TYPE (self )-> tp_free ((PyObject * )self );
334334}
335335
336+ static PyObject *
337+ QuadPrecision_get_real (QuadPrecisionObject * self , void * closure )
338+ {
339+ Py_INCREF (self );
340+ return (PyObject * )self ;
341+ }
342+
343+ static PyObject *
344+ QuadPrecision_get_imag (QuadPrecisionObject * self , void * closure )
345+ {
346+ // For real floating-point types, the imaginary part is always 0
347+ return (PyObject * )QuadPrecision_raw_new (self -> backend );
348+ }
349+
350+ static PyGetSetDef QuadPrecision_getset [] = {
351+ {"real" , (getter )QuadPrecision_get_real , NULL , "Real part of the scalar" , NULL },
352+ {"imag" , (getter )QuadPrecision_get_imag , NULL , "Imaginary part of the scalar (always 0 for real types)" , NULL },
353+ {NULL } /* Sentinel */
354+ };
355+
336356PyTypeObject QuadPrecision_Type = {
337357 PyVarObject_HEAD_INIT (NULL , 0 ).tp_name = "numpy_quaddtype.QuadPrecision" ,
338358 .tp_basicsize = sizeof (QuadPrecisionObject ),
@@ -343,6 +363,7 @@ PyTypeObject QuadPrecision_Type = {
343363 .tp_str = (reprfunc )QuadPrecision_str_dragon4 ,
344364 .tp_as_number = & quad_as_scalar ,
345365 .tp_richcompare = (richcmpfunc )quad_richcompare ,
366+ .tp_getset = QuadPrecision_getset ,
346367};
347368
348369int
0 commit comments