(这是计算椭圆周长的一种方法,a和b是半长轴和半短轴,h定义为:
h = (ab)^2/(a+b)^2)
阶乘函数可以通过 Gamma 函数扩展到负值,该函数是为所有非负整数的实数定义的。
在编码严重时,我尝试了 boost::math::factorial 和 boost::math::tgamma ,它们给出的结果仅低至 -1 (不包括)-1.5 例如给出错误。
#include <iostream>
#include <boost/math/special_functions/factorials.hpp>
int main()
{
double x;
double f;
double tg;
x = -0.5;
f = boost::math::factorial<double>(x);
tg = boost::math::tgamma<double>(x);
cout << "factorial of " << x << " = " << f << endl;
cout << "tgamma of " << x << " = " << tg << endl << endl;
x = -1.5;
f = boost::math::factorial<double>(x);
tg = boost::math::tgamma<double>(x);
cout …Run Code Online (Sandbox Code Playgroud)