/ test / test_mpfr_to_from_binary.txt
test_mpfr_to_from_binary.txt
 1  Testing of gmpy2 mpfr to_binary and from_binary
 2  -----------------------------------------------
 3  
 4      >>> import gmpy2
 5      >>> from gmpy2 import mpfr,to_binary,from_binary
 6  
 7  Test
 8  ----
 9  
10      >>> x=mpfr("0");x==from_binary(to_binary(x))
11      True
12      >>> x=mpfr("1");x==from_binary(to_binary(x))
13      True
14      >>> x=mpfr("-1");x==from_binary(to_binary(x))
15      True
16      >>> x=mpfr("inf");x==from_binary(to_binary(x))
17      True
18      >>> x=mpfr("-inf");x==from_binary(to_binary(x))
19      True
20      >>> x=mpfr("nan");gmpy2.is_nan(from_binary(to_binary(x)))
21      True
22      >>> x=mpfr(1.345);x==from_binary(to_binary(x))
23      True
24      >>> x=mpfr("1.345e1000");x==from_binary(to_binary(x))
25      True
26      >>> x=gmpy2.const_pi()
27      >>> x.rc
28      -1
29      >>> y=from_binary(to_binary(x))
30      >>> x==y
31      True
32      >>> y.rc
33      -1
34      >>> gmpy2.get_context().precision=100
35      >>> x=gmpy2.const_pi();x==from_binary(to_binary(x))
36      True
37      >>> gmpy2.get_context().precision=200
38      >>> x=mpfr(gmpy2.const_pi());x==from_binary(to_binary(x))
39      True
40      >>> gmpy2.get_context().precision=200
41      >>> x=gmpy2.const_pi()
42      >>> gmpy2.get_context().precision=300
43      >>> x=from_binary(to_binary(x))
44      >>> x.precision
45      200
46      >>> gmpy2.set_context(gmpy2.context())
47  
48