prod and F90 product
sounds like FAQ 7.31 Sent from my iPad
On Nov 7, 2013, at 18:39, Filippo <ingfimo at gmail.com> wrote:
Hi,
I'm having strange differences between the R function prod ad the F90 function product.
Processing the same vector C (see attachment). I get 2 different results:
prod(C) = 1.069678e-307
testProduct(C) = 0
where testProd is the following wrapping function:
testProd <- function(x) {
return(.Fortran('testProd', as.double(x), as.double(0), as.double(0), as.integer(length(x))))
}
subroutine testProd(x, p, q, n)
implicit none
integer, intent (in) :: n
double precision, intent (in) :: x(n)
double precision, intent (out) :: p
double precision, intent (out) :: q
integer :: i
p = product(x)
q=1
do i = 1, n
q = q*x(i)
end do
end subroutine testProd
I check the lowest possible number and seems to be the same for both R and F90.
Can anyone help me understanding this behaviour?
Thank you in advance
Regards,
Filippo
<C>
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.