bug-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gsl] bug and patch for cdf/beta.c


From: Jason Stover
Subject: [Bug-gsl] bug and patch for cdf/beta.c
Date: Mon, 27 Sep 2004 15:26:27 +0000
User-agent: Mutt/1.4.2.1i

The following program shows gsl_cdf_beta_P computes
1-Pr(X<t) instead of Pr(X<t) for a beta-distributed
random variable X when t > 1. gsl_cdf_beta_Q computes
Pr(X<t) instead of 1-Pr(X<t) when t <= 0.0.

#include <stdio.h>
#include <gsl/gsl_cdf.h>
int main()
{
  double x;
  double p;
  double a;
  double b = 2.0;
  
  x = gsl_cdf_beta_P(1.1,a,b);
  printf ("gsl_cdf_beta_P(1.1,a,b) = \t%f\n",x);
  x = gsl_cdf_beta_Q(-0.1,a,b);
  printf ("gsl_cdf_beta_Q(0.0,a,b) = \t%f\n",x);
  exit(0);
}

Patch included:

Index: beta.c
===================================================================
RCS file: /cvs/gsl/gsl/cdf/beta.c,v
retrieving revision 1.2
diff -u -r1.2 beta.c
--- beta.c      26 Jul 2003 13:47:53 -0000      1.2
+++ beta.c      27 Sep 2004 15:14:32 -0000
@@ -30,11 +30,14 @@
 {
   double P;
 
-  if (x <= 0.0 || x > 1.0)
+  if (x <= 0.0 )
     {
       return 0.0;
     }
-
+  if ( x > 1.0 )
+    {
+      return 1.0;
+    }
   P = beta_inc_AXPY (1.0, 0.0, a, b, x);
 
   return P;
@@ -45,10 +48,14 @@
 {
   double P;
 
-  if (x < 0.0 || x >= 1.0)
+  if ( x >= 1.0)
     {
       return 0.0;
     }
+  if ( x <= 0.0 )
+    {
+      return 1.0;
+    }
 
   P = beta_inc_AXPY (-1.0, 1.0, a, b, x);

-- 
address@hidden
SDF Public Access UNIX System - http://sdf.lonestar.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]