erfc.c

来自「spice中支持多层次元件模型仿真的可单独运行的插件源码」· C语言 代码 · 共 50 行

C
50
字号
/**********Copyright 1991 Regents of the University of California.  All rights reserved.Author:	1987 Kartikeya Mayaram, U. C. Berkeley CAD Group**********/#include <math.h>#include "numglobs.h"#include "numconst.h"#include "nummacs.h"/* erfc computes the erfc(x) the code is from sedan's derfc.f */double erfc ( x )double x;{    double sqrtPi, n, temp1, xSq, sum1, sum2;    sqrtPi = sqrt( PI );    x = ABS( x );    n = 1.0;    xSq = 2.0 * x * x;    sum1 = 0.0;    if ( x > 3.23 ) {	/* asymptotic expansion */	temp1 = exp( - x * x ) / ( sqrtPi * x );	sum2 = temp1;	while ( sum1 ISNOT sum2 ) {	    sum1 = sum2;	    temp1 = -1.0 * ( temp1 / xSq );	    sum2 += temp1;	    n += 2.0;	}	return( sum2 );    }    else {	/* series expansion for small x */	temp1 = ( 2.0 / sqrtPi ) * exp( - x * x ) * x;	sum2 = temp1;	while ( sum1 ISNOT sum2 ) {	    n += 2.0;	    sum1 = sum2;	    temp1 *= xSq / n;	    sum2 += temp1;	}        return( 1.0 - sum2 );    }}

⌨️ 快捷键说明

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