From 17127f9caa403a13b253159338c798706f3f77dd Mon Sep 17 00:00:00 2001 From: thevenyp Date: Tue, 6 May 2008 16:00:05 +0000 Subject: Add more tests and fix some bugs for trigonometric functions. git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@126 211d60ee-9f03-0410-a15a-8952a2c7a4e4 --- tests/tsin.c | 280 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 236 insertions(+), 44 deletions(-) (limited to 'tests/tsin.c') diff --git a/tests/tsin.c b/tests/tsin.c index 93a1365..2642787 100644 --- a/tests/tsin.c +++ b/tests/tsin.c @@ -55,19 +55,19 @@ special () /* sin(NaN +i*NaN) = NaN +i*NaN */ mpfr_set_nan (MPC_IM (z)); mpc_sin (s, z, MPC_RNDNN); - if (!mpfr_nan_p (MPC_RE (s)) && !mpfr_nan_p (MPC_IM (s))) + if (!mpfr_nan_p (MPC_RE (s)) || !mpfr_nan_p (MPC_IM (s))) test_failed (z, s, z); /* sin(NaN +i*infinity) = NaN +/-i*infinity */ mpfr_set_inf (MPC_IM (z), +1); mpc_sin (s, z, MPC_RNDNN); - if (!mpfr_nan_p (MPC_RE (s)) && !mpfr_inf_p (MPC_IM (s))) + if (!mpfr_nan_p (MPC_RE (s)) || !mpfr_inf_p (MPC_IM (s))) test_failed (z, s, z); /* sin(NaN -i*infinity) = NaN -/+i*infinity */ mpc_conj (z, z, MPC_RNDNN); mpc_sin (s, z, MPC_RNDNN); - if (!mpfr_nan_p (MPC_RE (s)) && !mpfr_inf_p (MPC_IM (s))) + if (!mpfr_nan_p (MPC_RE (s)) || !mpfr_inf_p (MPC_IM (s))) test_failed (z, s, z); /* sin(NaN +i*y) = NaN +i*NaN where 0<|y| I*sinh(x)\n" - "got "); - mpc_out_str (stderr, 10, 0, z, MPC_RNDNN); - fprintf (stderr, "\nexpected "); - mpfr_set_ui (MPC_RE(z), 0, GMP_RNDN); - mpfr_set (MPC_IM(z), g, GMP_RNDN); - mpc_out_str (stderr, 10, 0, z, MPC_RNDNN); - fprintf (stderr, "\n"); - exit (1); - } + printf ("mpc_sin(+0 - i) failed\n"); + exit (1); } + /* sin(-0 +i) = -0 +i*sinh(1) */ + mpc_neg (z, z, MPC_RNDNN); + mpfr_neg (sinh_y, sinh_y, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_IM (sin_z), sinh_y) != 0 + || !mpfr_zero_p (MPC_RE (sin_z)) || !mpfr_signbit (MPC_RE (sin_z))) + { + printf ("mpc_sin(-0 + i) failed\n"); + exit (1); + } + + /* sin(-0 -i) = -0 -i*sinh(1) */ + mpc_conj (z, z, MPC_RNDNN); + mpfr_neg (sinh_y, sinh_y, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_IM (sin_z), sinh_y) != 0 + || !mpfr_zero_p (MPC_RE (sin_z)) || !mpfr_signbit (MPC_RE (sin_z))) + { + printf ("mpc_sin(-0 - i) failed\n"); + exit (1); + } + + mpc_clear (sin_z); + mpc_clear (z); + mpfr_clear (sinh_y); + mpfr_clear (y); +} + +static void +check_53() +{ + mpc_t z; + mpc_t sin_z; + mpc_t s; + + mpc_init2 (z, 53); + mpc_init2 (sin_z, 53); + mpc_init2 (s, 53); + + /* sin(z) is almost 514 */ + mpfr_set_str (MPC_RE (z), "3243F6A8885A3p-49", 16, GMP_RNDN); + mpfr_set_str (MPC_IM (z), "-1BBDD1808C59A3p-50", 16, GMP_RNDN); + mpfr_set_str (MPC_RE (s), "514", 10, GMP_RNDN); + mpfr_set_str (MPC_IM (s), "-11B7CA26B51951p-97", 16, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpc_cmp (sin_z, s) != 0) + test_failed (z, sin_z, s); + + mpc_clear (s); + mpc_clear (sin_z); + mpc_clear (z); +} + +int +main() +{ special (); + pure_real_argument (); + pure_imaginary_argument (); + tgeneric (); - mpc_clear (x); - mpc_clear (z); - mpfr_clear (g); + check_53 (); return 0; } -- cgit v1.2.1