erf.c

来自「蒙特卡罗模拟光子成像C语言版,代码简洁专业」· C语言 代码 · 共 28 行

C
28
字号
/* Supply the missing error function for windows.  Not the most
 * accurate way to calculate error functions, perhaps, but better 
 * than nothing. 
 */

/* 2/sqrt(pi) from glibc math.h */
#define M_2_SQRTPI	1.12837916709551257390

/* Abramowitz+Stegun, 7.1.5 */

double erf(double x)
{
  double coef = x;
  double e    = coef;
  double del;
  int k;

  for (k = 1; k < 30; k++) 
    {
      coef *= -x*x/k;
      del   = coef/(2.0*k+1.0);
      e    += del;
    }

  return (M_2_SQRTPI * e);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?