stopifnot(all.equal(besselJs(1:10, 1), # our R code
besselJ (1:10, 1)))# internal C code w/ different algorithm
## Large 'nu' ...
x <- (0:20)/4
(bx <- besselJ(x, nu=200))# base R's -- gives (mostly wrong) warnings
if(require("Rmpfr")) { ## Use high precision, notably large exponent range, numbers:
Bx <- besselJs(mpfr(x, 64), nu=200)
all.equal(Bx, bx, tol = 1e-15)# TRUE -- warnings were mostly wrong; specifically:
cbind(bx, Bx)
signif(asNumeric(1 - (bx/Bx)[19:21]), 4) # only [19] had lost accuracy
## With*out* mpfr numbers -- using log -- is accurate (here)
lbx <- besselJs( x, nu=200, log=TRUE)
lBx <- besselJs(mpfr(x, 64), nu=200, log=TRUE)
cbind(x, lbx, lBx)
stopifnot(all.equal(asNumeric(log(Bx)), lbx, tol=1e-15),
all.equal(lBx, lbx, tol=4e-16))
} # Rmpfr
Run the code above in your browser using DataLab