From simon.urbanek at r-project.org  Thu Oct  7 20:57:14 2010
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 7 Oct 2010 14:57:14 -0400
Subject: [Rd] long double, C, fortran
In-Reply-To: <4CAE1150.2050006@rug.nl>
References: <mailman.21.1286445608.10801.r-devel@r-project.org>
	<4CAE1150.2050006@rug.nl>
Message-ID: <09250356-489B-4BA2-930C-0E9B5DBEDFD3@r-project.org>


On Oct 7, 2010, at 2:28 PM, Richard D. Morey wrote:

> I'm using .Call() to call C code from R under Windows (on an Intel Core 2 duo). The C code involves some very small numbers, and I think I'm losing precision using doubles.

The magnitude of numbers has really nothing to do with precision itself. Make sure this is really about precision and not something else. Also check your algorithm for common numerical problems (subtracting small numbers etc.).


> I thought I might use long doubles to see if I can get that precision back. I have a few questions:
> 
> 1. Does this affect the portability to other OSs or processors?

Different processors handle long doubles differently, but that is usually not an issue since you will end up passing back doubles (see below) so you simply take what you get (e.g. Intel processors actually use only fraction of the quadruple precision that long doubles offer [80 instead of 128 bits]). Although long doubles are supported on most systems these days, on some architectures this feature is emulated and thus can be slow.


> 2. I'm returning the results in a matrix. Will a matrix of REALs be sufficient for holding long doubles, or will it be cast back to doubles?

You can't use long doubles in any interface to R. You can use long doubles for intermediate calculations but you can only pass doubles between your code and R.


> 3. Will calls to FORTRAN BLAS (like dsymv, dpotrf, dpotri) still work with long doubles?
> 

No.

Cheers,
Simon



[Rd] long double, C, fortran
Simon Urbanek