Beispiel #1
0
static long double complex
clog_for_large_values(long double complex z)
{
	long double x, y;
	long double ax, ay, t;

	x = creall(z);
	y = cimagl(z);
	ax = fabsl(x);
	ay = fabsl(y);
	if (ax < ay) {
		t = ax;
		ax = ay;
		ay = t;
	}

	if (ax > HALF_MAX)
		return (CMPLXL(logl(hypotl(x / m_e, y / m_e)) + 1,
		    atan2l(y, x)));

	if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN)
		return (CMPLXL(logl(hypotl(x, y)), atan2l(y, x)));

	return (CMPLXL(logl(ax * ax + ay * ay) / 2, atan2l(y, x)));
}
Beispiel #2
0
void
test_small(void)
{
	static const double tests[] = {
	     /* csqrt(a + bI) = x + yI */
	     /* a	b	x			y */
		 1.0,	M_PI_4,	M_SQRT2 * 0.5 * M_E,	M_SQRT2 * 0.5 * M_E,
		-1.0,	M_PI_4,	M_SQRT2 * 0.5 / M_E,	M_SQRT2 * 0.5 / M_E,
		 2.0,	M_PI_2,	0.0,			M_E * M_E,
		 M_LN2,	M_PI,	-2.0,			0.0,
	};
	double a, b;
	double x, y;
	int i;

	for (i = 0; i < N(tests); i += 4) {
		printf("# Run %d..\n", i);
		a = tests[i];
		b = tests[i + 1];
		x = tests[i + 2];
		y = tests[i + 3];
		test_tol(cexp, CMPLXL(a, b), CMPLXL(x, y), 3 * DBL_ULP());

		/* float doesn't have enough precision to pass these tests */
		if (x == 0 || y == 0)
			continue;
		test_tol(cexpf, CMPLXL(a, b), CMPLXL(x, y), 1 * FLT_ULP());
        }
}
Beispiel #3
0
void
test_small(void)
{
	/*
	 * z =  0.75 + i 0.25
	 *     acos(z) = Pi/4 - i ln(2)/2
	 *     asin(z) = Pi/4 + i ln(2)/2
	 *     atan(z) = atan(4)/2 + i ln(17/9)/4
	 */
	static const struct {
		complex long double z;
		complex long double acos_z;
		complex long double asin_z;
		complex long double atan_z;
	} tests[] = {
		{ CMPLXL(0.75L, 0.25L),
		  CMPLXL(pi / 4, -0.34657359027997265470861606072908828L),
		  CMPLXL(pi / 4, 0.34657359027997265470861606072908828L),
		  CMPLXL(0.66290883183401623252961960521423782L,
			 0.15899719167999917436476103600701878L) },
	};
	int i;

	for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
		testall_tol(cacos, tests[i].z, tests[i].acos_z, 2);
		testall_odd_tol(casin, tests[i].z, tests[i].asin_z, 2);
		testall_odd_tol(catan, tests[i].z, tests[i].atan_z, 2);
        }
}
Beispiel #4
0
long double complex
catanl(long double complex z)
{
	long double complex w;

	w = catanhl(CMPLXL(cimagl(z), creall(z)));
	return (CMPLXL(cimagl(w), creall(w)));
}
Beispiel #5
0
// FIXME
long double complex casinl(long double complex z) {
  long double complex w;
  long double x, y;

  x = creall(z);
  y = cimagl(z);
  w = CMPLXL(1.0 - (x - y) * (x + y), -2.0 * x * y);
  return clogl(CMPLXL(-y, x) + csqrtl(w));
}
Beispiel #6
0
/*
 * Test csqrt for some finite arguments where the answer is exact.
 * (We do not test if it produces correctly rounded answers when the
 * result is inexact, nor do we check whether it throws spurious
 * exceptions.)
 */
static void
test_finite()
{
	static const double tests[] = {
	     /* csqrt(a + bI) = x + yI */
	     /* a	b	x	y */
		0,	8,	2,	2,
		0,	-8,	2,	-2,
		4,	0,	2,	0,
		-4,	0,	0,	2,
		3,	4,	2,	1,
		3,	-4,	2,	-1,
		-3,	4,	1,	2,
		-3,	-4,	1,	-2,
		5,	12,	3,	2,
		7,	24,	4,	3,
		9,	40,	5,	4,
		11,	60,	6,	5,
		13,	84,	7,	6,
		33,	56,	7,	4,
		39,	80,	8,	5,
		65,	72,	9,	4,
		987,	9916,	74,	67,
		5289,	6640,	83,	40,
		460766389075.0, 16762287900.0, 678910, 12345
	};
	/*
	 * We also test some multiples of the above arguments. This
	 * array defines which multiples we use. Note that these have
	 * to be small enough to not cause overflow for float precision
	 * with all of the constants in the above table.
	 */
	static const double mults[] = {
		1,
		2,
		3,
		13,
		16,
		0x1.p30,
		0x1.p-30,
	};

	double a, b;
	double x, y;
	int i, j;

	for (i = 0; i < nitems(tests); i += 4) {
		for (j = 0; j < nitems(mults); j++) {
			a = tests[i] * mults[j] * mults[j];
			b = tests[i + 1] * mults[j] * mults[j];
			x = tests[i + 2] * mults[j];
			y = tests[i + 3] * mults[j];
			assert(t_csqrt(CMPLXL(a, b)) == CMPLXL(x, y));
		}
	}

}
Beispiel #7
0
/* Tests for 0 */
void
test_zero(void)
{

	/* cexp(0) = 1, no exceptions raised */
	testall(0.0, 1.0, ALL_STD_EXCEPT, 0, 1);
	testall(-0.0, 1.0, ALL_STD_EXCEPT, 0, 1);
	testall(CMPLXL(0.0, -0.0), CMPLXL(1.0, -0.0), ALL_STD_EXCEPT, 0, 1);
	testall(CMPLXL(-0.0, -0.0), CMPLXL(1.0, -0.0), ALL_STD_EXCEPT, 0, 1);
}
Beispiel #8
0
/*
 * Test the handling of infinities when the other argument is not NaN.
 */
static void
test_infinities()
{
	static const double vals[] = {
		0.0,
		-0.0,
		42.0,
		-42.0,
		INFINITY,
		-INFINITY,
	};

	int i;

	for (i = 0; i < nitems(vals); i++) {
		if (isfinite(vals[i])) {
			assert_equal(t_csqrt(CMPLXL(-INFINITY, vals[i])),
			    CMPLXL(0.0, copysignl(INFINITY, vals[i])));
			assert_equal(t_csqrt(CMPLXL(INFINITY, vals[i])),
			    CMPLXL(INFINITY, copysignl(0.0, vals[i])));
		}
		assert_equal(t_csqrt(CMPLXL(vals[i], INFINITY)),
		    CMPLXL(INFINITY, INFINITY));
		assert_equal(t_csqrt(CMPLXL(vals[i], -INFINITY)),
		    CMPLXL(INFINITY, -INFINITY));
	}
}
Beispiel #9
0
long double complex
cacosl(long double complex z)
{
	long double x, y, ax, ay, rx, ry, B, sqrt_A2mx2, new_x;
	int sx, sy;
	int B_is_usable;
	long double complex w;

	x = creall(z);
	y = cimagl(z);
	sx = signbit(x);
	sy = signbit(y);
	ax = fabsl(x);
	ay = fabsl(y);

	if (isnan(x) || isnan(y)) {
		if (isinf(x))
			return (CMPLXL(y + y, -INFINITY));
		if (isinf(y))
			return (CMPLXL(x + x, -y));
		if (x == 0)
			return (CMPLXL(pio2_hi + pio2_lo, y + y));
		return (CMPLXL(nan_mix(x, y), nan_mix(x, y)));
	}

	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
		w = clog_for_large_values(z);
		rx = fabsl(cimagl(w));
		ry = creall(w) + m_ln2;
		if (sy == 0)
			ry = -ry;
		return (CMPLXL(rx, ry));
	}

	if (x == 1 && y == 0)
		return (CMPLXL(0, -y));

	raise_inexact();

	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
		return (CMPLXL(pio2_hi - (x - pio2_lo), -y));

	do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x);
	if (B_is_usable) {
		if (sx == 0)
			rx = acosl(B);
		else
			rx = acosl(-B);
	} else {
		if (sx == 0)
			rx = atan2l(sqrt_A2mx2, new_x);
		else
			rx = atan2l(sqrt_A2mx2, -new_x);
	}
	if (sy == 0)
		ry = -ry;
	return (CMPLXL(rx, ry));
}
Beispiel #10
0
/* Tests for 0 */
void
test_zero(void)
{
	long double complex zero = CMPLXL(0.0, 0.0);

	testall_tol(cacosh, zero, CMPLXL(0.0, pi / 2), 1);
	testall_tol(cacosh, -zero, CMPLXL(0.0, -pi / 2), 1);
	testall_tol(cacos, zero, CMPLXL(pi / 2, -0.0), 1);
	testall_tol(cacos, -zero, CMPLXL(pi / 2, 0.0), 1);

	testall_odd(casinh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
	testall_odd(casin, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);

	testall_odd(catanh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
	testall_odd(catan, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
}
Beispiel #11
0
/*
 * Test the handling of +/- 0.
 */
static void
test_zeros()
{

	assert_equal(t_csqrt(CMPLXL(0.0, 0.0)), CMPLXL(0.0, 0.0));
	assert_equal(t_csqrt(CMPLXL(-0.0, 0.0)), CMPLXL(0.0, 0.0));
	assert_equal(t_csqrt(CMPLXL(0.0, -0.0)), CMPLXL(0.0, -0.0));
	assert_equal(t_csqrt(CMPLXL(-0.0, -0.0)), CMPLXL(0.0, -0.0));
}
Beispiel #12
0
long double complex
cacoshl(long double complex z)
{
	long double complex w;
	long double rx, ry;

	w = cacosl(z);
	rx = creall(w);
	ry = cimagl(w);
	if (isnan(rx) && isnan(ry))
		return (CMPLXL(ry, rx));
	if (isnan(rx))
		return (CMPLXL(fabsl(ry), rx));
	if (isnan(ry))
		return (CMPLXL(ry, ry));
	return (CMPLXL(fabsl(ry), copysignl(rx, cimagl(z))));
}
Beispiel #13
0
long double complex
cprojl(long double complex z)
{

	if (!isinf(creall(z)) && !isinf(cimagl(z)))
		return (z);
	else
		return (CMPLXL(INFINITY, copysignl(0.0, cimagl(z))));
}
Beispiel #14
0
/*
 * Test whether csqrt(a + bi) works for inputs that are large enough to
 * cause overflow in hypot(a, b) + a. In this case we are using
 *	csqrt(115 + 252*I) == 14 + 9*I
 * scaled up to near MAX_EXP.
 */
static void
test_overflow(int maxexp)
{
	long double a, b;
	long double complex result;

	a = ldexpl(115 * 0x1p-8, maxexp);
	b = ldexpl(252 * 0x1p-8, maxexp);
	result = t_csqrt(CMPLXL(a, b));
	assert(creall(result) == ldexpl(14 * 0x1p-4, maxexp / 2));
	assert(cimagl(result) == ldexpl(9 * 0x1p-4, maxexp / 2));
}
Beispiel #15
0
void
test_small(void)
{
	/*
	 * z =  0.75 + i 0.25
	 *     acos(z) = Pi/4 - i ln(2)/2
	 *     asin(z) = Pi/4 + i ln(2)/2
	 *     atan(z) = atan(4)/2 + i ln(17/9)/4
	 */
	complex long double z;
	complex long double acos_z;
	complex long double asin_z;
	complex long double atan_z;

	z = CMPLXL(0.75L, 0.25L);
	acos_z = CMPLXL(pi / 4, -0.34657359027997265470861606072908828L);
	asin_z = CMPLXL(pi / 4, 0.34657359027997265470861606072908828L);
	atan_z = CMPLXL(0.66290883183401623252961960521423782L,
			 0.15899719167999917436476103600701878L);

	testall_tol(cacos, z, acos_z, 2);
	testall_odd_tol(casin, z, asin_z, 2);
	testall_odd_tol(catan, z, atan_z, 2);
}
Beispiel #16
0
long double complex
catanhl(long double complex z)
{
	long double x, y, ax, ay, rx, ry;

	x = creall(z);
	y = cimagl(z);
	ax = fabsl(x);
	ay = fabsl(y);

	if (y == 0 && ax <= 1)
		return (CMPLXL(atanhl(x), y));

	if (x == 0)
		return (CMPLXL(x, atanl(y)));

	if (isnan(x) || isnan(y)) {
		if (isinf(x))
			return (CMPLXL(copysignl(0, x), y + y));
		if (isinf(y))
			return (CMPLXL(copysignl(0, x),
			    copysignl(pio2_hi + pio2_lo, y)));
		return (CMPLXL(nan_mix(x, y), nan_mix(x, y)));
	}

	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
		return (CMPLXL(real_part_reciprocal(x, y),
		    copysignl(pio2_hi + pio2_lo, y)));

	if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
		raise_inexact();
		return (z);
	}

	if (ax == 1 && ay < LDBL_EPSILON)
		rx = (m_ln2 - logl(ay)) / 2;
	else
		rx = log1pl(4 * ax / sum_squares(ax - 1, ay)) / 4;

	if (ax == 1)
		ry = atan2l(2, -ay) / 2;
	else if (ay < LDBL_EPSILON)
		ry = atan2l(2 * ay, (1 - ax) * (1 + ax)) / 2;
	else
		ry = atan2l(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2;

	return (CMPLXL(copysignl(rx, x), copysignl(ry, y)));
}
Beispiel #17
0
void
test_imaginaries(void)
{
	int i;

	for (i = 0; i < N(finites); i++) {
		printf("# Run %d..\n", i);
		test(cexp, CMPLXL(0.0, finites[i]),
		     CMPLXL(cos(finites[i]), sin(finites[i])),
		     ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
		test(cexp, CMPLXL(-0.0, finites[i]),
		     CMPLXL(cos(finites[i]), sin(finites[i])),
		     ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
		test(cexpf, CMPLXL(0.0, finites[i]),
		     CMPLXL(cosf(finites[i]), sinf(finites[i])),
		     ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
		test(cexpf, CMPLXL(-0.0, finites[i]),
		     CMPLXL(cosf(finites[i]), sinf(finites[i])),
		     ALL_STD_EXCEPT & ~FE_INEXACT, 0, 1);
	}
}
Beispiel #18
0
void
test_reals(void)
{
	int i;

	for (i = 0; i < N(finites); i++) {
		/* XXX could check exceptions more meticulously */
		printf("# Run %d..\n", i);
		test(cexp, CMPLXL(finites[i], 0.0),
		     CMPLXL(exp(finites[i]), 0.0),
		     FE_INVALID | FE_DIVBYZERO, 0, 1);
		test(cexp, CMPLXL(finites[i], -0.0),
		     CMPLXL(exp(finites[i]), -0.0),
		     FE_INVALID | FE_DIVBYZERO, 0, 1);
		test(cexpf, CMPLXL(finites[i], 0.0),
		     CMPLXL(expf(finites[i]), 0.0),
		     FE_INVALID | FE_DIVBYZERO, 0, 1);
		test(cexpf, CMPLXL(finites[i], -0.0),
		     CMPLXL(expf(finites[i]), -0.0),
		     FE_INVALID | FE_DIVBYZERO, 0, 1);
	}
}
Beispiel #19
0
long double complex
casinhl(long double complex z)
{
	long double x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y;
	int B_is_usable;
	long double complex w;

	x = creall(z);
	y = cimagl(z);
	ax = fabsl(x);
	ay = fabsl(y);

	if (isnan(x) || isnan(y)) {
		if (isinf(x))
			return (CMPLXL(x, y + y));
		if (isinf(y))
			return (CMPLXL(y, x + x));
		if (y == 0)
			return (CMPLXL(x + x, y));
		return (CMPLXL(nan_mix(x, y), nan_mix(x, y)));
	}

	if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
		if (signbit(x) == 0)
			w = clog_for_large_values(z) + m_ln2;
		else
			w = clog_for_large_values(-z) + m_ln2;
		return (CMPLXL(copysignl(creall(w), x),
		    copysignl(cimagl(w), y)));
	}

	if (x == 0 && y == 0)
		return (z);

	raise_inexact();

	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
		return (z);

	do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y);
	if (B_is_usable)
		ry = asinl(B);
	else
		ry = atan2l(new_y, sqrt_A2my2);
	return (CMPLXL(copysignl(rx, x), copysignl(ry, y)));
}
Beispiel #20
0
/*
 * Test the handling of NaNs.
 */
static void
test_nans()
{

	assert(creall(t_csqrt(CMPLXL(INFINITY, NAN))) == INFINITY);
	assert(isnan(cimagl(t_csqrt(CMPLXL(INFINITY, NAN)))));

	assert(isnan(creall(t_csqrt(CMPLXL(-INFINITY, NAN)))));
	assert(isinf(cimagl(t_csqrt(CMPLXL(-INFINITY, NAN)))));

	assert_equal(t_csqrt(CMPLXL(NAN, INFINITY)),
		     CMPLXL(INFINITY, INFINITY));
	assert_equal(t_csqrt(CMPLXL(NAN, -INFINITY)),
		     CMPLXL(INFINITY, -INFINITY));

	assert_equal(t_csqrt(CMPLXL(0.0, NAN)), CMPLXL(NAN, NAN));
	assert_equal(t_csqrt(CMPLXL(-0.0, NAN)), CMPLXL(NAN, NAN));
	assert_equal(t_csqrt(CMPLXL(42.0, NAN)), CMPLXL(NAN, NAN));
	assert_equal(t_csqrt(CMPLXL(-42.0, NAN)), CMPLXL(NAN, NAN));
	assert_equal(t_csqrt(CMPLXL(NAN, 0.0)), CMPLXL(NAN, NAN));
	assert_equal(t_csqrt(CMPLXL(NAN, -0.0)), CMPLXL(NAN, NAN));
	assert_equal(t_csqrt(CMPLXL(NAN, 42.0)), CMPLXL(NAN, NAN));
	assert_equal(t_csqrt(CMPLXL(NAN, -42.0)), CMPLXL(NAN, NAN));
	assert_equal(t_csqrt(CMPLXL(NAN, NAN)), CMPLXL(NAN, NAN));
}
Beispiel #21
0
long double complex
clogl(long double complex z)
{
	long double ax, ax2h, ax2l, axh, axl, ay, ay2h, ay2l, ayh, ayl;
	long double sh, sl, t;
	long double x, y, v;
	uint16_t hax, hay;
	int kx, ky;

	ENTERIT(long double complex);

	x = creall(z);
	y = cimagl(z);
	v = atan2l(y, x);

	ax = fabsl(x);
	ay = fabsl(y);
	if (ax < ay) {
		t = ax;
		ax = ay;
		ay = t;
	}

	GET_LDBL_EXPSIGN(hax, ax);
	kx = hax - 16383;
	GET_LDBL_EXPSIGN(hay, ay);
	ky = hay - 16383;

	/* Handle NaNs and Infs using the general formula. */
	if (kx == MAX_EXP || ky == MAX_EXP)
		RETURNI(CMPLXL(logl(hypotl(x, y)), v));

	/* Avoid spurious underflow, and reduce inaccuracies when ax is 1. */
	if (ax == 1) {
		if (ky < (MIN_EXP - 1) / 2)
			RETURNI(CMPLXL((ay / 2) * ay, v));
		RETURNI(CMPLXL(log1pl(ay * ay) / 2, v));
	}

	/* Avoid underflow when ax is not small.  Also handle zero args. */
	if (kx - ky > MANT_DIG || ay == 0)
		RETURNI(CMPLXL(logl(ax), v));

	/* Avoid overflow. */
	if (kx >= MAX_EXP - 1)
		RETURNI(CMPLXL(logl(hypotl(x * 0x1p-16382L, y * 0x1p-16382L)) +
		    (MAX_EXP - 2) * ln2l_lo + (MAX_EXP - 2) * ln2_hi, v));
	if (kx >= (MAX_EXP - 1) / 2)
		RETURNI(CMPLXL(logl(hypotl(x, y)), v));

	/* Reduce inaccuracies and avoid underflow when ax is denormal. */
	if (kx <= MIN_EXP - 2)
		RETURNI(CMPLXL(logl(hypotl(x * 0x1p16383L, y * 0x1p16383L)) +
		    (MIN_EXP - 2) * ln2l_lo + (MIN_EXP - 2) * ln2_hi, v));

	/* Avoid remaining underflows (when ax is small but not denormal). */
	if (ky < (MIN_EXP - 1) / 2 + MANT_DIG)
		RETURNI(CMPLXL(logl(hypotl(x, y)), v));

	/* Calculate ax*ax and ay*ay exactly using Dekker's algorithm. */
	t = (long double)(ax * (MULT_REDUX + 1));
	axh = (long double)(ax - t) + t;
	axl = ax - axh;
	ax2h = ax * ax;
	ax2l = axh * axh - ax2h + 2 * axh * axl + axl * axl;
	t = (long double)(ay * (MULT_REDUX + 1));
	ayh = (long double)(ay - t) + t;
	ayl = ay - ayh;
	ay2h = ay * ay;
	ay2l = ayh * ayh - ay2h + 2 * ayh * ayl + ayl * ayl;

	/*
	 * When log(|z|) is far from 1, accuracy in calculating the sum
	 * of the squares is not very important since log() reduces
	 * inaccuracies.  We depended on this to use the general
	 * formula when log(|z|) is very far from 1.  When log(|z|) is
	 * moderately far from 1, we go through the extra-precision
	 * calculations to reduce branches and gain a little accuracy.
	 *
	 * When |z| is near 1, we subtract 1 and use log1p() and don't
	 * leave it to log() to subtract 1, since we gain at least 1 bit
	 * of accuracy in this way.
	 *
	 * When |z| is very near 1, subtracting 1 can cancel almost
	 * 3*MANT_DIG bits.  We arrange that subtracting 1 is exact in
	 * doubled precision, and then do the rest of the calculation
	 * in sloppy doubled precision.  Although large cancellations
	 * often lose lots of accuracy, here the final result is exact
	 * in doubled precision if the large calculation occurs (because
	 * then it is exact in tripled precision and the cancellation
	 * removes enough bits to fit in doubled precision).  Thus the
	 * result is accurate in sloppy doubled precision, and the only
	 * significant loss of accuracy is when it is summed and passed
	 * to log1p().
	 */
	sh = ax2h;
	sl = ay2h;
	_2sumF(sh, sl);
	if (sh < 0.5 || sh >= 3)
		RETURNI(CMPLXL(logl(ay2l + ax2l + sl + sh) / 2, v));
	sh -= 1;
	_2sum(sh, sl);
	_2sum(ax2l, ay2l);
	/* Briggs-Kahan algorithm (except we discard the final low term): */
	_2sum(sh, ax2l);
	_2sum(sl, ay2l);
	t = ax2l + sl;
	_2sumF(sh, t);
	RETURNI(CMPLXL(log1pl(ay2l + t + sh) / 2, v));
}
Beispiel #22
0
long double complex catanhl(long double complex z) {
    z = catanl(CMPLXL(-cimagl(z), creall(z)));
    return CMPLXL(cimagl(z), -creall(z));
}
Beispiel #23
0
long double complex cprojl(long double complex z) {
    if (isinf(creall(z)) || isinf(cimagl(z)))
        return CMPLXL(INFINITY, copysignl(0.0, creall(z)));
    return z;
}
Beispiel #24
0
long double complex conjl(long double complex z)
{
	return CMPLXL(creall(z), -cimagl(z));
}
Beispiel #25
0
long double complex ccosl(long double complex z)
{
	return ccoshl(CMPLXL(-cimagl(z), creall(z)));
}
Beispiel #26
0
/*
 * Tests for NaN inputs.
 */
void
test_nan()
{
	long double complex nan_nan = CMPLXL(NAN, NAN);
	long double complex z;

	/*
	 * IN		CACOSH	    CACOS	CASINH	    CATANH
	 * NaN,NaN	NaN,NaN	    NaN,NaN	NaN,NaN	    NaN,NaN
	 * finite,NaN	NaN,NaN*    NaN,NaN*	NaN,NaN*    NaN,NaN*
	 * NaN,finite   NaN,NaN*    NaN,NaN*	NaN,NaN*    NaN,NaN*
	 * NaN,Inf	Inf,NaN     NaN,-Inf	?Inf,NaN    ?0,pi/2	
	 * +-Inf,NaN	Inf,NaN     NaN,?Inf	+-Inf,NaN   +-0,NaN
	 * +-0,NaN	NaN,NaN*    pi/2,NaN	NaN,NaN*    +-0,NaN
	 * NaN,0	NaN,NaN*    NaN,NaN*	NaN,0	    NaN,NaN*
	 *
	 *  * = raise invalid
	 */
	z = nan_nan;
	testall(cacosh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(cacos, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(casinh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(casin, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(catanh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
	testall(catan, z, nan_nan, ALL_STD_EXCEPT, 0, 0);

	z = CMPLXL(0.5, NAN);
	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casinh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catanh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catan, z, nan_nan, OPT_INVALID, 0, 0);

	z = CMPLXL(NAN, 0.5);
	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casinh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catanh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catan, z, nan_nan, OPT_INVALID, 0, 0);

	z = CMPLXL(NAN, INFINITY);
	testall(cacosh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
	testall(cacosh, -z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
	testall(cacos, z, CMPLXL(NAN, -INFINITY), ALL_STD_EXCEPT, 0, CS_IMAG);
	testall(casinh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, 0);
	testall(casin, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, CS_IMAG);
	testall_tol(catanh, z, CMPLXL(0.0, pi / 2), 1);
	testall(catan, z, CMPLXL(NAN, 0.0), ALL_STD_EXCEPT, 0, CS_IMAG);

	z = CMPLXL(INFINITY, NAN);
	testall_even(cacosh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0,
		     CS_REAL);
	testall_even(cacos, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
	testall_odd(casinh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0,
		    CS_REAL);
	testall_odd(casin, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
	testall_odd(catanh, z, CMPLXL(0.0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0.0), 1);

	z = CMPLXL(0.0, NAN);
        /* XXX We allow a spurious inexact exception here. */
	testall_even(cacosh, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
	testall_even_tol(cacos, z, CMPLXL(pi / 2, NAN), 1);
	testall_odd(casinh, z, nan_nan, OPT_INVALID, 0, 0);
	testall_odd(casin, z, CMPLXL(0.0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
	testall_odd(catanh, z, CMPLXL(0.0, NAN), OPT_INVALID, 0, CS_REAL);
	testall_odd(catan, z, nan_nan, OPT_INVALID, 0, 0);

	z = CMPLXL(NAN, 0.0);
	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
	testall(casinh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
	testall(catanh, z, nan_nan, OPT_INVALID, 0, CS_IMAG);
	testall(catan, z, CMPLXL(NAN, 0.0), ALL_STD_EXCEPT, 0, 0);
}
Beispiel #27
0
void
test_inf(void)
{
	long double complex z;

	/*
	 * IN		CACOSH	    CACOS	CASINH	    CATANH
	 * Inf,Inf	Inf,pi/4    pi/4,-Inf	Inf,pi/4    0,pi/2
	 * -Inf,Inf	Inf,3pi/4   3pi/4,-Inf	---	    ---
	 * Inf,finite	Inf,0	    0,-Inf	Inf,0	    0,pi/2
	 * -Inf,finite	Inf,pi      pi,-Inf	---	    ---
	 * finite,Inf	Inf,pi/2    pi/2,-Inf	Inf,pi/2    0,pi/2
	 */
	z = CMPLXL(INFINITY, INFINITY);
	testall_tol(cacosh, z, CMPLXL(INFINITY, pi / 4), 1);
	testall_tol(cacosh, -z, CMPLXL(INFINITY, -c3pi / 4), 1);
	testall_tol(cacos, z, CMPLXL(pi / 4, -INFINITY), 1);
	testall_tol(cacos, -z, CMPLXL(c3pi / 4, INFINITY), 1);
	testall_odd_tol(casinh, z, CMPLXL(INFINITY, pi / 4), 1);
	testall_odd_tol(casin, z, CMPLXL(pi / 4, INFINITY), 1);
	testall_odd_tol(catanh, z, CMPLXL(0, pi / 2), 1);
	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0), 1);

	z = CMPLXL(INFINITY, 0.5);
	/* XXX We allow a spurious inexact exception here. */
	testall(cacosh, z, CMPLXL(INFINITY, 0), OPT_INEXACT, 0, CS_BOTH);
	testall_tol(cacosh, -z, CMPLXL(INFINITY, -pi), 1);
	testall(cacos, z, CMPLXL(0, -INFINITY), OPT_INEXACT, 0, CS_BOTH);
	testall_tol(cacos, -z, CMPLXL(pi, INFINITY), 1);
	testall_odd(casinh, z, CMPLXL(INFINITY, 0), OPT_INEXACT, 0, CS_BOTH);
	testall_odd_tol(casin, z, CMPLXL(pi / 2, INFINITY), 1);
	testall_odd_tol(catanh, z, CMPLXL(0, pi / 2), 1);
	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0), 1);

	z = CMPLXL(0.5, INFINITY);
	testall_tol(cacosh, z, CMPLXL(INFINITY, pi / 2), 1);
	testall_tol(cacosh, -z, CMPLXL(INFINITY, -pi / 2), 1);
	testall_tol(cacos, z, CMPLXL(pi / 2, -INFINITY), 1);
	testall_tol(cacos, -z, CMPLXL(pi / 2, INFINITY), 1);
	testall_odd_tol(casinh, z, CMPLXL(INFINITY, pi / 2), 1);
	/* XXX We allow a spurious inexact exception here. */
	testall_odd(casin, z, CMPLXL(0.0, INFINITY), OPT_INEXACT, 0, CS_BOTH);
	testall_odd_tol(catanh, z, CMPLXL(0, pi / 2), 1);
	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0), 1);
}
Beispiel #28
0
/* Tests along the real and imaginary axes. */
void
test_axes(void)
{
	static const long double nums[] = {
		-2, -1, -0.5, 0.5, 1, 2
	};
	long double complex z;
	int i;

	for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) {
		/* Real axis */
		z = CMPLXL(nums[i], 0.0);
		if (fabs(nums[i]) <= 1) {
			testall_tol(cacosh, z, CMPLXL(0.0, acos(nums[i])), 1);
			testall_tol(cacos, z, CMPLXL(acosl(nums[i]), -0.0), 1);
			testall_tol(casin, z, CMPLXL(asinl(nums[i]), 0.0), 1);
			testall_tol(catanh, z, CMPLXL(atanh(nums[i]), 0.0), 1);
		} else {
			testall_tol(cacosh, z,
				    CMPLXL(acosh(fabs(nums[i])),
					   (nums[i] < 0) ? pi : 0), 1);
			testall_tol(cacos, z,
				    CMPLXL((nums[i] < 0) ? pi : 0,
					   -acosh(fabs(nums[i]))), 1);
			testall_tol(casin, z,
				    CMPLXL(copysign(pi / 2, nums[i]),
					   acosh(fabs(nums[i]))), 1);
			testall_tol(catanh, z,
				    CMPLXL(atanh(1 / nums[i]), pi / 2), 1);
		}
		testall_tol(casinh, z, CMPLXL(asinh(nums[i]), 0.0), 1);
		testall_tol(catan, z, CMPLXL(atan(nums[i]), 0), 1);

		/* TODO: Test the imaginary axis. */
	}
}
Beispiel #29
0
long double complex cacoshl(long double complex z) {
  z = cacosl(z);
  return CMPLXL(-cimagl(z), creall(z));
}
Beispiel #30
0
long double complex cacosl(long double complex z)
{
	z = casinl(z);
	return CMPLXL(PI_2 - creall(z), -cimagl(z));
}