Exemple #1
0
long double
log10l(long double x) {
	long double y, z;
	enum fp_direction_type rd;
	int n;

	if (!finitel(x))
		return (x + fabsl(x));	/* x is +-INF or NaN */
	else if (x > zero) {
		n = ilogbl(x);
		if (n < 0)
			n += 1;
		rd = __swapRD(fp_nearest);
		y = n;
		x = scalbnl(x, -n);
		z = y * log10_2lo + ivln10 * logl(x);
		z += y * log10_2hi;
		if (rd != fp_nearest)
			(void) __swapRD(rd);
		return (z);
	} else if (x == zero)	/* -INF */
		return (-one / zero);
	else			/* x <0 , return NaN */
		return (zero / zero);
}
Exemple #2
0
int
irintl(long double x) {
	enum fp_direction_type rd;

	rd = __swapRD(fp_nearest);
	(void) __swapRD(rd);	/* restore Rounding Direction */
	switch (rd) {
	case fp_nearest:
		if (x < 2147483647.5L && x >= -2147483648.5L)
			return ((int)rintl(x));
		break;
	case fp_tozero:
		if (x < 2147483648.0L && x > -2147483649.0L)
			return ((int)rintl(x));
		break;
	case fp_positive:
		if (x <= 2147483647.0L && x > -2147483649.0L)
			return ((int)rintl(x));
		break;
	case fp_negative:
		if (x < 2147483648.0L && x >= -2147483648.0L)
			return ((int)rintl(x));
		break;
	}
	return ((int)copysignl(1.0e100L, x));
}
Exemple #3
0
long double
hypotl(long double x, long double y) {
	int n0, n1, n2, n3;
	long double t1, t2, y1, y2, w;
	int *px = (int *) &x, *py = (int *) &y;
	int *pt1 = (int *) &t1, *py1 = (int *) &y1;
	enum fp_direction_type rd;
	int j, k, nx, ny, nz;

	if ((*(int *) &one) != 0) {	/* determine word ordering */
		n0 = 0;
		n1 = 1;
		n2 = 2;
		n3 = 3;
	} else {
		n0 = 3;
		n1 = 2;
		n2 = 1;
		n3 = 0;
	}

	px[n0] &= 0x7fffffff;	/* clear sign bit of x and y */
	py[n0] &= 0x7fffffff;
	k = 0x7fff0000;
	nx = px[n0] & k;	/* exponent of x and y */
	ny = py[n0] & k;
	if (ny > nx) {
		w = x;
		x = y;
		y = w;
		nz = ny;
		ny = nx;
		nx = nz;
	}			/* force x > y */
	if ((nx - ny) >= 0x00730000)
		return (x + y);	/* x/y >= 2**116 */
	if (nx < 0x5ff30000 && ny > 0x205b0000) {	/* medium x,y */
		/* save and set RD to Rounding to nearest */
		rd = __swapRD(fp_nearest);
		w = x - y;
		if (w > y) {
			pt1[n0] = px[n0];
			pt1[n1] = px[n1];
			pt1[n2] = pt1[n3] = 0;
			t2 = x - t1;
			x = sqrtl(t1 * t1 - (y * (-y) - t2 * (x + t1)));
		} else {
			x = x + x;
			py1[n0] = py[n0];
			py1[n1] = py[n1];
			py1[n2] = py1[n3] = 0;
			y2 = y - y1;
			pt1[n0] = px[n0];
			pt1[n1] = px[n1];
			pt1[n2] = pt1[n3] = 0;
			t2 = x - t1;
			x = sqrtl(t1 * y1 - (w * (-w) - (t2 * y1 + y2 * x)));
		}
		if (rd != fp_nearest)
			(void) __swapRD(rd);	/* restore rounding mode */
		return (x);
	} else {
		if (nx == k || ny == k) {	/* x or y is INF or NaN */
			if (isinfl(x))
				t2 = x;
			else if (isinfl(y))
				t2 = y;
			else
				t2 = x + y;	/* invalid if x or y is sNaN */
			return (t2);
		}
		if (ny == 0) {
			if (y == zero || x == zero)
				return (x + y);
			t1 = scalbnl(one, 16381);
			x *= t1;
			y *= t1;
			return (scalbnl(one, -16381) * hypotl(x, y));
		}
		j = nx - 0x3fff0000;
		px[n0] -= j;
		py[n0] -= j;
		pt1[n0] = nx;
		pt1[n1] = pt1[n2] = pt1[n3] = 0;
		return (t1 * hypotl(x, y));
	}
}