Files
2025-02-Numerical/lib/nr/cpp/recipes/betai.cpp
2025-09-12 18:55:25 +09:00

18 lines
383 B
C++

#include <cmath>
#include "nr.h"
using namespace std;
DP NR::betai(const DP a, const DP b, const DP x)
{
DP bt;
if (x < 0.0 || x > 1.0) nrerror("Bad x in routine betai");
if (x == 0.0 || x == 1.0) bt=0.0;
else
bt=exp(gammln(a+b)-gammln(a)-gammln(b)+a*log(x)+b*log(1.0-x));
if (x < (a+1.0)/(a+b+2.0))
return bt*betacf(a,b,x)/a;
else
return 1.0-bt*betacf(b,a,1.0-x)/b;
}