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

Commit

Permalink
#15114 force choice of coercion maps from UCF to CC, CIF, ...
Browse files Browse the repository at this point in the history
Without this commit:

$ ./sage
sage: foo = E(17,2) + E(17,15)
sage: CC(foo)
1.47801783444132 - 2.43945488809238e-19*I
sage: CIF(foo)
1.478017834441319? + 0.?e-17*I

$ ./sage
sage: foo = E(17,2) + E(17,15)
sage: CIF(foo)
1.47801783444132?
sage: CC(foo)
1.47801783444132 - 2.43945488809238e-19*I
  • Loading branch information
mezzarobba committed Dec 19, 2020
1 parent 3cc998a commit a51cfe0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/sage/rings/complex_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def late_import():
global AlgebraicNumber_base
global AlgebraicNumber
global AlgebraicReal
global UniversalCyclotomicField
global AA, QQbar, SR
global CLF, RLF, CDF
if NumberFieldElement_quadratic is None:
Expand All @@ -96,6 +97,7 @@ def late_import():
AlgebraicNumber_base = sage.rings.qqbar.AlgebraicNumber_base
AlgebraicNumber = sage.rings.qqbar.AlgebraicNumber
AlgebraicReal = sage.rings.qqbar.AlgebraicReal
from sage.rings.universal_cyclotomic_field import UniversalCyclotomicField
AA = sage.rings.qqbar.AA
QQbar = sage.rings.qqbar.QQbar
import sage.symbolic.ring
Expand Down Expand Up @@ -558,6 +560,13 @@ class ComplexField_class(ring.Field):
return None
if S in [AA, QQbar, CLF, RLF]:
return self._generic_coerce_map(S)
# Needed to discover the correct coerce map. Without this, the maps
# (direct or via QQbar, with slightly different behavior wrt imaginary
# parts of real elements) that get picked for conversion from UCF both
# to CC and to other types of complex fields depend in which order the
# coercions are discovered.
if isinstance(S, UniversalCyclotomicField):
return self._generic_coerce_map(S)
return self._coerce_map_via([CLF], S)

def _repr_(self):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/universal_cyclotomic_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class UCFtoQQbar(Morphism):
-0.500000000000000? + 0.866025403784439?*I
sage: CC(UCF.gen(7,2) + UCF.gen(7,6))
0.400968867902419 + 0.193096429713794*I
0.400968867902419 + 0.193096429713793*I
sage: complex(E(7)+E(7,2))
(0.40096886790241915+1.7567593946498534j)
Expand Down

0 comments on commit a51cfe0

Please sign in to comment.