在iOS上计算十进制(即伽马函数)的阶乘

在iOS上计算十进制(即伽马函数)的阶乘,ios,math,ios7,Ios,Math,Ios7,我需要在iOS上计算十进制数的阶乘,比如说6.4。我试过了 double myFactorial = gamma(6.4); 但出现错误“'gamma不可用”:在iOS上不可用”。有没有办法将gamma函数添加到iOS中?您是否尝试过: tgamma(6.4) 我看到它在我的代码中工作 还有: double tgamma (double x) float tgammaf (float x) long double tgammal (long double x) 您可以尝试这样的逻辑,这可能

我需要在iOS上计算十进制数的阶乘,比如说6.4。我试过了

double myFactorial = gamma(6.4);
但出现错误“'gamma不可用”:在iOS上不可用”。有没有办法将gamma函数添加到iOS中?

您是否尝试过:

tgamma(6.4)
我看到它在我的代码中工作

还有:

double tgamma (double x)
float tgammaf (float x)
long double tgammal (long double x)
您可以尝试这样的逻辑,这可能对您很有帮助。
-(int)阶乘:(int)操作数
{
如果“在此处输入代码”(操作数<0)
返回-1;
else if(操作数>1)
返回操作数*[自阶乘:操作数-1];
其他的
返回1;
}
然后

- (double)factorial:(double)operand
{
    double output = operand;

    if      (output == 0) output = 1; // factorial of 0 is 1
    else if (output < 0)  output = NAN;
    else if (output > 0)
    {
        if (fmod(output, floor(output)) == 0) // integer
            output = round(exp(lgamma(output + 1)));
        else // natural number
            output = exp(lgamma(output + 1));
    }

    return output;
}

- (double)n:(double)n chooseR:(double)r
{
    return round(exp((lgamma(n+1)) - (lgamma(r+1) + lgamma(n-r+1))));
}

- (double)n:(double)n pickR:(double)r
{
    return round(exp(lgamma(n+1) - lgamma(n-r+1)));
}
-(双)阶乘:(双)操作数
{
双输出=操作数;
如果(output==0)output=1;//0的阶乘是1
如果(输出<0)输出=NAN,则为else;
else if(输出>0)
{
if(fmod(输出,楼层(输出))==0)//整数
输出=四舍五入(经验(lgamma(输出+1));
else//自然数
输出=exp(lgamma(输出+1));
}
返回输出;
}
-(双)n:(双)n选择器:(双)r
{
返回回合(经验((LGAMA(n+1))-(LGAMA(r+1)+LGAMA(n-r+1));
}
-(双)n:(双)n选择器r:(双)r
{
返回回合(经验(LGAMA(n+1)-LGAMA(n-r+1));
}

lgama*函数是gamma函数的对数。对于伽玛函数,使用
tgamma
tgammaf
tgammal
- (double)factorial:(double)operand
{
    double output = operand;

    if      (output == 0) output = 1; // factorial of 0 is 1
    else if (output < 0)  output = NAN;
    else if (output > 0)
    {
        if (fmod(output, floor(output)) == 0) // integer
            output = round(exp(lgamma(output + 1)));
        else // natural number
            output = exp(lgamma(output + 1));
    }

    return output;
}

- (double)n:(double)n chooseR:(double)r
{
    return round(exp((lgamma(n+1)) - (lgamma(r+1) + lgamma(n-r+1))));
}

- (double)n:(double)n pickR:(double)r
{
    return round(exp(lgamma(n+1) - lgamma(n-r+1)));
}