lgamma函数怎么调用,找不到库函数

caoeryingzi 2009-06-21 10:43:11
vc中,要调用lgamma函数,可是,调用了math.h之后,仍然无法识别。

我想问一下这个函数如何调用。谢谢
...全文
500 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lingyin55 2009-06-21
  • 打赏
  • 举报
回复
*nix 数学库里面有lgamma. 是log gamma. 如果你加了windows下面的math库还Link不到的话,那就自己编一个好了。下面是lgamma实现的功能。


NAME
lgamma - log gamma function

SYNOPSIS
#include <math.h>

double lgamma(double x);
float lgammaf(float x);
long double lgammal(long double x);

double lgamma_r(double x, int *signp);
float lgammaf_r(float x, int *signp);
long double lgammal_r(long double x, int *signp);

DESCRIPTION
The Gamma function is defined by

Gamma(x) = integral from 0 to infinity of t^(x-1) e^-t dt

It is defined for every real number except for nonpositive integers.
For nonnegative integral m one has Gamma(m+1) = m!

and, more generally, for all x:

Gamma(x+1) = x * Gamma(x)

For x < 0.5 one can use

Gamma(x) * Gamma(1-x) = PI/sin(PI*x)

The lgamma() function returns the natural logarithm of the absolute
value of the Gamma function. The sign of the Gamma function is
returned in the external integer signgam declared in <math.h>. It is 1
when the Gamma function is positive or zero, -1 when it is negative.

Since using a constant location signgam is not thread-safe, the func-
tions lgamma_r() etc. have been introduced; they return this sign via
the parameter signp.

For nonpositive integer values of x, lgamma() returns HUGE_VAL, sets
errno to ERANGE and raises the zero divide exception. (Similarly,
lgammaf() returns HUGE_VALF and lgammal() returns HUGE_VALL.)

CONFORMING TO
C99, SVID 3, BSD 4.3
老邓 2009-06-21
  • 打赏
  • 举报
回复
GCC 4.4通过:
#include <math.h>
#include <stdio.h>

int main(void)
{
double x=42, g_at_x;

g_at_x = exp(lgamma(x)); /* g_at_x = 3.345253e+49 */
printf ("The value of G(%4.2f) is %7.2e\n", x, g_at_x);
return 0;
}

输出:
The value of G(42.00) is 3.35e+049

Process returned 0 (0x0) execution time : 0.094 s
Press any key to continue.
老邓 2009-06-21
  • 打赏
  • 举报
回复
Format

#define _XOPEN_SOURCE
#include <math.h>

double lgamma(double x);
extern int signgam;
int *__signgam(void);C99

#define _ISOC99_SOURCE
#include <math.h>

double lgamma(double x);
float lgammaf(float x);
long double lgammal(long double x);

64,660

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧