R-alpha: Buglet & patch in dbinom.c (0.50 - PreR 7)
Martin Maechler
Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 15 Apr 97 23:36:12 +0200
dbinom(k, n, prob = 0) # or prob=1 would not work;
The following patch makes it work (in $RHOME/src/math/ ) :
--- dbinom.c~ Sun Nov 24 23:43:10 1996
+++ dbinom.c Tue Apr 15 23:31:46 1997
@@ -23,9 +23,13 @@
{
x = floor(x + 0.5);
n = floor(n + 0.5);
- if (n <= 0.0 || p <= 0.0 || p >= 1.0)
+ if (n <= 0.0 || p < 0.0 || p > 1.0)
DOMAIN_ERROR;
if (x < 0.0 || x > n)
return 0.0;
+ if (p == 0.0)
+ return (x == 0) ? 1.0 : 0.0;
+ if (p == 1.0)
+ return (x == n) ? 1.0 : 0.0;
return exp(lfastchoose(n, x) + log(p) * x + (n - x) * log(1.0 - p));
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-