diff options
author | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2008-05-06 16:00:05 +0000 |
---|---|---|
committer | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2008-05-06 16:00:05 +0000 |
commit | 17127f9caa403a13b253159338c798706f3f77dd (patch) | |
tree | e923b8377118dfb37824a02e63b69aeb6b7f71b0 /tests/tsin.c | |
parent | 036d29fca7d6b4b790c27644ab6ad891ac988d96 (diff) | |
download | mpc-17127f9caa403a13b253159338c798706f3f77dd.tar.gz |
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
Diffstat (limited to 'tests/tsin.c')
-rw-r--r-- | tests/tsin.c | 280 |
1 files changed, 236 insertions, 44 deletions
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|<infinity */ @@ -75,21 +75,22 @@ special () mpfr_set_nan (MPC_RE (c99)); mpfr_set_nan (MPC_IM (c99)); 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, c99); mpc_conj (z, z, MPC_RNDNN); 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, c99); /* sin(NaN +i*0) = NaN +/-i*0 */ + /* sin(NaN -i*0) = NaN -/+i*0 */ mpfr_set_ui (MPC_IM (z), 0, GMP_RNDN); mpc_sin (s, z, MPC_RNDNN); - if (!mpfr_nan_p (MPC_RE (s)) && !mpfr_zero_p (MPC_IM (s))) + if (!mpfr_nan_p (MPC_RE (s)) || !mpfr_zero_p (MPC_IM (s))) test_failed (z, s, z); mpc_conj (z, z, MPC_RNDNN); mpc_sin (s, z, MPC_RNDNN); - if (!mpfr_nan_p (MPC_RE (s)) && !mpfr_zero_p (MPC_IM (s))) + if (!mpfr_nan_p (MPC_RE (s)) || !mpfr_zero_p (MPC_IM (s))) test_failed (z, s, z); /* sin(+0 +i*NaN) = +0 +i*NaN */ @@ -109,19 +110,19 @@ special () /* sin(x +i*NaN) = NaN +i*NaN where x!=0 */ mpfr_set_inf (MPC_RE (z), +1); 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, c99); mpc_neg (z, z, MPC_RNDNN); 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, c99); mpfr_set_ui (MPC_RE (z), +1, MPC_RNDNN); 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, c99); mpc_neg (z, z, MPC_RNDNN); 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, c99); mpfr_set_inf (MPC_RE(z), -1); @@ -251,54 +252,245 @@ special () if (!mpfr_nan_p (MPC_RE (s)) || !mpfr_nan_p (MPC_IM (s))) test_failed (z, s, c99); + /* sin(+0 +0*i) = +0 +0*i */ + mpc_set_ui_ui (z, 0, 0, MPC_RNDNN); + mpc_sin (s, z, MPC_RNDNN); + if (mpc_cmp(s, z) != 0) + test_failed (z, s, z); + + /* sin(+0 -0*i) = +0 -0*i */ + mpc_conj (z, z, MPC_RNDNN); + mpc_sin (s, z, MPC_RNDNN); + if (mpc_cmp(s, z) != 0) + test_failed (z, s, z); + + /* sin(-0 +0*i) = -0 +0*i */ + mpc_neg (z, z, MPC_RNDNN); + mpc_sin (s, z, MPC_RNDNN); + if (mpc_cmp(s, z) != 0) + test_failed (z, s, z); + + /* sin(-0 -0*i) = -0 -0*i */ + mpc_conj (z, z, MPC_RNDNN); + mpc_sin (s, z, MPC_RNDNN); + if (mpc_cmp(s, z) != 0) + test_failed (z, s, z); + mpc_clear (c99); mpc_clear (s); mpc_clear (z); } -int -main() +static void +pure_real_argument () +{ + /* sin(x -i*0) = sin(x) -i*0*cos(x) */ + /* sin(x +i*0) = sin(x) +i*0*cos(x) */ + mpfr_t x; + mpfr_t sin_x; + mpc_t z; + mpc_t sin_z; + + mpfr_init (x); + mpfr_init (sin_x); + mpc_init (z); + mpc_init (sin_z); + + /* sin(1 +i*0) = sin(1) +i*0*cos(1) */ + mpc_set_ui_ui (z, 1, 0, MPC_RNDNN); + mpfr_set_ui (x, 1, GMP_RNDN); + mpfr_sin (sin_x, x, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_RE (sin_z), sin_x) != 0 + || !mpfr_zero_p (MPC_IM (sin_z)) || mpfr_signbit (MPC_IM (sin_z))) + { + printf ("mpc_sin(1 + i * 0) failed\n"); + exit (1); + } + + /* sin(-1 -i*0) = sin(-1) -i*0*cos(1) */ + mpc_neg (z, z, MPC_RNDNN); + mpfr_neg (sin_x, sin_x, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_RE (sin_z), sin_x) != 0 + || !mpfr_zero_p (MPC_IM (sin_z)) || !mpfr_signbit (MPC_IM (sin_z))) + { + printf ("mpc_sin(-1 - i * 0) failed\n"); + exit (1); + } + + /* sin(-1 +i*0) = sin(-1) +i*0*cos(1) */ + mpc_conj (z, z, MPC_RNDNN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_RE (sin_z), sin_x) != 0 + || !mpfr_zero_p (MPC_IM (sin_z)) || mpfr_signbit (MPC_IM (sin_z))) + { + printf ("mpc_sin(-1 + i * 0) failed\n"); + exit (1); + } + + /* sin(1 -i*0) = sin(1) -i*0*cos(1) */ + mpc_neg (z, z, MPC_RNDNN); + mpfr_neg (sin_x, sin_x, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_RE (sin_z), sin_x) != 0 + || !mpfr_zero_p (MPC_IM (sin_z)) || !mpfr_signbit (MPC_IM (sin_z))) + { + printf ("mpc_sin(1 - i * 0) failed\n"); + exit (1); + } + + /* sin(2 +i*0) = sin(2) +i*0*cos(2) */ + mpc_set_ui_ui (z, 2, 0, MPC_RNDNN); + mpfr_set_ui (x, 2, GMP_RNDN); + mpfr_sin (sin_x, x, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_RE (sin_z), sin_x) != 0 + || !mpfr_zero_p (MPC_IM (sin_z)) || !mpfr_signbit (MPC_IM (sin_z))) + { + printf ("mpc_sin(2 + i * 0) failed\n"); + exit (1); + } + + /* sin(-2 -i*0) = sin(-2) -i*0*cos(-2) */ + mpc_neg (z, z, MPC_RNDNN); + mpfr_neg (sin_x, sin_x, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_RE (sin_z), sin_x) != 0 + || !mpfr_zero_p (MPC_IM (sin_z)) || mpfr_signbit (MPC_IM (sin_z))) + { + printf ("mpc_sin(1 - i * 0) failed\n"); + exit (1); + } + + /* sin(-2 +i*0) = sin(-2) +i*0*cos(-2) */ + mpc_conj (z, z, MPC_RNDNN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_RE (sin_z), sin_x) != 0 + || !mpfr_zero_p (MPC_IM (sin_z)) || !mpfr_signbit (MPC_IM (sin_z))) + { + printf ("mpc_sin(-2 + i * 0) failed\n"); + exit (1); + } + + /* sin(2 -i*0) = sin(2) -i*0*cos(2) */ + mpc_neg (z, z, MPC_RNDNN); + mpfr_neg (sin_x, sin_x, GMP_RNDN); + mpc_sin (sin_z, z, MPC_RNDNN); + if (mpfr_cmp (MPC_RE (sin_z), sin_x) != 0 + || !mpfr_zero_p (MPC_IM (sin_z)) || mpfr_signbit (MPC_IM (sin_z))) + { + printf ("mpc_sin(2 - i * 0) failed\n"); + exit (1); + } + + mpc_clear (sin_z); + mpc_clear (z); + mpfr_clear (sin_x); + mpfr_clear (x); +} + +static void +pure_imaginary_argument () { - mpc_t x, z; - mpfr_t g; - mp_prec_t prec; + /* sin(-0 +i*y) = -0 +i*sinh(y) */ + /* sin(+0 +i*y) = +0 +i*sinh(y) */ + mpfr_t y; + mpfr_t sinh_y; + mpc_t z; + mpc_t sin_z; - mpc_init (x); + mpfr_init (y); + mpfr_init (sinh_y); mpc_init (z); - mpfr_init (g); + mpc_init (sin_z); + + /* sin(+0 +i) = +0 +i*sinh(1) */ + mpc_set_ui_ui (z, 0, 1, MPC_RNDNN); + mpfr_set_ui (y, 1, GMP_RNDN); + mpfr_sinh (sinh_y, 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); + } - for (prec = 2; prec <= 1000; prec+=2) + /* 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))) { - mpc_set_prec (x, prec); - mpc_set_prec (z, prec); - mpfr_set_prec (g, prec); - - /* check that sin(I*b) = I*sinh(b) */ - mpfr_set_ui (MPC_RE (x), 0, GMP_RNDN); - mpfr_random (MPC_IM (x)); - - mpc_sin (z, x, MPC_RNDNN); - mpfr_sinh (g, MPC_IM(x), GMP_RNDN); - if (mpfr_cmp_ui (MPC_RE(z), 0) || mpfr_cmp (g, MPC_IM(z))) - { - fprintf (stderr, "Error in mpc_sin: sin(I*x) <> 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; } |