Skip to content

Commit 4c2e232

Browse files
Release Managervbraun
Release Manager
authored andcommitted
Trac #24511: Move create_RealField to real_field.py
This is part of #24457 but it already makes sense without that ticket to have the factory function in a separate module. URL: https://trac.sagemath.org/24511 Reported by: rws Ticket author(s): Ralf Stephan Reviewer(s): Vincent Delecroix
2 parents 714b911 + c02bb43 commit 4c2e232

File tree

4 files changed

+82
-63
lines changed

4 files changed

+82
-63
lines changed

src/sage/rings/qqbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ def completion(self, p, prec, extras = {}):
848848
NotImplementedError
849849
"""
850850
if p == infinity.Infinity:
851-
from sage.rings.real_mpfr import create_RealField
851+
from sage.rings.real_field import create_RealField
852852
return create_RealField(prec, **extras)
853853
else:
854854
raise NotImplementedError
@@ -1243,7 +1243,7 @@ def completion(self, p, prec, extras = {}):
12431243
NotImplementedError
12441244
"""
12451245
if p == infinity.Infinity:
1246-
from sage.rings.real_mpfr import create_RealField
1246+
from sage.rings.real_field import create_RealField
12471247
return create_RealField(prec, **extras).complex_field()
12481248
else:
12491249
raise NotImplementedError

src/sage/rings/rational_field.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def completion(self, p, prec, extras = {}):
336336
"""
337337
from sage.rings.infinity import Infinity
338338
if p == Infinity:
339-
from sage.rings.real_mpfr import create_RealField
339+
from sage.rings.real_field import create_RealField
340340
return create_RealField(prec, **extras)
341341
else:
342342
from sage.rings.padics.factory import Qp

src/sage/rings/real_field.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
def create_RealField(prec=53, type="MPFR", rnd="RNDN", sci_not=0):
2+
"""
3+
Create a real field with given precision, type, rounding mode and
4+
scientific notation.
5+
6+
Some options are ignored for certain types (RDF for example).
7+
8+
INPUT:
9+
10+
- ``prec`` -- a positive integer
11+
12+
- ``type`` -- type of real field:
13+
14+
- ``'RDF'`` -- the Sage real field corresponding to native doubles
15+
- ``'Interval'`` -- real fields implementing interval arithmetic
16+
- ``'RLF'`` -- the real lazy field
17+
- ``'MPFR'`` -- floating point real numbers implemented using the MPFR
18+
library
19+
20+
- ``rnd`` -- rounding mode:
21+
22+
- ``'RNDN'`` -- round to nearest
23+
- ``'RNDZ'`` -- round toward zero
24+
- ``'RNDD'`` -- round down
25+
- ``'RNDU'`` -- round up
26+
27+
- ``sci_not`` -- boolean, whether to use scientific notation for printing
28+
29+
OUTPUT:
30+
31+
the appropriate real field
32+
33+
EXAMPLES::
34+
35+
sage: from sage.rings.real_field import create_RealField
36+
sage: create_RealField(30)
37+
Real Field with 30 bits of precision
38+
sage: create_RealField(20, 'RDF') # ignores precision
39+
Real Double Field
40+
sage: create_RealField(60, 'Interval')
41+
Real Interval Field with 60 bits of precision
42+
sage: create_RealField(40, 'RLF') # ignores precision
43+
Real Lazy Field
44+
"""
45+
if type == "RDF":
46+
from .real_double import RDF
47+
return RDF
48+
elif type == "Interval":
49+
from .real_mpfi import RealIntervalField
50+
return RealIntervalField(prec, sci_not)
51+
elif type == "Ball":
52+
from .real_arb import RealBallField
53+
return RealBallField(prec)
54+
elif type == "RLF":
55+
from .real_lazy import RLF
56+
return RLF
57+
else:
58+
from .real_mpfr import RealField
59+
return RealField(prec, sci_not, rnd)
60+
61+

src/sage/rings/real_mpfr.pyx

+18-60
Original file line numberDiff line numberDiff line change
@@ -5710,66 +5710,6 @@ def create_RealNumber(s, int base=10, int pad=0, rnd="RNDN", int min_prec=53):
57105710
return RealLiteral(R, s, base)
57115711

57125712

5713-
# here because this imports the other real fields
5714-
def create_RealField(prec=53, type="MPFR", rnd="RNDN", sci_not=0):
5715-
"""
5716-
Create a real field with given precision, type, rounding mode and
5717-
scientific notation.
5718-
5719-
Some options are ignored for certain types (RDF for example).
5720-
5721-
INPUT:
5722-
5723-
- ``prec`` -- a positive integer
5724-
5725-
- ``type`` -- type of real field:
5726-
5727-
- ``'RDF'`` -- the Sage real field corresponding to native doubles
5728-
- ``'Interval'`` -- real fields implementing interval arithmetic
5729-
- ``'RLF'`` -- the real lazy field
5730-
- ``'MPFR'`` -- floating point real numbers implemented using the MPFR
5731-
library
5732-
5733-
- ``rnd`` -- rounding mode:
5734-
5735-
- ``'RNDN'`` -- round to nearest
5736-
- ``'RNDZ'`` -- round toward zero
5737-
- ``'RNDD'`` -- round down
5738-
- ``'RNDU'`` -- round up
5739-
5740-
- ``sci_not`` -- boolean, whether to use scientific notation for printing
5741-
5742-
OUTPUT:
5743-
5744-
the appropriate real field
5745-
5746-
EXAMPLES::
5747-
5748-
sage: from sage.rings.real_mpfr import create_RealField
5749-
sage: create_RealField(30)
5750-
Real Field with 30 bits of precision
5751-
sage: create_RealField(20, 'RDF') # ignores precision
5752-
Real Double Field
5753-
sage: create_RealField(60, 'Interval')
5754-
Real Interval Field with 60 bits of precision
5755-
sage: create_RealField(40, 'RLF') # ignores precision
5756-
Real Lazy Field
5757-
"""
5758-
if type == "RDF":
5759-
return RDF
5760-
elif type == "Interval":
5761-
from .real_mpfi import RealIntervalField
5762-
return RealIntervalField(prec, sci_not)
5763-
elif type == "Ball":
5764-
from .real_arb import RealBallField
5765-
return RealBallField(prec)
5766-
elif type == "RLF":
5767-
from .real_lazy import RLF
5768-
return RLF
5769-
else:
5770-
return RealField(prec, sci_not, rnd)
5771-
5772-
57735713
def is_RealField(x):
57745714
"""
57755715
Returns ``True`` if ``x`` is technically of a Python real field type.
@@ -5968,3 +5908,21 @@ cdef class int_toRR(Map):
59685908
raise TypeError("argument cannot be converted to a Python int/long")
59695909

59705910
return y
5911+
5912+
5913+
def create_RealField(*args, **kwds):
5914+
r"""
5915+
Deprecated function moved to :mod:`sage.rings.real_field`.
5916+
5917+
TESTS::
5918+
5919+
sage: from sage.rings.real_mpfr import create_RealField
5920+
sage: create_RealField()
5921+
doctest:...: DeprecationWarning: Please import create_RealField from sage.rings.real_field
5922+
See http://trac.sagemath.org/24511 for details.
5923+
Real Field with 53 bits of precision
5924+
"""
5925+
from sage.misc.superseded import deprecation
5926+
deprecation(24511, "Please import create_RealField from sage.rings.real_field")
5927+
from sage.rings.real_field import create_RealField as cr
5928+
return cr(*args, **kwds)

0 commit comments

Comments
 (0)