diff options
Diffstat (limited to 'tests/ttan.c')
-rw-r--r-- | tests/ttan.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/ttan.c b/tests/ttan.c index 9b7b4c435..b14683dd0 100644 --- a/tests/ttan.c +++ b/tests/ttan.c @@ -55,20 +55,56 @@ int main(int argc, char *argv[]) { mpfr_t x; + unsigned int i; + unsigned int prec[10] = {14, 15, 19, 22, 23, 24, 25, 40, 41, 52}; + unsigned int prec2[10] = {4, 5, 6, 19, 70, 95, 100, 106, 107, 108}; check53(0.0/0.0, 0.0/0.0, GMP_RNDN); check53(1.0/0.0, 0.0/0.0, GMP_RNDN); check53(-1.0/0.0, 0.0/0.0, GMP_RNDN); mpfr_init (x); + mpfr_set_prec (x, 2); mpfr_set_d (x, 0.5, GMP_RNDN); mpfr_tan (x, x, GMP_RNDD); - if (mpfr_get_d(x) != 0.5) + if (mpfr_get_d (x) != 0.5) { fprintf (stderr, "mpfr_tan(0.5, GMP_RNDD) failed\n"); + fprintf (stderr, "expected 0.5, got %f\n", mpfr_get_d (x)); exit (1); } + + /* check that tan(3*Pi/4) ~ -1 */ + for (i=0; i<10; i++) + { + mpfr_set_prec (x, prec[i]); + mpfr_const_pi (x, GMP_RNDN); + mpfr_mul_ui (x, x, 3, GMP_RNDN); + mpfr_div_ui (x, x, 4, GMP_RNDN); + mpfr_tan (x, x, GMP_RNDN); + if (mpfr_cmp_si (x, -1)) + { + fprintf (stderr, "tan(3*Pi/4) fails for prec=%u\n", prec[i]); + exit (1); + } + } + + /* check that tan(7*Pi/4) ~ -1 */ + for (i=0; i<10; i++) + { + mpfr_set_prec (x, prec2[i]); + mpfr_const_pi (x, GMP_RNDN); + mpfr_mul_ui (x, x, 7, GMP_RNDN); + mpfr_div_ui (x, x, 4, GMP_RNDN); + mpfr_tan (x, x, GMP_RNDN); + if (mpfr_cmp_si (x, -1)) + { + fprintf (stderr, "tan(3*Pi/4) fails for prec=%u\n", prec2[i]); + exit (1); + } + } + mpfr_clear (x); test_generic (2, 100, 100); |