Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
sage.rings.numbers_abc: Move remaining numbers abc registrations to t…
Browse files Browse the repository at this point in the history
…he individual implementation modules
  • Loading branch information
Matthias Koeppe committed Oct 23, 2021
1 parent 1dc709c commit 8024209
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/sage/rings/complex_double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2657,3 +2657,8 @@ cdef inline ComplexDoubleElement ComplexDoubleElement_from_doubles(double re, do
z._complex.real = re
z._complex.imag = im
return z


# Support Python's numbers abstract base class
import numbers
numbers.Complex.register(ComplexDoubleElement)
5 changes: 5 additions & 0 deletions src/sage/rings/complex_mpc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2575,3 +2575,8 @@ cdef class CCtoMPC(Map):
y = (<MPComplexField_class>self.codomain())._new()
mpc_set_fr_fr(y.value, (<ComplexNumber>z).__re, (<ComplexNumber>z).__im, rnd)
return y


# Support Python's numbers abstract base class
import numbers
from sage.rings.complex_mpc import MPComplexNumber
5 changes: 5 additions & 0 deletions src/sage/rings/complex_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3610,3 +3610,8 @@ def _format_complex_number(real, imag, format_spec):
"complex format specifier")
result = format(result, align + width)
return result


# Support Python's numbers abstract base class
import numbers
numbers.Complex.register(ComplexNumber)
24 changes: 2 additions & 22 deletions src/sage/rings/numbers_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import numbers


def register_sage_classes():
"""
Expand Down Expand Up @@ -65,23 +63,5 @@ def register_sage_classes():
sage: isscalar(4/17)
True
"""
from sage.rings.integer import Integer
from sage.rings.rational import Rational
from sage.rings.real_mpfr import RealNumber
from sage.rings.real_double import RealDoubleElement
from sage.rings.complex_mpfr import ComplexNumber
from sage.rings.complex_double import ComplexDoubleElement
from sage.rings.complex_mpc import MPComplexNumber
from sage.rings.qqbar import AlgebraicReal, AlgebraicNumber

numbers.Integral.register(Integer)
numbers.Rational.register(Rational)
numbers.Real.register(RealNumber)
numbers.Real.register(RealDoubleElement)
numbers.Real.register(AlgebraicReal)
numbers.Complex.register(ComplexNumber)
numbers.Complex.register(MPComplexNumber)
numbers.Complex.register(ComplexDoubleElement)
numbers.Complex.register(AlgebraicNumber)

register_sage_classes()
from sage.misc.superseded import deprecation
deprecation(32641, "register_sage_classes is a deprecated no-op")
6 changes: 6 additions & 0 deletions src/sage/rings/qqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8546,3 +8546,9 @@ def get_AA_golden_ratio():
AA_golden_ratio_generator = AlgebraicGenerator(AA_golden_ratio_nf, ANRoot(AAPoly.gen()**2 - AAPoly.gen() - 1, RIF(1.618, 1.6181)))
AA_golden_ratio = AlgebraicReal(ANExtensionElement(AA_golden_ratio_generator, AA_golden_ratio_nf.gen()))
return AA_golden_ratio


# Support Python's numbers abstract base class
import numbers
numbers.Real.register(AlgebraicReal)
numbers.Complex.register(AlgebraicNumber)
5 changes: 5 additions & 0 deletions src/sage/rings/real_double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2943,3 +2943,8 @@ cdef double_repr(double x):
if v < 0:
return "-infinity"
return "NaN"
# Support Python's numbers abstract base class
import numbers
numbers.Real.register(RealDoubleElement)
5 changes: 5 additions & 0 deletions src/sage/rings/real_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6122,3 +6122,8 @@ def create_RealField(*args, **kwds):
deprecation(24511, "Please import create_RealField from sage.rings.real_field")
from sage.rings.real_field import create_RealField as cr
return cr(*args, **kwds)


# Support Python's numbers abstract base class
import numbers
numbers.Real.register(RealNumber)

0 comments on commit 8024209

Please sign in to comment.