ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
cbetai.cpp
Go to the documentation of this file.
00001 
00007 #include <fvar.hpp>
00008 #include <math.h>
00009 
00021 double betai(const double a,const double b,const double x,int maxit)
00022 {
00023   double bt;
00024 
00025   if (x < 0.0 || x > 1.0) cerr << "Bad x in routine betai" << endl;
00026   if (x == 0.0 || x == 1.0) bt=0.0;
00027   else
00028     bt=exp(gammln(a+b)-gammln(a)-gammln(b)+a*log(x)+b*log(1.0-x));
00029   if (x < (a+1.0)/(a+b+2.0))
00030     return bt*betacf(a,b,x,maxit)/a;
00031   else
00032     return 1.0-bt*betacf(b,a,1.0-x,maxit)/b;
00033 }