File: test_mpfr_to_from_binary.txt

package info (click to toggle)
python-gmpy2 2.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,628 kB
  • ctags: 1,123
  • sloc: ansic: 21,036; python: 5,846; makefile: 163
file content (48 lines) | stat: -rw-r--r-- 1,242 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Testing of gmpy2 mpfr to_binary and from_binary
-----------------------------------------------

    >>> import gmpy2
    >>> from gmpy2 import mpfr,to_binary,from_binary

Test
----

    >>> x=mpfr("0");x==from_binary(to_binary(x))
    True
    >>> x=mpfr("1");x==from_binary(to_binary(x))
    True
    >>> x=mpfr("-1");x==from_binary(to_binary(x))
    True
    >>> x=mpfr("inf");x==from_binary(to_binary(x))
    True
    >>> x=mpfr("-inf");x==from_binary(to_binary(x))
    True
    >>> x=mpfr("nan");gmpy2.is_nan(from_binary(to_binary(x)))
    True
    >>> x=mpfr(1.345);x==from_binary(to_binary(x))
    True
    >>> x=mpfr("1.345e1000");x==from_binary(to_binary(x))
    True
    >>> x=gmpy2.const_pi()
    >>> x.rc
    -1
    >>> y=from_binary(to_binary(x))
    >>> x==y
    True
    >>> y.rc
    -1
    >>> gmpy2.get_context().precision=100
    >>> x=gmpy2.const_pi();x==from_binary(to_binary(x))
    True
    >>> gmpy2.get_context().precision=200
    >>> x=mpfr(gmpy2.const_pi());x==from_binary(to_binary(x))
    True
    >>> gmpy2.get_context().precision=200
    >>> x=gmpy2.const_pi()
    >>> gmpy2.get_context().precision=300
    >>> x=from_binary(to_binary(x))
    >>> x.precision
    200
    >>> gmpy2.set_context(gmpy2.context())