Googling for: What Every Computer Scientist should know about floating point arithmetic Gets you to a very enlightening pdf about these issues. Hth, ingmar
> From: "Gichangi, Anthony" <[EMAIL PROTECTED]> > Date: Fri, 19 May 2006 14:25:51 +0200 > To: R-help <[email protected]> > Subject: [R] Precision in estimating log > > Hi R-users, > > I have the following code: > > f <-function(x,p)sqrt(-(x^2)-2*log(1-p)) > > r1 <-sqrt(-2*log(1-0.95)) > > r2 <-sqrt(-2*log(0.05)) > > on executing i get the following results > >> f(r1,0.95) > [1] 0 >> >> f(r2,0.95) > [1] NaN > Warning message: > NaNs produced in: sqrt(-(x^2) - 2 * log(1 - p)) > > I tried to track the problem and found that the answer to > log(0.05) is different from the answer to log(1-0.95) which > is ofcourse not true and hence it causes problems in the code > > print(log(0.05),digit=22) > > [1] -2.9957322735539909 >> print(log(1-0.95),digit=22) > > [1] -2.99573227355399 > > > Any possible explanation ? > > Regards > Anthony > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
