[R] prod and F90 product
Duncan Murdoch
murdoch.duncan at gmail.com
Fri Nov 8 01:28:38 CET 2013
On 13-11-07 6:39 PM, Filippo 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?
Some intermediate results may be stored with 80 bit precision in R, 64
bit precision in Fortran.
Duncan Murdoch
More information about the R-help
mailing list