@@ -4,6 +4,7 @@ Faster versions of some key functions in mpmath.libmp
4
4
from .ext_impl cimport *
5
5
from sage.libs.gmp.all cimport *
6
6
7
+ # the next line is used by mpmath
7
8
from .ext_impl import exp_fixed, cos_sin_fixed, log_int_fixed
8
9
9
10
# Note: not thread-safe
@@ -12,6 +13,7 @@ cdef MPF tmp2
12
13
MPF_init(& tmp1)
13
14
MPF_init(& tmp2)
14
15
16
+
15
17
def mpf_add (tuple x , tuple y , int prec = 0 , str rnd = ' d' ):
16
18
cdef MPopts opts
17
19
MPF_set_tuple(& tmp1, x)
@@ -21,6 +23,7 @@ def mpf_add(tuple x, tuple y, int prec=0, str rnd='d'):
21
23
MPF_add(& tmp1, & tmp1, & tmp2, opts)
22
24
return MPF_to_tuple(& tmp1)
23
25
26
+
24
27
def mpf_sub (tuple x , tuple y , int prec = 0 , str rnd = ' d' ):
25
28
cdef MPopts opts
26
29
MPF_set_tuple(& tmp1, x)
@@ -30,6 +33,7 @@ def mpf_sub(tuple x, tuple y, int prec=0, str rnd='d'):
30
33
MPF_sub(& tmp1, & tmp1, & tmp2, opts)
31
34
return MPF_to_tuple(& tmp1)
32
35
36
+
33
37
def mpf_mul (tuple x , tuple y , int prec = 0 , str rnd = ' d' ):
34
38
cdef MPopts opts
35
39
MPF_set_tuple(& tmp1, x)
@@ -39,6 +43,7 @@ def mpf_mul(tuple x, tuple y, int prec=0, str rnd='d'):
39
43
MPF_mul(& tmp1, & tmp1, & tmp2, opts)
40
44
return MPF_to_tuple(& tmp1)
41
45
46
+
42
47
def mpf_div (tuple x , tuple y , int prec , str rnd = ' d' ):
43
48
cdef MPopts opts
44
49
MPF_set_tuple(& tmp1, x)
@@ -48,9 +53,10 @@ def mpf_div(tuple x, tuple y, int prec, str rnd='d'):
48
53
MPF_div(& tmp1, & tmp1, & tmp2, opts)
49
54
return MPF_to_tuple(& tmp1)
50
55
56
+
51
57
def mpf_sqrt (tuple x , int prec , str rnd = ' d' ):
52
58
"""
53
- Computes sqrt(x) with mpf value tuples.
59
+ Compute sqrt(x) with mpf value tuples.
54
60
55
61
EXAMPLES::
56
62
@@ -59,7 +65,6 @@ def mpf_sqrt(tuple x, int prec, str rnd='d'):
59
65
sage: y = mpf_sqrt(x, 53, 'n')
60
66
sage: to_float(y)
61
67
1.4142135623730951
62
-
63
68
"""
64
69
if x[0 ]:
65
70
import mpmath.libmp as libmp
@@ -71,9 +76,10 @@ def mpf_sqrt(tuple x, int prec, str rnd='d'):
71
76
MPF_sqrt(& tmp1, & tmp1, opts)
72
77
return MPF_to_tuple(& tmp1)
73
78
79
+
74
80
def mpf_log (tuple x , int prec , str rnd = ' d' ):
75
81
"""
76
- Computes log(x) with mpf value tuples.
82
+ Compute log(x) with mpf value tuples.
77
83
78
84
EXAMPLES::
79
85
@@ -82,7 +88,6 @@ def mpf_log(tuple x, int prec, str rnd='d'):
82
88
sage: y = mpf_log(x, 53, 'n')
83
89
sage: to_float(y)
84
90
0.6931471805599453
85
-
86
91
"""
87
92
if x[0 ]:
88
93
import mpmath.libmp as libmp
@@ -94,9 +99,10 @@ def mpf_log(tuple x, int prec, str rnd='d'):
94
99
MPF_log(& tmp1, & tmp1, opts)
95
100
return MPF_to_tuple(& tmp1)
96
101
102
+
97
103
def mpf_exp (tuple x , int prec , str rnd = ' d' ):
98
104
"""
99
- Computes exp(x) with mpf value tuples.
105
+ Compute exp(x) with mpf value tuples.
100
106
101
107
EXAMPLES::
102
108
@@ -105,7 +111,6 @@ def mpf_exp(tuple x, int prec, str rnd='d'):
105
111
sage: z = mpf_exp(x, 53, 'n')
106
112
sage: to_float(z)
107
113
7.38905609893065
108
-
109
114
"""
110
115
cdef MPopts opts
111
116
MPF_set_tuple(& tmp1, x)
@@ -114,9 +119,10 @@ def mpf_exp(tuple x, int prec, str rnd='d'):
114
119
MPF_exp(& tmp1, & tmp1, opts)
115
120
return MPF_to_tuple(& tmp1)
116
121
122
+
117
123
def mpf_cos (tuple x , int prec , str rnd = ' d' ):
118
124
"""
119
- Computes cos(x) with mpf value tuples.
125
+ Compute cos(x) with mpf value tuples.
120
126
121
127
EXAMPLES::
122
128
@@ -125,7 +131,6 @@ def mpf_cos(tuple x, int prec, str rnd='d'):
125
131
sage: y = mpf_cos(x, 53, 'n')
126
132
sage: to_float(y)
127
133
0.5403023058681398
128
-
129
134
"""
130
135
cdef MPopts opts
131
136
MPF_set_tuple(& tmp1, x)
@@ -134,9 +139,10 @@ def mpf_cos(tuple x, int prec, str rnd='d'):
134
139
MPF_cos(& tmp1, & tmp1, opts)
135
140
return MPF_to_tuple(& tmp1)
136
141
142
+
137
143
def mpf_sin (tuple x , int prec , str rnd = ' d' ):
138
144
"""
139
- Computes sin(x) with mpf value tuples.
145
+ Compute sin(x) with mpf value tuples.
140
146
141
147
EXAMPLES::
142
148
@@ -145,7 +151,6 @@ def mpf_sin(tuple x, int prec, str rnd='d'):
145
151
sage: y = mpf_sin(x, 53, 'n')
146
152
sage: to_float(y)
147
153
0.8414709848078965
148
-
149
154
"""
150
155
cdef MPopts opts
151
156
MPF_set_tuple(& tmp1, x)
@@ -154,9 +159,10 @@ def mpf_sin(tuple x, int prec, str rnd='d'):
154
159
MPF_sin(& tmp1, & tmp1, opts)
155
160
return MPF_to_tuple(& tmp1)
156
161
162
+
157
163
def mpc_sqrt (tuple z , int prec , str rnd = ' d' ):
158
164
"""
159
- Computes sqrt(z) with mpc value tuples.
165
+ Compute sqrt(z) with mpc value tuples.
160
166
161
167
EXAMPLES::
162
168
@@ -176,9 +182,10 @@ def mpc_sqrt(tuple z, int prec, str rnd='d'):
176
182
MPF_complex_sqrt(& tmp1, & tmp2, & tmp1, & tmp2, opts)
177
183
return MPF_to_tuple(& tmp1), MPF_to_tuple(& tmp2)
178
184
185
+
179
186
def mpc_exp (tuple z , int prec , str rnd = ' d' ):
180
187
"""
181
- Computes exp(z) with mpc value tuples.
188
+ Compute exp(z) with mpc value tuples.
182
189
183
190
EXAMPLES::
184
191
@@ -198,9 +205,10 @@ def mpc_exp(tuple z, int prec, str rnd='d'):
198
205
MPF_complex_exp(& tmp1, & tmp2, & tmp1, & tmp2, opts)
199
206
return MPF_to_tuple(& tmp1), MPF_to_tuple(& tmp2)
200
207
208
+
201
209
def mpf_pow (tuple x , tuple y , int prec , str rnd = ' d' ):
202
210
"""
203
- Computes x ^ y with mpf value tuples.
211
+ Compute x ^ y with mpf value tuples.
204
212
205
213
EXAMPLES::
206
214
0 commit comments