root / pobysoPythonSage / src / sageMpfr.spyx @ 43
Historique | Voir | Annoter | Télécharger (1,26 ko)
1 |
from sage.rings.real_mpfr cimport * |
---|---|
2 |
# |
3 |
# Two functions to manipulate the real RealNumber values. |
4 |
# |
5 |
# Get the address of the value of a RealNumber. This address can be |
6 |
# used to to set the value as well. |
7 |
# |
8 |
cpdef int get_rn_value(RealNumber x): |
9 |
return(<int>&(x.value)) |
10 |
# |
11 |
# We use the "array trick" to workaround the pointer dereferencing |
12 |
# issue (in Cython there is no unary operator "*"). |
13 |
# |
14 |
cpdef set_rn_value(RealNumber x, int p, mp_rnd_t rnd=GMP_RNDN): |
15 |
mpfr_set(x.value, (<mpfr_t *>p)[0], rnd) |
16 |
# |
17 |
# Do not use this function! |
18 |
# It changes the precision of the instance behind the curtain, but precision is |
19 |
# class attribute. If the precision is increased, memory space is wasted and |
20 |
# other problems may surface in subsequent operations. |
21 |
# If the precision is decreased the semantics |
22 |
# are broken since the expected precision (from the class attribute) is not |
23 |
# the actual precision. |
24 |
# |
25 |
cpdef s_rn_value(RealNumber x, int p): |
26 |
mpfr_clear(x.value) |
27 |
mpfr_init2(x.value, mpfr_get_prec((<mpfr_t *>p)[0])) |
28 |
#x.__prec = mpfr_get_prec(x.value) |
29 |
printf("x.value prec: %d\n", mpfr_get_prec(x.value)) |
30 |
mpfr_set(x.value, (<mpfr_t *>p)[0], GMP_RNDN) |
31 |
# |
32 |
# Compare two RN with the mpfr_cmp function |
33 |
cpdef cmp_rn_value(RealNumber x, RealNumber y): |
34 |
return(mpfr_cmp(x.value, y.value)) |