[R] Precision

Duncan Murdoch murdoch at stats.uwo.ca
Wed Apr 6 14:46:08 CEST 2005


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?

For most floating point operations R uses "double precision", which 
gives about 18-19 significant digit precision.  Leading zeros don't count.

Duncan Murdoch

>
> 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)}
> ---------------------------------------
>   1   1.000000000000000000000000
>   2   0.785398163397448278999491
>   3   0.523598775598298815658893
>   4   0.308425137534042437259529
>   5   0.164493406684822623953224
>   6   0.080745512188280771370685
>   7   0.036912234143214060766436
>   8   0.015854344243815498421979
>   9   0.006442400200661534299951
>  10   0.002490394570192719803786
>  11   0.000919972597358349329817
>  12   0.000325991886927389960208
>  13   0.000111160736667881195885
>  14   0.000036576204182177245747
>  15   0.000011640725122781503579
>  16   0.000003590860448591509251
>  17   0.000001075600486123191399
>  18   0.000000313361689037812061
>  19   0.000000088923646984269168
>  20   0.000000024611369504941992
>  21   0.000000006651473240385528
>  22   0.000000001757247673443401
>  23   0.000000000454265640598788
>  24   0.000000000115011591279740
>  25   0.000000000028542351985668
>  26   0.000000000006948453273887
>  27   0.000000000001660526728044
>  28   0.000000000000389807317126
>  29   0.000000000000089943078792
>  30   0.000000000000020410263397
>  31   0.000000000000004557492187
>  32   0.000000000000001001886462
>  33   0.000000000000000216936121
>  34   0.000000000000000046287046
>  35   0.000000000000000009736070
>  36   0.000000000000000002019653
>  37   0.000000000000000000413335
>  38   0.000000000000000000083486
>  39   0.000000000000000000016648
>  40   0.000000000000000000003278
>
>------------------------------------------------------------------------
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list