Something like the following might be more appropriate:
"%~=%"<-function(x,y){
if(is.numeric(x) & is.numeric(y)){
xpy <- (x+y)
xpy[xpy==0] <- 4*.Machine$double.eps
return((abs(x-y)/xpy)<(4*.Machine$double.eps))
}
else return(x==y)
}This is close but not quite there yet, I don't think. Consider the following:
> 1e-50 %~=% 2e-50 [1] FALSE > 0 %~=% 2e-50 [1] FALSE > 1e+50 %~=% 2e+50 [1] FALSE > 0 %~=% 2e+50 [1] FALSE > 11e-50 %~=% 2e-50 [1] FALSE > 1 %~=% (1+.Machine$double.eps) [1] TRUE > 1 %~=% (1+3*.Machine$double.eps) [1] TRUE
?????? spencer graves
(Ted Harding) wrote:
At 7/14/2003 at 03:29 AM, Marc Vandemeulebroecke wrote: Dear R programmers,
is there a sensible explanation for the following behaviour?
seq(0.7, 0.9, by=0.1) == 0.8
[1] FALSE FALSE FALSE
Yet another %**% function ...
"%~=%"<-function(x,y){abs(x-y)<1e-15} seq(0.7, 0.9, by=0.1) %~=% 0.8
[1] FALSE TRUE FALSE
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 167 1972 Date: 14-Jul-03 Time: 22:16:38 ------------------------------ XFMail ------------------------------
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
