[Rd] precision of do_arith() in arithmetic.c

Berend Hasselman bhh at xs4all.nl
Wed May 24 14:08:03 CEST 2017


> On 24 May 2017, at 04:24, M Kim <mkim0710 at gmail.com> wrote:
> 
> To the R development team:
> 
> First of all, thank you so much for maintaining wonderful R software.
> 
> Perhaps, Dr. Ahn has just reported an error on the wilcox.test() function,
> and suggesting that an error may arise from abs() and rank().
> 
> 
> I just had a quick check that the problem may come from the precision of
> the results of arithmetic functions.
> 
> 
> 87.7-89.1+1.4
> # > 87.7-89.1+1.4
> # [1] 8.437695e-15
> 

R FAQ 7.31.
See https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

Berend

> I checked that do_arith() in arithmetic.c is using double type (8 byte) for
> PLUSOP, MINUSOP, TIMESOP, DIVOP etc.
> 
> https://github.com/wch/r-source/blob/f68b30e3b5479d84adbff516d48d4722a574dc82/src/main/arithmetic.c
> 
> 
> I have two thoughts:
> 
> (1) in the rank() function, we may round at less than 14 decimal places by
> default?
> 
> (2) using long double type (10 byte) instead of double type (8 byte) by
> default in the arithmetic function could be helpful for preventing
> embarassment?
> 
> Perhaps, R may provide the arithmetic function with various variable types,
> if some application needs.
> 
> 
> Thanks.
> 
> Min-hyung
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list