[Rd] long double, C, fortran

Simon Urbanek simon.urbanek at r-project.org
Thu Oct 7 20:57:14 CEST 2010

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?



More information about the R-devel mailing list