28
28
Base. showerror (io:: IO , err:: AmosException ) = print (io, " AmosException with id $(err. id) : $(err. msg) " )
29
29
30
30
# # Airy functions
31
- let
32
- const ai:: Array{Float64,1} = Array {Float64} (2 )
33
- const ae:: Array{Int32,1} = Array {Int32} (2 )
34
- global _airy, _biry
35
- function _airy (z:: Complex128 , id:: Int32 , kode:: Int32 )
36
- ccall ((:zairy_ ,openspecfun), Void,
37
- (Ptr{Float64}, Ptr{Float64}, Ptr{Int32}, Ptr{Int32},
38
- Ptr{Float64}, Ptr{Float64}, Ptr{Int32}, Ptr{Int32}),
39
- & real (z), & imag (z),
40
- & id, & kode,
41
- pointer (ai,1 ), pointer (ai,2 ),
42
- pointer (ae,1 ), pointer (ae,2 ))
43
- if ae[2 ] == 0 || ae[2 ] == 3
44
- return complex (ai[1 ],ai[2 ])
45
- else
46
- throw (AmosException (ae[2 ]))
47
- end
31
+ function _airy (z:: Complex128 , id:: Int32 , kode:: Int32 )
32
+ ai1, ai2 = Ref {Float64} (), Ref {Float64} ()
33
+ ae1, ae2 = Ref {Int32} (), Ref {Int32} ()
34
+
35
+ ccall ((:zairy_ ,openspecfun), Void,
36
+ (Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32},
37
+ Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32}),
38
+ real (z), imag (z), id, kode,
39
+ ai1, ai2, ae1, ae2)
40
+
41
+ if ae2[] == 0 || ae2[] == 3 # ignore underflow and less than half machine accuracy loss
42
+ return complex (ai1[], ai2[])
43
+ else
44
+ throw (AmosException (ae2[]))
48
45
end
49
- function _biry (z:: Complex128 , id:: Int32 , kode:: Int32 )
50
- ccall ((:zbiry_ ,openspecfun), Void,
51
- (Ptr{Float64}, Ptr{Float64}, Ptr{Int32}, Ptr{Int32},
52
- Ptr{Float64}, Ptr{Float64}, Ptr{Int32}),
53
- & real (z), & imag (z),
54
- & id, & kode,
55
- pointer (ai,1 ), pointer (ai,2 ),
56
- pointer (ae,1 ))
57
- if ae[1 ] == 0 || ae[1 ] == 3 # ignore underflow
58
- return complex (ai[1 ],ai[2 ])
59
- else
60
- throw (AmosException (ae[2 ]))
61
- end
46
+ end
47
+
48
+ function _biry (z:: Complex128 , id:: Int32 , kode:: Int32 )
49
+ ai1, ai2 = Ref {Float64} (), Ref {Float64} ()
50
+ ae1 = Ref {Int32} ()
51
+
52
+ ccall ((:zbiry_ ,openspecfun), Void,
53
+ (Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32},
54
+ Ref{Float64}, Ref{Float64}, Ref{Int32}),
55
+ real (z), imag (z), id, kode,
56
+ ai1, ai2, ae1)
57
+
58
+ if ae1[] == 0 || ae1[] == 3 # ignore less than half machine accuracy loss
59
+ return complex (ai1[], ai2[])
60
+ else
61
+ throw (AmosException (ae1[]))
62
62
end
63
63
end
64
64
145
145
146
146
function airyai (x:: BigFloat )
147
147
z = BigFloat ()
148
- ccall ((:mpfr_ai , :libmpfr ), Int32, (Ptr {BigFloat}, Ptr {BigFloat}, Int32), & z, & x, ROUNDING_MODE[])
148
+ ccall ((:mpfr_ai , :libmpfr ), Int32, (Ref {BigFloat}, Ref {BigFloat}, Int32), z, x, ROUNDING_MODE[])
149
149
return z
150
150
end
151
151
@@ -174,79 +174,89 @@ for jy in ("j","y"), nu in (0,1)
174
174
end
175
175
176
176
177
- const cy = Array {Float64} (2 )
178
- const ae = Array {Int32} (2 )
179
- const wrk = Array {Float64} (2 )
180
-
181
177
function _besselh (nu:: Float64 , k:: Int32 , z:: Complex128 , kode:: Int32 )
178
+ ai1, ai2 = Ref {Float64} (), Ref {Float64} ()
179
+ ae1, ae2 = Ref {Int32} (), Ref {Int32} ()
180
+
182
181
ccall ((:zbesh_ ,openspecfun), Void,
183
- (Ptr {Float64}, Ptr {Float64}, Ptr {Float64}, Ptr {Int32}, Ptr {Int32},
184
- Ptr{Int32}, Ptr {Float64}, Ptr {Float64}, Ptr {Int32}, Ptr {Int32}),
185
- & real (z), & imag (z), & nu, & kode, & k, & 1 ,
186
- pointer (cy, 1 ), pointer (cy, 2 ),
187
- pointer (ae, 1 ), pointer (ae, 2 ))
188
- if ae[ 2 ] == 0 || ae[ 2 ] == 3
189
- return complex (cy[ 1 ],cy[ 2 ])
182
+ (Ref {Float64}, Ref {Float64}, Ref {Float64}, Ref {Int32}, Ref {Int32}, Ref{Int },
183
+ Ref {Float64}, Ref {Float64}, Ref {Int32}, Ref {Int32}),
184
+ real (z), imag (z), nu, kode, k, 1 ,
185
+ ai1, ai2, ae1, ae2)
186
+
187
+ if ae2[ ] == 0 || ae2[ ] == 3
188
+ return complex (ai1[], ai2[ ])
190
189
else
191
- throw (AmosException (ae[ 2 ]))
190
+ throw (AmosException (ae2[ ]))
192
191
end
193
192
end
194
193
195
194
function _besseli (nu:: Float64 , z:: Complex128 , kode:: Int32 )
195
+ ai1, ai2 = Ref {Float64} (), Ref {Float64} ()
196
+ ae1, ae2 = Ref {Int32} (), Ref {Int32} ()
197
+
196
198
ccall ((:zbesi_ ,openspecfun), Void,
197
- (Ptr {Float64}, Ptr {Float64}, Ptr {Float64}, Ptr {Int32}, Ptr {Int32},
198
- Ptr {Float64}, Ptr {Float64}, Ptr {Int32}, Ptr {Int32}),
199
- & real (z), & imag (z), & nu, & kode, & 1 ,
200
- pointer (cy, 1 ), pointer (cy, 2 ),
201
- pointer (ae, 1 ), pointer (ae, 2 ))
202
- if ae[ 2 ] == 0 || ae[ 2 ] == 3
203
- return complex (cy[ 1 ],cy[ 2 ])
199
+ (Ref {Float64}, Ref {Float64}, Ref {Float64}, Ref {Int32}, Ref {Int32},
200
+ Ref {Float64}, Ref {Float64}, Ref {Int32}, Ref {Int32}),
201
+ real (z), imag (z), nu, kode, 1 ,
202
+ ai1, ai2, ae1, ae2)
203
+
204
+ if ae2[ ] == 0 || ae2[ ] == 3
205
+ return complex (ai1[], ai2[ ])
204
206
else
205
- throw (AmosException (ae[ 2 ]))
207
+ throw (AmosException (ae2[ ]))
206
208
end
207
209
end
208
210
209
211
function _besselj (nu:: Float64 , z:: Complex128 , kode:: Int32 )
212
+ ai1, ai2 = Ref {Float64} (), Ref {Float64} ()
213
+ ae1, ae2 = Ref {Int32} (), Ref {Int32} ()
214
+
210
215
ccall ((:zbesj_ ,openspecfun), Void,
211
- (Ptr {Float64}, Ptr {Float64}, Ptr {Float64}, Ptr {Int32}, Ptr {Int32},
212
- Ptr {Float64}, Ptr {Float64}, Ptr {Int32}, Ptr {Int32}),
213
- & real (z), & imag (z), & nu, & kode, & 1 ,
214
- pointer (cy, 1 ), pointer (cy, 2 ),
215
- pointer (ae, 1 ), pointer (ae, 2 ))
216
- if ae[ 2 ] == 0 || ae[ 2 ] == 3
217
- return complex (cy[ 1 ],cy[ 2 ])
216
+ (Ref {Float64}, Ref {Float64}, Ref {Float64}, Ref {Int32}, Ref {Int32},
217
+ Ref {Float64}, Ref {Float64}, Ref {Int32}, Ref {Int32}),
218
+ real (z), imag (z), nu, kode, 1 ,
219
+ ai1, ai2, ae1, ae2)
220
+
221
+ if ae2[ ] == 0 || ae2[ ] == 3
222
+ return complex (ai1[], ai2[ ])
218
223
else
219
- throw (AmosException (ae[ 2 ]))
224
+ throw (AmosException (ae2[ ]))
220
225
end
221
226
end
222
227
223
228
function _besselk (nu:: Float64 , z:: Complex128 , kode:: Int32 )
229
+ ai1, ai2 = Ref {Float64} (), Ref {Float64} ()
230
+ ae1, ae2 = Ref {Int32} (), Ref {Int32} ()
231
+
224
232
ccall ((:zbesk_ ,openspecfun), Void,
225
- (Ptr {Float64}, Ptr {Float64}, Ptr {Float64}, Ptr {Int32}, Ptr {Int32},
226
- Ptr {Float64}, Ptr {Float64}, Ptr {Int32}, Ptr {Int32}),
227
- & real (z), & imag (z), & nu, & kode, & 1 ,
228
- pointer (cy, 1 ), pointer (cy, 2 ),
229
- pointer (ae, 1 ), pointer (ae, 2 ))
230
- if ae[ 2 ] == 0 || ae[ 2 ] == 3
231
- return complex (cy[ 1 ],cy[ 2 ])
233
+ (Ref {Float64}, Ref {Float64}, Ref {Float64}, Ref {Int32}, Ref {Int32},
234
+ Ref {Float64}, Ref {Float64}, Ref {Int32}, Ref {Int32}),
235
+ real (z), imag (z), nu, kode, 1 ,
236
+ ai1, ai2, ae1, ae2)
237
+
238
+ if ae2[ ] == 0 || ae2[ ] == 3
239
+ return complex (ai1[], ai2[ ])
232
240
else
233
- throw (AmosException (ae[ 2 ]))
241
+ throw (AmosException (ae2[ ]))
234
242
end
235
243
end
236
244
237
245
function _bessely (nu:: Float64 , z:: Complex128 , kode:: Int32 )
246
+ ai1, ai2 = Ref {Float64} (), Ref {Float64} ()
247
+ ae1, ae2 = Ref {Int32} (), Ref {Int32} ()
248
+ wrk1, wrk2 = Ref {Float64} (), Ref {Float64} ()
249
+
238
250
ccall ((:zbesy_ ,openspecfun), Void,
239
- (Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Ptr{Int32},
240
- Ptr{Int32}, Ptr{Float64}, Ptr{Float64}, Ptr{Int32},
241
- Ptr{Float64}, Ptr{Float64}, Ptr{Int32}),
242
- & real (z), & imag (z), & nu, & kode, & 1 ,
243
- pointer (cy,1 ), pointer (cy,2 ),
244
- pointer (ae,1 ), pointer (wrk,1 ),
245
- pointer (wrk,2 ), pointer (ae,2 ))
246
- if ae[2 ] == 0 || ae[2 ] == 3
247
- return complex (cy[1 ],cy[2 ])
251
+ (Ref{Float64}, Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32},
252
+ Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Float64}, Ref{Float64}, Ref{Int32}),
253
+ real (z), imag (z), nu, kode, 1 ,
254
+ ai1, ai2, ae1, wrk1, wrk2, ae2)
255
+
256
+ if ae2[] == 0 || ae2[] == 3
257
+ return complex (ai1[], ai2[])
248
258
else
249
- throw (AmosException (ae[ 2 ]))
259
+ throw (AmosException (ae2[ ]))
250
260
end
251
261
end
252
262
@@ -520,7 +530,7 @@ Bessel function of the first kind of order 0, ``J_0(x)``.
520
530
"""
521
531
function besselj0 (x:: BigFloat )
522
532
z = BigFloat ()
523
- ccall ((:mpfr_j0 , :libmpfr ), Int32, (Ptr {BigFloat}, Ptr {BigFloat}, Int32), & z, & x, ROUNDING_MODE[])
533
+ ccall ((:mpfr_j0 , :libmpfr ), Int32, (Ref {BigFloat}, Ref {BigFloat}, Int32), z, x, ROUNDING_MODE[])
524
534
return z
525
535
end
526
536
@@ -531,13 +541,13 @@ Bessel function of the first kind of order 1, ``J_1(x)``.
531
541
"""
532
542
function besselj1 (x:: BigFloat )
533
543
z = BigFloat ()
534
- ccall ((:mpfr_j1 , :libmpfr ), Int32, (Ptr {BigFloat}, Ptr {BigFloat}, Int32), & z, & x, ROUNDING_MODE[])
544
+ ccall ((:mpfr_j1 , :libmpfr ), Int32, (Ref {BigFloat}, Ref {BigFloat}, Int32), z, x, ROUNDING_MODE[])
535
545
return z
536
546
end
537
547
538
548
function besselj (n:: Integer , x:: BigFloat )
539
549
z = BigFloat ()
540
- ccall ((:mpfr_jn , :libmpfr ), Int32, (Ptr {BigFloat}, Clong, Ptr {BigFloat}, Int32), & z, n, & x, ROUNDING_MODE[])
550
+ ccall ((:mpfr_jn , :libmpfr ), Int32, (Ref {BigFloat}, Clong, Ref {BigFloat}, Int32), z, n, x, ROUNDING_MODE[])
541
551
return z
542
552
end
543
553
@@ -551,7 +561,7 @@ function bessely0(x::BigFloat)
551
561
throw (DomainError (x, " `x` must be nonnegative." ))
552
562
end
553
563
z = BigFloat ()
554
- ccall ((:mpfr_y0 , :libmpfr ), Int32, (Ptr {BigFloat}, Ptr {BigFloat}, Int32), & z, & x, ROUNDING_MODE[])
564
+ ccall ((:mpfr_y0 , :libmpfr ), Int32, (Ref {BigFloat}, Ref {BigFloat}, Int32), z, x, ROUNDING_MODE[])
555
565
return z
556
566
end
557
567
@@ -565,7 +575,7 @@ function bessely1(x::BigFloat)
565
575
throw (DomainError (x, " `x` must be nonnegative." ))
566
576
end
567
577
z = BigFloat ()
568
- ccall ((:mpfr_y1 , :libmpfr ), Int32, (Ptr {BigFloat}, Ptr {BigFloat}, Int32), & z, & x, ROUNDING_MODE[])
578
+ ccall ((:mpfr_y1 , :libmpfr ), Int32, (Ref {BigFloat}, Ref {BigFloat}, Int32), z, x, ROUNDING_MODE[])
569
579
return z
570
580
end
571
581
@@ -574,7 +584,7 @@ function bessely(n::Integer, x::BigFloat)
574
584
throw (DomainError (x, " `x` must be nonnegative." ))
575
585
end
576
586
z = BigFloat ()
577
- ccall ((:mpfr_yn , :libmpfr ), Int32, (Ptr {BigFloat}, Clong, Ptr {BigFloat}, Int32), & z, n, & x, ROUNDING_MODE[])
587
+ ccall ((:mpfr_yn , :libmpfr ), Int32, (Ref {BigFloat}, Clong, Ref {BigFloat}, Int32), z, n, x, ROUNDING_MODE[])
578
588
return z
579
589
end
580
590
0 commit comments