Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/c_lib/src/convert.c
4024 views
1
/*
2
3
convert.c
4
2007 Aug 19
5
Author: Craig Citro
6
7
C code behind conversions to and from pari types.
8
9
Currently implemented:
10
Integer <--> t_INT
11
12
*/
13
14
#include "convert.h"
15
16
/*
17
18
Both t_INT_to_ZZ and ZZ_to_t_INT convert back and forth
19
from mpz_t to PARI's t_INT GEN type. Nothing fancy happens
20
here -- we simply use GMP's mpz_import or mpz_export to
21
basically memcopy the limbs in the integer.
22
23
*/
24
25
void t_INT_to_ZZ ( mpz_t value, GEN g )
26
{
27
long limbs = 0;
28
29
limbs = lgefint(g) - 2;
30
31
mpz_realloc2( value, limbs );
32
mpz_import( value, limbs, -1, sizeof(long), 0, 0, int_LSW(g) );
33
34
if ( signe(g) == -1 )
35
mpz_neg( value, value );
36
37
return;
38
}
39
40
41
/*
42
43
Convert back and forth from mpq_t to PARI's t_FRAC GEN type. Nothing
44
fancy happens here either.
45
46
No type checking is done.
47
48
AUTHOR: William Stein
49
50
*/
51
52
void t_FRAC_to_QQ ( mpq_t value, GEN g )
53
{
54
t_INT_to_ZZ(mpq_numref(value), numer(g));
55
t_INT_to_ZZ(mpq_denref(value), denom(g));
56
}
57
58