Beispiel #1
0
_C_STD_BEGIN

_CRTIMP2_PURE double __CLRCALL_PURE_OR_CDECL _Cosh(double x, double y)
	{	/* compute y * cosh(x), |y| <= 1 */
	switch (_Dtest(&x))
		{	/* test for special codes */
	case _NANCODE:
	case _INFCODE:
		return (x);
	case 0:
		return (y);
	default:	/* finite */
		if (y == 0.0)
			return (y);
		if (x < 0.0)
			x = -x;
		if (x < _Xbig)
			{	/* worth adding in exp(-x) */
			_Exp(&x, 1.0, -1);
			return (y * (x + 0.25 / x));
			}
		switch (_Exp(&x, y, -1))
			{	/* report over/underflow */
		case 0:
			_Feraise(_FE_UNDERFLOW);
			break;
		case _INFCODE:
			_Feraise(_FE_OVERFLOW);
			}
		return (x);
		}
	}
Beispiel #2
0
double (fmod)(double x, double y)
	{	/* compute fmod(x, y) */
	const short errx = _Dtest(&x);
	const short erry = _Dtest(&y);

	if (errx == NAN || erry == NAN || errx == INF || erry == 0)
		{	/* fmod undefined */
		errno = EDOM;
		return (errx == NAN ? x : erry == NAN ? y : _Nan._D);
		}
	else if (errx == 0 || erry == INF)
		return (x);	/* fmod(0,nonzero) or fmod(finite,INF) */
	else
		{	/* fmod(finite,finite) */
		double t;
		short n, neg, ychar;
	
		if (y < 0.0)
			y = -y;
		if (x < 0.0)
			x = -x, neg = 1;
		else
			neg = 0;
		for (t = y, _Dunscale(&ychar, &t), n = 0; ; )
			{	/* subtract |y| until |x|<|y| */
			short xchar;
	
			t = x;
			if (n < 0 || _Dunscale(&xchar, &t) == 0
				|| (n = xchar - ychar) < 0)
				return (neg ? -x : x);
			for (; 0 <= n; --n)
				{	/* try to subtract |y|*2^n */
				t = y, _Dscale(&t, n);
				if (t <= x)
					{
					x -= t;
					break;
					}
				}
			}
		}
	}
Beispiel #3
0
double (atan2)(double y, double x)
	{	/* compute atan(y/x) */
	double z;
	const short errx = _Dtest(&x);
	const short erry = _Dtest(&y);
	unsigned short hex;

	if (errx <= 0 && erry <= 0)
		{	/* x & y both finite or 0 */
		if (y < 0.0)
			y = -y, hex = 0x8;
		else
			hex = 0x0;
		if (x < 0.0)
			x = -x, hex ^= 0x6;
		if (x < y)
			z = x / y, hex ^= 0x2;
		else if (0.0 < x)
			z = y / x;
		else
			return (0.0);	/* atan(0, 0) */
		}
	else if (errx == NAN || erry == NAN)
		{	/* return one of the NaNs */
		errno = EDOM;
		return (errx == NAN ? x : y);
		}
	else
		{	/* at least one INF */
		z = errx == erry ? 1.0 : 0.0;
		hex = DSIGN(y) ? 0x8 : 0x0;
		if (DSIGN(x))
			hex ^= 0x6;
		if (erry == INF)
			hex ^= 0x2;
		}
	return (_Atan(z, hex));
	}
Beispiel #4
0
double (exp)(double x)
	{	/* compute exp(x) */
	switch (_Dtest(&x))
		{	/* test for special codes */
	case NAN:
		errno = EDOM;
		return (x);
	case INF:
		errno = ERANGE;
		return (DSIGN(x) ? 0.0 : _Inf._D);
	case 0:
		return (1.0);
	default:	/* finite */
		if (0 <= _Exp(&x, 0))
			errno = ERANGE;
		return (x);
		}
	}
Beispiel #5
0
double (tan)(double x)
	{	/* compute tan(x) */
	double g, gd;
	long quad;

	switch (_Dtest(&x))
		{
	case NAN:
		errno = EDOM;
		return (x);
	case INF:
		errno = EDOM;
		return (_Nan._D);
	case 0:
		return (0.0);
	default:	/* finite */
		if (x < -HUGE_RAD || HUGE_RAD < x)
			{	/* x huge, sauve qui peut */
			g = x / twopi;
			_Dint(&g, 0);
			x -= g * twopi;
			}
		g = x * twobypi;
		quad = (long)(0 < g ? g + 0.5 : g - 0.5);
		g = (double)quad;
		g = (x - g * c1) - g * c2;
		gd = 1.0;
		if (_Rteps._D < (g < 0.0 ? -g : g))
			{	/* g*g worth computing */
			double y = g * g;
	
			gd += (((q[0] * y + q[1]) * y + q[2]) * y + q[3]) * y;
			g += ((p[0] * y + p[1]) * y + p[2]) * y * g;
			}
		return ((unsigned int)quad & 0x1 ? -gd / g : g / gd);
		}
	}
Beispiel #6
0
double (atan)(double x)
	{	/* compute atan(x) */
	unsigned short hex;
	static const double piby2 = 1.57079632679489661923;

	switch (_Dtest(&x))
		{	/* test for special codes */
	case NAN:
		errno = EDOM;
		return (x);
	case INF:
		return (DSIGN(x) ? -piby2 : piby2);
	case 0:
		return (0.0);
	default:	/* finite */
		if (x < 0.0)
			x = -x, hex = 0x8;
		else
			hex = 0x0;
		if (1.0 < x)
			x = 1.0 / x, hex ^= 0x2;
		return (_Atan(x, hex));
		}
	}