/*12convert.c32007 Aug 194Author: Craig Citro56C code behind conversions to and from pari types.78Currently implemented:9Integer <--> t_INT1011*/1213#include "convert.h"1415/*1617Both t_INT_to_ZZ and ZZ_to_t_INT convert back and forth18from mpz_t to PARI's t_INT GEN type. Nothing fancy happens19here -- we simply use GMP's mpz_import or mpz_export to20basically memcopy the limbs in the integer.2122*/2324void t_INT_to_ZZ ( mpz_t value, GEN g )25{26long limbs = 0;2728limbs = lgefint(g) - 2;2930mpz_realloc2( value, limbs );31mpz_import( value, limbs, -1, sizeof(long), 0, 0, int_LSW(g) );3233if ( signe(g) == -1 )34mpz_neg( value, value );3536return;37}383940/*4142Convert back and forth from mpq_t to PARI's t_FRAC GEN type. Nothing43fancy happens here either.4445No type checking is done.4647AUTHOR: William Stein4849*/5051void t_FRAC_to_QQ ( mpq_t value, GEN g )52{53t_INT_to_ZZ(mpq_numref(value), numer(g));54t_INT_to_ZZ(mpq_denref(value), denom(g));55}565758