[R] Precision
Jan T. Kim
jtk at cmp.uea.ac.uk
Wed Apr 6 15:36:03 CEST 2005
On Wed, Apr 06, 2005 at 02:00:58PM +0200, Josef Eschgfaeller wrote:
> How precise is R numerically? For example I
> wrote the following function for calculating
> the volume of the ball inscribed in the
> unit cube in m dimensions. In order to see what
> happens in 40 dimensions, I created an output
> of 24 digits. But how many are precise?
R uses IEEE-754 double precision floating point arithmetic (see
capabilities()), which has a 52 bit mantissa, roughly corresponding to
15 decimal digits. This is how much information is available, how much
of it is precise in the sense that it accurately reflects the quantity
you're computing depends on the computation you're doing.
> Thanks
> Josef Eschgf?ller
> Ferrara
> ---------------------------------------
> Vol = function (m)
> {if (m<=1) 1
> else Vol(m-2)*pi/(m+m)}
>
>
> for (m in 1:40)
> {x=sprintf('%2d %.24f',m,Vol(m))
> print(x)}
> ---------------------------------------
For getting an impression of "what happens", this looks ok to me. If
you're concerned that precision wanes because you get less and less
non-zero digits: that's not the case -- use the %e or %g format to
see that the number of mantissa digits does not decrease.
Best regards, Jan
--
+- Jan T. Kim -------------------------------------------------------+
| *NEW* email: jtk at cmp.uea.ac.uk |
| *NEW* WWW: http://www.cmp.uea.ac.uk/people/jtk |
*-----=< hierarchical systems are for files, not for humans >=-----*
More information about the R-help
mailing list