⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exp.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
/*	@(#)exp.c	1.11	*//*LINTLIBRARY*//* *	exp returns the exponential function of its double-precision argument. *	Returns ERANGE error and value 0 if argument too small, *	   value HUGE if argument too large. *	Algorithm and coefficients from Cody and Waite (1980). *	Calls ldexp. */#include <math.h>#include <values.h>#include <errno.h>doubleexp(x)register double x;{	static double p[] = {		0.31555192765684646356e-4,	        0.75753180159422776666e-2,	        0.25000000000000000000e0,	}, q[] = {		0.75104028399870046114e-6,	        0.63121894374398503557e-3,	        0.56817302698551221787e-1,	        0.50000000000000000000e0,	};	register double y;	register int n;	struct exception exc;	exc.arg1 = x;	if (x < 0)		x = -x;	if (x < X_EPS) /* use first term of Taylor series expansion */		return (1.0 + exc.arg1);	exc.name = "exp";	if (exc.arg1 <= LN_MINDOUBLE) {		if (exc.arg1 == LN_MINDOUBLE) /* protect against roundoff */			return (MINDOUBLE); /* causing ldexp to underflow */		exc.type = UNDERFLOW;		exc.retval = 0.0;		if (!matherr(&exc))			errno = ERANGE;		return (exc.retval);	}	if (exc.arg1 >= LN_MAXDOUBLE) {		if (exc.arg1 == LN_MAXDOUBLE) /* protect against roundoff */			return (MAXDOUBLE); /* causing ldexp to overflow */		exc.type = OVERFLOW;		exc.retval = HUGE;		if (!matherr(&exc)) 			errno = ERANGE;		return (exc.retval);	}	n = (int)(x * M_LOG2E + 0.5);	y = (double)n;	_REDUCE(int, x, y, 0.693359375, -2.1219444005469058277e-4);	if (exc.arg1 < 0) {		x = -x;		n = -n;	}	y = x * x;	x *= _POLY2(y, p);	return (ldexp(0.5 + x/(_POLY3(y, q) - x), n + 1));}

⌨️ 快捷键说明

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