@@ -365,6 +365,55 @@ cpdef bint parent_is_integers(P) except -1:
365365 from sage.rings.integer_ring import ZZ
366366 return P is ZZ
367367
368+ def parent_is_numerical (P ):
369+ r """
370+ Test if elements of the parent or type ``P`` can be numerically evaluated
371+ as complex numbers ( in a canonical way) .
372+
373+ EXAMPLES::
374+
375+ sage: from sage. structure. coerce import parent_is_numerical
376+ sage: import gmpy2, numpy
377+ sage: [parent_is_numerical(R) for R in [RR, CC, QQ, QuadraticField(-1),
378+ ....: int, complex, gmpy2.mpc, numpy.complexfloating ]]
379+ [True, True, True, True, True, True, True, True ]
380+ sage: [parent_is_numerical(R) for R in [SR, QQ['x' ], QQ[['x' ]], str]]
381+ [False, False, False, False ]
382+ sage: [parent_is_numerical(R) for R in [RIF, RBF, CIF, CBF ]]
383+ [False, False, False, False ]
384+ """
385+ if not isinstance (P, Parent):
386+ P = py_scalar_parent(P)
387+ if P is None :
388+ return False
389+ return P._is_numerical()
390+
391+ def parent_is_real_numerical (P ):
392+ r """
393+ Test if elements of the parent or type ``P`` can be numerically evaluated
394+ as real numbers ( in a canonical way) .
395+
396+ EXAMPLES::
397+
398+ sage: from sage. structure. coerce import parent_is_real_numerical
399+ sage: import gmpy2, numpy
400+ sage: [parent_is_real_numerical(R) for R in [RR, QQ, ZZ, RLF,
401+ ....: QuadraticField(2), int, float, gmpy2.mpq, numpy.integer ]]
402+ [True, True, True, True, True, True, True, True, True ]
403+ sage: [parent_is_real_numerical(R) for R in [CC, QuadraticField(-1),
404+ ....: complex, gmpy2.mpc, numpy.complexfloating ]]
405+ [False, False, False, False, False ]
406+ sage: [parent_is_real_numerical(R) for R in [SR, QQ['x' ], QQ[['x' ]], str]]
407+ [False, False, False, False ]
408+ sage: [parent_is_real_numerical(R) for R in [RIF, RBF, CIF, CBF ]]
409+ [False, False, False, False ]
410+ """
411+ if not isinstance (P, Parent):
412+ P = py_scalar_parent(P)
413+ if P is None :
414+ return False
415+ return P._is_real_numerical()
416+
368417
369418cpdef bint is_numpy_type(t):
370419 """
0 commit comments