@@ -144,6 +144,20 @@ cpdef gen_to_sage(Gen z, locals=None):
144
144
sage: a.parent()
145
145
Complex Field with 64 bits of precision
146
146
147
+ sage: z = pari('1 + 1.0*I'); z
148
+ 1 + 1.00000000000000*I
149
+ sage: a = gen_to_sage(z); a
150
+ 1.00000000000000000 + 1.00000000000000000*I
151
+ sage: a.parent()
152
+ Complex Field with 64 bits of precision
153
+
154
+ sage: z = pari('1.0 + 1*I'); z
155
+ 1.00000000000000 + I
156
+ sage: a = gen_to_sage(z); a
157
+ 1.00000000000000000 + 1.00000000000000000*I
158
+ sage: a.parent()
159
+ Complex Field with 64 bits of precision
160
+
147
161
Converting polynomials::
148
162
149
163
sage: f = pari('(2/3)*x^3 + x - 5/7 + y')
@@ -233,16 +247,20 @@ cpdef gen_to_sage(Gen z, locals=None):
233
247
cdef GEN g = z.g
234
248
cdef long t = typ(g)
235
249
cdef long tx, ty
236
- cdef Gen real, imag
250
+ cdef Gen real, imag, prec, xprec, yprec
237
251
cdef Py_ssize_t i, j, nr, nc
238
252
239
253
if t == t_INT:
240
254
return Integer(z)
241
255
elif t == t_FRAC:
242
256
return Rational(z)
243
257
elif t == t_REAL:
244
- prec = prec_words_to_bits(z.precision())
245
- return RealField(prec)(z)
258
+ prec = z.bitprecision()
259
+ if typ(prec.g) == t_INFINITY:
260
+ sage_prec = 53
261
+ else :
262
+ sage_prec = prec
263
+ return RealField(sage_prec)(z)
246
264
elif t == t_COMPLEX:
247
265
real = z.real()
248
266
imag = z.imag()
@@ -251,17 +269,20 @@ cpdef gen_to_sage(Gen z, locals=None):
251
269
if tx in [t_INTMOD, t_PADIC] or ty in [t_INTMOD, t_PADIC]:
252
270
raise NotImplementedError (" No conversion to python available for t_COMPLEX with t_INTMOD or t_PADIC components" )
253
271
if tx == t_REAL or ty == t_REAL:
254
- xprec = real.precision() # will be 0 if exact
255
- yprec = imag.precision() # will be 0 if exact
256
- if xprec == 0 :
257
- prec = prec_words_to_bits(yprec)
258
- elif yprec == 0 :
259
- prec = prec_words_to_bits(xprec)
272
+ xprec = real.bitprecision() # will be infinite if exact
273
+ yprec = imag.bitprecision() # will be infinite if exact
274
+ if typ(xprec.g) == t_INFINITY:
275
+ if typ(yprec.g) == t_INFINITY:
276
+ sage_prec = 53
277
+ else :
278
+ sage_prec = yprec
279
+ elif typ(yprec.g) == t_INFINITY:
280
+ sage_prec = xprec
260
281
else :
261
- prec = max (prec_words_to_bits( xprec), prec_words_to_bits( yprec) )
282
+ sage_prec = max (xprec, yprec)
262
283
263
- R = RealField(prec )
264
- C = ComplexField(prec )
284
+ R = RealField(sage_prec )
285
+ C = ComplexField(sage_prec )
265
286
return C(R(real), R(imag))
266
287
else :
267
288
K = QuadraticField(- 1 , ' i' )
0 commit comments