@@ -5,19 +5,29 @@ must be linked with are not.
55
66A very basic example::
77
8- import mpfdtype as mpf
8+ import numpy as np
9+ from mpfdtype import MPFDType, MPFloat
910
1011 # create an array with 200 bits precision:
11- arr = np.arange(10).astype(MPFDType(200))
12+ arr = np.arange(3).astype(MPFDType(200))
13+ print(repr(arr))
14+ # array(['0E+00', '1.0E+00', '2.0E+00'], dtype=MPFDType(200))
1215
13- # Math uses the input precision:
14- arr**2 + np.sqrt(arr)
16+ # Math uses the input precision (wraps almost all math functions):
17+ res = arr**2 + np.sqrt(arr)
18+ print(repr(res))
19+ # array(['0E+00', '2.0E+00',
20+ # '5.4142135623730950488016887242096980785696718753769480731766784E+00'],
21+ # dtype=MPFDType(200))
1522
1623 # cast to a different precision:
17- arr2 = arr.astype(mpf.MPFDtype(500))
24+ arr2 = arr.astype(MPFDType(500))
25+ print(repr(arr2))
26+ # array(['0E+00', '1.0E+00', '2.0E+00'], dtype=MPFDType(500))
1827
19- res = arr1 + arr2
20- print(res) # uses the larger precision now
28+ res = arr + arr2
29+ print(repr(res)) # uses the larger precision now
30+ # array(['0E+00', '2.0E+00', '4.0E+00'], dtype=MPFDType(500))
2131
2232There also is an ` mpf.MPFloat(value, prec=None) ` . There is no "context"
2333as most libraries like this (including mpfr itself) typically have.
0 commit comments