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

Commit 93a039f

Browse files
committed
Do not convert unsigned elements to InfinityRing
1 parent 20007d5 commit 93a039f

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/sage/rings/infinity.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,13 @@ def _element_constructor_(self, x):
11501150
Traceback (most recent call last):
11511151
...
11521152
ValueError: infinite but not with +/- phase
1153+
1154+
Unsigned elements raise an exception::
1155+
1156+
sage: InfinityRing(x)
1157+
Traceback (most recent call last):
1158+
...
1159+
ArithmeticError: cannot determine sign of x
11531160
"""
11541161
# Lazy elements can wrap infinity or not, unwrap first
11551162
from sage.rings.real_lazy import LazyWrapper
@@ -1185,8 +1192,7 @@ def _element_constructor_(self, x):
11851192
pass
11861193

11871194
# If we got here then x is not infinite
1188-
c = int(bool(x > 0)) - int(bool(x < 0))
1189-
return FiniteNumber(self, c)
1195+
return FiniteNumber(self, x)
11901196

11911197
def _coerce_map_from_(self, R):
11921198
r"""
@@ -1265,17 +1271,41 @@ def __init__(self, parent, x):
12651271
"""
12661272
Initialize ``self``.
12671273
1268-
TESTS::
1274+
INPUT:
1275+
1276+
- ``x`` -- the sign of ``x`` (positive, zero, negative)
1277+
determines the kind of finite number to create.
12691278
1270-
sage: sage.rings.infinity.FiniteNumber(InfinityRing, 1)
1279+
EXAMPLES::
1280+
1281+
sage: from sage.rings.infinity import FiniteNumber
1282+
sage: FiniteNumber(InfinityRing, 1)
12711283
A positive finite number
1272-
sage: sage.rings.infinity.FiniteNumber(InfinityRing, -1)
1284+
sage: FiniteNumber(InfinityRing, -1e100)
12731285
A negative finite number
1274-
sage: sage.rings.infinity.FiniteNumber(InfinityRing, 0)
1286+
sage: FiniteNumber(InfinityRing, 0)
12751287
Zero
1288+
sage: FiniteNumber(InfinityRing, RIF(-2, -1))
1289+
A negative finite number
1290+
sage: FiniteNumber(InfinityRing, RIF(0, 1))
1291+
Traceback (most recent call last):
1292+
...
1293+
ArithmeticError: cannot determine sign of 1.?
12761294
"""
12771295
RingElement.__init__(self, parent)
1278-
self.value = x
1296+
sgn = None
1297+
try:
1298+
if x == 0:
1299+
sgn = 0
1300+
elif x > 0:
1301+
sgn = 1
1302+
elif x < 0:
1303+
sgn = -1
1304+
except TypeError:
1305+
pass
1306+
if sgn is None:
1307+
raise ArithmeticError("cannot determine sign of {!r}".format(x))
1308+
self.value = sgn
12791309

12801310
def _richcmp_(self, other, op):
12811311
"""

0 commit comments

Comments
 (0)