Permalink
Browse files

Stop ChiSquare pdf failing for 0-input

PR-URL: #114
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information...
1 parent c39d868 commit f16411c6b3bdd2a0b599077682a5b0e7f6acde7f @DaveSimons DaveSimons committed with trevnorris Dec 1, 2014
Showing with 4 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +3 −2 src/distribution.js
View
@@ -1,2 +1,3 @@
dist/docs
node_modules
+.idea
View
@@ -204,8 +204,9 @@ jStat.extend(jStat.cauchy, {
// extend chisquare function with static methods
jStat.extend(jStat.chisquare, {
pdf: function pdf(x, dof) {
- return Math.exp((dof / 2 - 1) * Math.log(x) - x / 2 - (dof / 2) *
- Math.log(2) - jStat.gammaln(dof / 2));
+ return x === 0 ? 0 :
+ Math.exp((dof / 2 - 1) * Math.log(x) - x / 2 - (dof / 2) *
+ Math.log(2) - jStat.gammaln(dof / 2));
},
cdf: function cdf(x, dof) {

0 comments on commit f16411c

Please sign in to comment.