This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/sage/rings/complex_double.pyx: Move PARI conversion functions to …
…src/sage/libs/pari/
- Loading branch information
Matthias Koeppe
committed
Oct 22, 2021
1 parent
2cc2fa7
commit d641dc6
Showing
3 changed files
with
62 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from cypari2.gen cimport Gen | ||
from sage.rings.complex_double cimport ComplexDoubleElement | ||
|
||
cdef inline ComplexDoubleElement pari_to_cdf(Gen g) | ||
|
||
cpdef Gen new_gen_from_complex_double_element(ComplexDoubleElement self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from cysignals.signals cimport sig_on, sig_off | ||
|
||
from sage.libs.gsl.complex cimport * | ||
|
||
from cypari2.paridecl cimport * | ||
from cypari2.convert cimport new_gen_from_double, new_t_COMPLEX_from_double | ||
|
||
|
||
cdef inline ComplexDoubleElement pari_to_cdf(Gen g): | ||
""" | ||
Create a CDF element from a PARI ``gen``. | ||
EXAMPLES:: | ||
sage: CDF(pari("Pi")) | ||
3.141592653589793 | ||
sage: CDF(pari("1 + I/2")) | ||
1.0 + 0.5*I | ||
TESTS: | ||
Check that we handle PARI errors gracefully, see :trac:`17329`:: | ||
sage: CDF(-151.386325246 + 992.34771962*I).zeta() | ||
Traceback (most recent call last): | ||
... | ||
PariError: overflow in t_REAL->double conversion | ||
sage: CDF(pari(x^2 + 5)) | ||
Traceback (most recent call last): | ||
... | ||
PariError: incorrect type in gtofp (t_POL) | ||
""" | ||
cdef ComplexDoubleElement z = ComplexDoubleElement.__new__(ComplexDoubleElement) | ||
sig_on() | ||
if typ(g.g) == t_COMPLEX: | ||
z._complex = gsl_complex_rect(gtodouble(gel(g.g, 1)), gtodouble(gel(g.g, 2))) | ||
else: | ||
z._complex = gsl_complex_rect(gtodouble(g.g), 0.0) | ||
sig_off() | ||
return z | ||
|
||
|
||
cpdef Gen new_gen_from_complex_double_element(ComplexDoubleElement self): | ||
|
||
if not self._complex.imag: | ||
return new_gen_from_double(self._complex.real) | ||
else: | ||
return new_t_COMPLEX_from_double(self._complex.real, self._complex.imag) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters