diff options
42 files changed, 291 insertions, 186 deletions
diff --git a/tests/tacosh.c b/tests/tacosh.c index 7d518e7d7..a3b7aaf0f 100644 --- a/tests/tacosh.c +++ b/tests/tacosh.c @@ -32,7 +32,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 25); + test_generic (2, 100, 25); return 0; } diff --git a/tests/tadd.c b/tests/tadd.c index 357e8aec6..855b77dff 100644 --- a/tests/tadd.c +++ b/tests/tadd.c @@ -447,10 +447,10 @@ void check_case_1b (void) mpfr_init (b); mpfr_init (c); - for (prec_a = 1; prec_a <= 64; prec_a++) + for (prec_a = 2; prec_a <= 64; prec_a++) { mpfr_set_prec (a, prec_a); - for (prec_b = prec_a + 1; prec_b <= 64; prec_b++) + for (prec_b = prec_a + 2; prec_b <= 64; prec_b++) { dif = prec_b - prec_a; mpfr_set_prec (b, prec_b); @@ -549,7 +549,7 @@ check_inexact () mpfr_init (z); mpfr_init (u); - mpfr_set_prec (x, 1); + mpfr_set_prec (x, 2); mpfr_set_str_raw (x, "0.1E-4"); mpfr_set_prec (u, 33); mpfr_set_str_raw (u, "0.101110100101101100000000111100000E-1"); @@ -560,7 +560,7 @@ check_inexact () exit (1); } - mpfr_set_prec (x, 1); + mpfr_set_prec (x, 2); mpfr_set_str_raw (x, "0.1E-4"); mpfr_set_prec (u, 33); mpfr_set_str_raw (u, "0.101110100101101100000000111100000E-1"); @@ -571,15 +571,15 @@ check_inexact () exit (1); } - for (px=1; px<MAX_PREC; px++) + for (px=2; px<MAX_PREC; px++) { mpfr_set_prec (x, px); mpfr_random (x); - for (pu=1; pu<MAX_PREC; pu++) + for (pu=2; pu<MAX_PREC; pu++) { mpfr_set_prec (u, pu); mpfr_random (u); - for (py=1; py<MAX_PREC; py++) + for (py=2; py<MAX_PREC; py++) { mpfr_set_prec (y, py); pz = (mpfr_cmp_abs (x, u) >= 0) ? MPFR_EXP(x)-MPFR_EXP(u) diff --git a/tests/tasin.c b/tests/tasin.c index 3d48f2910..f2ed0e51e 100644 --- a/tests/tasin.c +++ b/tests/tasin.c @@ -36,7 +36,7 @@ main (void) mpfr_init (y); mpfr_init (z); - for (prec = 1; prec <= 100; prec++) + for (prec = 2; prec <= 100; prec++) { mpfr_set_prec (x, prec); mpfr_set_prec (z, prec); diff --git a/tests/tasinh.c b/tests/tasinh.c index 5dcca7776..8c74d12d6 100644 --- a/tests/tasinh.c +++ b/tests/tasinh.c @@ -41,7 +41,7 @@ main (int argc, char *argv[]) mpfr_set_str_raw (x, "0.111001101100000110011001010000101"); mpfr_asinh (y, x, GMP_RNDZ); - test_generic (1, 100, 25); + test_generic (2, 100, 25); mpfr_clear (x); mpfr_clear (y); diff --git a/tests/tatan.c b/tests/tatan.c index cbf5ccc25..e699cfe83 100644 --- a/tests/tatan.c +++ b/tests/tatan.c @@ -30,7 +30,7 @@ int mpfr_arctan_aux2 (mpfr_ptr, mpfr_srcptr, mp_rnd_t); int main (int argc, char *argv[]) { - unsigned int prec, err, yprec, n, p0 = 1, p1 = 100, N = 10; + unsigned int prec, err, yprec, n, p0 = 2, p1 = 100, N = 10; mp_rnd_t rnd; mpfr_t x, y, z, t; diff --git a/tests/tatanh.c b/tests/tatanh.c index c982d8403..9bd2b4a39 100644 --- a/tests/tatanh.c +++ b/tests/tatanh.c @@ -31,7 +31,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 25); + test_generic (2, 100, 25); return 0; } diff --git a/tests/tcos.c b/tests/tcos.c index 9b860ca4d..c3fac3cad 100644 --- a/tests/tcos.c +++ b/tests/tcos.c @@ -58,6 +58,11 @@ main (int argc, char *argv[]) mpfr_init (x); mpfr_init (y); + mpfr_set_prec (x, 53); + mpfr_set_prec (y, 2); + mpfr_set_d (x, 9.81333845856942e-1, GMP_RNDN); + mpfr_cos (y, x, GMP_RNDN); + mpfr_set_prec (x, 30); mpfr_set_prec (y, 30); mpfr_set_str_raw (x, "1.00001010001101110010100010101e-1"); @@ -112,7 +117,7 @@ main (int argc, char *argv[]) check53 (1.00591265847407274059, 0.53531755997839769456, GMP_RNDN); - test_generic (1, 100, 100); + test_generic (2, 100, 100); mpfr_clear (x); mpfr_clear (y); diff --git a/tests/tcosh.c b/tests/tcosh.c index 6792c1626..4ead3b465 100644 --- a/tests/tcosh.c +++ b/tests/tcosh.c @@ -31,7 +31,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 100); + test_generic (2, 100, 100); return 0; } diff --git a/tests/tdiv.c b/tests/tdiv.c index 94a5a4de8..a0b79dcd4 100644 --- a/tests/tdiv.c +++ b/tests/tdiv.c @@ -310,7 +310,7 @@ check_inexact () mpfr_set_prec (x, 33); mpfr_set_str_raw (x, "0.101111100011011101010011101100001E0"); - mpfr_set_prec (u, 1); + mpfr_set_prec (u, 2); mpfr_set_str_raw (u, "0.1E0"); mpfr_set_prec (y, 28); if ((inexact = mpfr_div (y, x, u, GMP_RNDN) >= 0)) @@ -333,15 +333,15 @@ check_inexact () exit (1); } - for (px=1; px<MAX_PREC; px++) + for (px=2; px<MAX_PREC; px++) { mpfr_set_prec (x, px); mpfr_random (x); - for (pu=1; pu<=MAX_PREC; pu++) + for (pu=2; pu<=MAX_PREC; pu++) { mpfr_set_prec (u, pu); do { mpfr_random (u); } while (mpfr_cmp_ui (u, 0) == 0); - for (py=1; py<=MAX_PREC; py++) + for (py=2; py<=MAX_PREC; py++) { mpfr_set_prec (y, py); mpfr_set_prec (z, py + pu); diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c index 7db5cb509..615aa5d05 100644 --- a/tests/tdiv_ui.c +++ b/tests/tdiv_ui.c @@ -125,12 +125,12 @@ check_inexact () mpfr_init (y); mpfr_init (z); - for (px=1; px<300; px++) + for (px=2; px<300; px++) { mpfr_set_prec (x, px); mpfr_random (x); do { u = lrand48 (); } while (u == 0); - for (py=1; py<300; py++) + for (py=2; py<300; py++) { mpfr_set_prec (y, py); mpfr_set_prec (z, py + mp_bits_per_limb); diff --git a/tests/teuler.c b/tests/teuler.c index d302e4cf0..ab9f74321 100644 --- a/tests/teuler.c +++ b/tests/teuler.c @@ -29,7 +29,7 @@ int main (int argc, char *argv[]) { mpfr_t gamma, y, z, t; - unsigned int err, prec, yprec, p0 = 1, p1 = 200; + unsigned int err, prec, yprec, p0 = 2, p1 = 200; mp_rnd_t rnd; prec = (argc < 2) ? 53 : atoi(argv[1]); diff --git a/tests/texp.c b/tests/texp.c index 5d5362db0..6e389b885 100644 --- a/tests/texp.c +++ b/tests/texp.c @@ -173,23 +173,36 @@ void compare_exp2_exp3 (int n) { mpfr_t x, y, z; int prec; mp_rnd_t rnd; - mpfr_init(x); mpfr_init(y); mpfr_init(z); - for (prec=20;prec<=n;prec++) { - mpfr_set_prec(x, prec); mpfr_set_prec(y, prec); mpfr_set_prec(z, prec); - mpfr_random(x); - rnd = rand() % 4; - mpfr_exp_2 (y, x, rnd); - mpfr_exp3 (z, x, rnd); - if (mpfr_cmp(y,z)) { - printf("mpfr_exp_2 and mpfr_exp3 disagree for rnd=%s and\nx=", - mpfr_print_rnd_mode(rnd)); - mpfr_print_binary(x); putchar('\n'); - printf("mpfr_exp_2 gives "); mpfr_print_binary(y); putchar('\n'); - printf("mpfr_exp3 gives "); mpfr_print_binary(z); putchar('\n'); - exit(1); - } + mpfr_init (x); + mpfr_init (y); + mpfr_init (z); + for (prec=20; prec<=n; prec++) + { + mpfr_set_prec (x, prec); + mpfr_set_prec (y, prec); + mpfr_set_prec (z, prec); + mpfr_random (x); + rnd = rand() % 4; + mpfr_exp_2 (y, x, rnd); + mpfr_exp3 (z, x, rnd); + if (mpfr_cmp (y,z)) + { + printf ("mpfr_exp_2 and mpfr_exp3 disagree for rnd=%s and\nx=", + mpfr_print_rnd_mode (rnd)); + mpfr_print_binary (x); + putchar ('\n'); + printf ("mpfr_exp_2 gives "); + mpfr_print_binary (y); + putchar ('\n'); + printf ("mpfr_exp3 gives "); + mpfr_print_binary (z); + putchar ('\n'); + exit (1); + } } - mpfr_clear(x); mpfr_clear(y); mpfr_clear(z); + mpfr_clear (x); + mpfr_clear (y); + mpfr_clear (z); } #define TEST_FUNCTION mpfr_exp @@ -202,7 +215,7 @@ main (int argc, char *argv[]) int i, N, s=0, e, maxe=0; double d, lo, hi; #endif - test_generic (1, 100, 100); + test_generic (2, 100, 100); if (argc == 4) { diff --git a/tests/texp2.c b/tests/texp2.c index db6c1f1a7..567ce4631 100644 --- a/tests/texp2.c +++ b/tests/texp2.c @@ -63,7 +63,7 @@ main (int argc, char *argv[]) exit (1); } - test_generic (1, 100, 100); + test_generic (2, 100, 100); mpfr_clear (x); mpfr_clear (y); diff --git a/tests/texpm1.c b/tests/texpm1.c index 14e53b773..b57ff9d0e 100644 --- a/tests/texpm1.c +++ b/tests/texpm1.c @@ -31,7 +31,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 100); + test_generic (2, 100, 100); return 0; } diff --git a/tests/tfactorial.c b/tests/tfactorial.c index b78bbca8c..4b81bb22a 100644 --- a/tests/tfactorial.c +++ b/tests/tfactorial.c @@ -50,7 +50,7 @@ main (int argc, char *argv[]) exit (1); } - for (prec = 1; prec <= 100; prec++) + for (prec = 2; prec <= 100; prec++) { mpfr_set_prec (x, prec); mpfr_set_prec (z, prec); diff --git a/tests/tfma.c b/tests/tfma.c index 05360c033..137d6c190 100644 --- a/tests/tfma.c +++ b/tests/tfma.c @@ -38,6 +38,15 @@ main (int argc, char *argv[]) mpfr_init (y); mpfr_init (z); + /* check special cases */ + mpfr_set_prec (x, 2); + mpfr_set_prec (y, 2); + mpfr_set_prec (z, 2); + mpfr_set_prec (s, 2); + mpfr_set_d (x, -0.75, GMP_RNDN); + mpfr_set_d (y, 0.5, GMP_RNDN); + mpfr_set_d (z, 0.375, GMP_RNDN); + mpfr_fma (s, x, y, z, GMP_RNDU); /* result is 0 */ MPFR_SET_NAN(x); mpfr_random(y); @@ -45,7 +54,7 @@ main (int argc, char *argv[]) mpfr_fma (s,x, y,z, GMP_RNDN); if(!MPFR_IS_NAN(s)) { - printf ("evaluation of function in x=NAN does not return NAN"); + fprintf (stderr, "evaluation of function in x=NAN does not return NAN"); exit (1); } @@ -219,7 +228,7 @@ main (int argc, char *argv[]) int inexact, compare; unsigned int n; - int p0=1; + int p0=2; int p1=200; int N=200; @@ -237,7 +246,6 @@ main (int argc, char *argv[]) for (n=0; n<N; n++) { - mpfr_random (x); mpfr_random (y); mpfr_random (z); diff --git a/tests/tget_str.c b/tests/tget_str.c index e27852350..1a79785c9 100644 --- a/tests/tget_str.c +++ b/tests/tget_str.c @@ -49,15 +49,16 @@ void check3 (double d, mp_rnd_t rnd, char *res) { mpfr_t x; char *str; mp_exp_t e; - mpfr_init2(x, 53); - mpfr_set_d(x, d, rnd); - str = mpfr_get_str(NULL, &e, 10, 5, x, rnd); - if (strcmp(str, res)) { - fprintf(stderr, "Error in mpfr_get_str for x=%1.20e\n", d); - fprintf(stderr, "got %s instead of %s\n", str, res); - } - mpfr_clear(x); - free(str); + mpfr_init2 (x, 53); + mpfr_set_d (x, d, rnd); + str = mpfr_get_str (NULL, &e, 10, 5, x, rnd); + if (strcmp(str, res)) + { + fprintf (stderr, "Error in mpfr_get_str for x=%1.20e\n", d); + fprintf (stderr, "got %s instead of %s\n", str, res); + } + mpfr_clear (x); + free (str); } void check_small () diff --git a/tests/thypot.c b/tests/thypot.c index 739e54143..3e78928a6 100644 --- a/tests/thypot.c +++ b/tests/thypot.c @@ -33,7 +33,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - unsigned int prec, err, yprec, n, p0 = 1, p1 = 100, N = 100; + unsigned int prec, err, yprec, n, p0 = 2, p1 = 100, N = 100; mp_rnd_t rnd; mpfr_t x1, x2, y, z, t; int inexact, compare, compare2; diff --git a/tests/tlog.c b/tests/tlog.c index bbdda9638..432b71011 100644 --- a/tests/tlog.c +++ b/tests/tlog.c @@ -345,7 +345,7 @@ main (int argc, char *argv[]) check2(6.09969788341579732815e+00,GMP_RNDD,1.80823924264386204363e+00); } - test_generic (1, 100, 40); + test_generic (2, 100, 40); return 0; } diff --git a/tests/tlog1p.c b/tests/tlog1p.c index 33f54c8f7..7e6fb5f84 100644 --- a/tests/tlog1p.c +++ b/tests/tlog1p.c @@ -31,7 +31,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 100); + test_generic (2, 100, 100); return 0; } diff --git a/tests/tlog2.c b/tests/tlog2.c index 3d9dc721a..b3b120d61 100644 --- a/tests/tlog2.c +++ b/tests/tlog2.c @@ -26,6 +26,49 @@ MA 02111-1307, USA. */ /* tlog2 [prec] [rnd] [0 = no print] */ +extern mp_prec_t __mpfr_const_log2_prec; +void check _PROTO ((mp_prec_t, mp_prec_t)); + +void +check (mp_prec_t p0, mp_prec_t p1) +{ + mpfr_t x, y, z; + mp_rnd_t rnd; + + mpfr_init (x); + mpfr_init (y); + mpfr_init2 (z, p1 + 10); + mpfr_const_log2 (z, GMP_RNDN); + __mpfr_const_log2_prec = 1; + + for (; p0<=p1; p0++) + { + mpfr_set_prec (x, p0); + mpfr_set_prec (y, p0); + for (rnd = 0; rnd < 4; rnd++) + { + mpfr_const_log2 (x, rnd); + mpfr_set (y, z, rnd); + if (mpfr_cmp (x, y) && mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN, + rnd, p0)) + { + fprintf (stderr, "mpfr_const_log2 fails for prec=%u, rnd=%s\n", + (unsigned int) p0, mpfr_print_rnd_mode (rnd)); + fprintf (stderr, "expected "); + mpfr_out_str (stderr, 2, 0, y, GMP_RNDN); + fprintf (stderr, "\ngot "); + mpfr_out_str (stderr, 2, 0, x, GMP_RNDN); + fprintf (stderr, "\n"); + exit (1); + } + } + } + + mpfr_clear (x); + mpfr_clear (y); + mpfr_clear (z); +} + int main (int argc, char *argv[]) { @@ -35,14 +78,38 @@ main (int argc, char *argv[]) p = (argc>1) ? atoi(argv[1]) : 53; rnd = (argc>2) ? atoi(argv[2]) : GMP_RNDZ; - mpfr_init2(x, p); - mpfr_const_log2(x, rnd); - if (argc>=2) { - printf("log(2)="); mpfr_out_str(stdout, 10, 0, x, rnd); putchar('\n'); - } - else if (mpfr_get_d(x) != 6.9314718055994530941e-1) { - fprintf(stderr, "mpfr_const_log2 failed for prec=53\n"); exit(1); - } + + mpfr_init (x); + + check (2, 1000); + + /* check precision of 2 bits */ + mpfr_set_prec (x, 2); + mpfr_const_log2 (x, GMP_RNDN); + if (mpfr_get_d (x) != 0.75) + { + fprintf (stderr, "mpfr_const_log2 failed for prec=2, rnd=GMP_RNDN\n"); + fprintf (stderr, "expected 0.75, got %f\n", mpfr_get_d (x)); + exit (1); + } + + if (argc>=2) + { + mpfr_set_prec (x, p); + mpfr_const_log2 (x, rnd); + printf ("log(2)="); + mpfr_out_str (stdout, 10, 0, x, rnd); + putchar('\n'); + } + + mpfr_set_prec (x, 53); + mpfr_const_log2 (x, rnd); + if (mpfr_get_d(x) != 6.9314718055994530941e-1) + { + fprintf (stderr, "mpfr_const_log2 failed for prec=53\n"); + exit (1); + } + mpfr_clear(x); return 0; diff --git a/tests/tlog_base_10.c b/tests/tlog_base_10.c index e18c4116d..9e5fd769d 100644 --- a/tests/tlog_base_10.c +++ b/tests/tlog_base_10.c @@ -31,7 +31,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 100); + test_generic (2, 100, 100); return 0; } diff --git a/tests/tlog_base_2.c b/tests/tlog_base_2.c index 80c55fcff..fa778c652 100644 --- a/tests/tlog_base_2.c +++ b/tests/tlog_base_2.c @@ -31,7 +31,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 30); + test_generic (2, 100, 30); return 0; } diff --git a/tests/tmul.c b/tests/tmul.c index c4e820867..70ea757d7 100644 --- a/tests/tmul.c +++ b/tests/tmul.c @@ -41,9 +41,9 @@ void check (double x, double y, mp_rnd_t rnd_mode, unsigned int px, { double z1, z2; mpfr_t xx, yy, zz; - mpfr_init2(xx, px); - mpfr_init2(yy, py); - mpfr_init2(zz, pz); + mpfr_init2 (xx, px); + mpfr_init2 (yy, py); + mpfr_init2 (zz, pz); mpfr_set_d(xx, x, rnd_mode); mpfr_set_d(yy, y, rnd_mode); mpfr_mul(zz, xx, yy, rnd_mode); @@ -67,13 +67,13 @@ void check53 (double x, double y, mp_rnd_t rnd_mode, double z1) { double z2; mpfr_t xx, yy, zz; - mpfr_init2(xx, 53); - mpfr_init2(yy, 53); - mpfr_init2(zz, 53); - mpfr_set_d(xx, x, rnd_mode); - mpfr_set_d(yy, y, rnd_mode); - mpfr_mul(zz, xx, yy, rnd_mode); - z2 = mpfr_get_d(zz); + mpfr_init2 (xx, 53); + mpfr_init2 (yy, 53); + mpfr_init2 (zz, 53); + mpfr_set_d (xx, x, rnd_mode); + mpfr_set_d (yy, y, rnd_mode); + mpfr_mul (zz, xx, yy, rnd_mode); + z2 = mpfr_get_d (zz); if (z1!=z2 && (!isnan(z1) || !isnan(z2))) { printf("mpfr_mul failed for x=%1.20e y=%1.20e with rnd_mode=%s\n", x, y, mpfr_print_rnd_mode(rnd_mode)); @@ -89,13 +89,13 @@ void check24 (float x, float y, mp_rnd_t rnd_mode, float z1) { float z2; mpfr_t xx, yy, zz; - mpfr_init2(xx, 24); - mpfr_init2(yy, 24); - mpfr_init2(zz, 24); - mpfr_set_d(xx, x, rnd_mode); - mpfr_set_d(yy, y, rnd_mode); - mpfr_mul(zz, xx, yy, rnd_mode); - z2 = (float) mpfr_get_d(zz); + mpfr_init2 (xx, 24); + mpfr_init2 (yy, 24); + mpfr_init2 (zz, 24); + mpfr_set_d (xx, x, rnd_mode); + mpfr_set_d (yy, y, rnd_mode); + mpfr_mul (zz, xx, yy, rnd_mode); + z2 = (float) mpfr_get_d (zz); if (z1!=z2) { printf("mpfr_mul failed for x=%1.0f y=%1.0f with prec=24 and rnd_mode=%s\n", x, y, mpfr_print_rnd_mode(rnd_mode)); printf("libm.a gives %1.0f, mpfr_mul gives %1.0f\n", z1, z2); @@ -154,7 +154,8 @@ void check_sign () { mpfr_t a, b; - mpfr_init2(a, 53); mpfr_init2(b, 53); + mpfr_init2 (a, 53); + mpfr_init2 (b, 53); mpfr_set_d(a, -1.0, GMP_RNDN); mpfr_set_d(b, 2.0, GMP_RNDN); mpfr_mul(a, b, b, GMP_RNDN); @@ -258,7 +259,7 @@ main (int argc, char *argv[]) check53(0.31869277231188065, 0.88642843322303122, GMP_RNDZ, 2.8249833483992453642e-1); check(8.47622108205396074254e-01, 3.24039313247872939883e-01, GMP_RNDU, - 28, 45, 1, 0.5); + 28, 45, 2, 0.375); check(2.63978122803639081440e-01, 6.8378615379333496093e-1, GMP_RNDN, 34, 23, 31, 0.180504585267044603); check(1.0, 0.11835170935876249132, GMP_RNDU, 6, 41, 36, 0.1183517093595583); @@ -270,7 +271,7 @@ main (int argc, char *argv[]) check(3.90798504668055102229e-14, 9.85394674650308388664e-04, GMP_RNDN, 46, 22, 12, 0.385027296503914762e-16); check(4.58687081072827851358e-01, 2.20543551472118792844e-01, GMP_RNDN, - 49, 3, 1, 0.125); + 49, 3, 2, 0.09375); #ifdef TEST srand48(getpid()); prec = (argc<2) ? 53 : atoi(argv[1]); diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c index 0512513f5..e307d5a5b 100644 --- a/tests/tmul_ui.c +++ b/tests/tmul_ui.c @@ -47,7 +47,8 @@ check_inexact (mp_prec_t p) fprintf (stderr, "Error: result should be exact\n"); exit (1); } - for (q=1; q<=p; q++) + + for (q=2; q<=p; q++) for (rnd=0; rnd<4; rnd++) { mpfr_set_prec (y, q); @@ -63,11 +64,11 @@ check_inexact (mp_prec_t p) } } - mpfr_set_prec (x, 1); - mpfr_set_ui (x, 2, GMP_RNDN); - if (mpfr_mul_ui (x, x, 3, GMP_RNDZ) == 0) + mpfr_set_prec (x, 2); + mpfr_set_ui (x, 1, GMP_RNDN); + if (mpfr_mul_ui (x, x, 5, GMP_RNDZ) == 0) { - fprintf (stderr, "mul_ui(2, 3) cannot be exact with prec=1\n"); + fprintf (stderr, "mul_ui(1, 5) cannot be exact with prec=2\n"); exit (1); } @@ -83,7 +84,7 @@ main (int argc, char *argv[]) unsigned int xprec, yprec, i; mp_prec_t p; - for (p=1; p<100; p++) + for (p=2; p<100; p++) for (i=1; i<50; i++) check_inexact (p); diff --git a/tests/tout_str.c b/tests/tout_str.c index f0453e07f..37d7acaf8 100644 --- a/tests/tout_str.c +++ b/tests/tout_str.c @@ -54,47 +54,51 @@ void check_large () mpfr_init(x); - mpfr_set_prec(x, 7); - mpfr_set_str_raw(x, "0.1010101E10"); - s = mpfr_get_str(NULL, &e, 10, 2, x, GMP_RNDU); - free(s); + mpfr_set_prec (x, 7); + mpfr_set_str_raw (x, "0.1010101E10"); + s = mpfr_get_str (NULL, &e, 10, 2, x, GMP_RNDU); + free (s); /* checks rounding of negative numbers */ - mpfr_set_d(x, -1.5, GMP_RNDN); - s = mpfr_get_str(NULL, &e, 10, 1, x, GMP_RNDD); - if (strcmp(s, "-2")) { - fprintf(stderr, "Error in mpfr_get_str for x=-1.5 and rnd=GMP_RNDD\n"); - free(s); mpfr_clear(x); - exit(1); + mpfr_set_prec (x, 7); + mpfr_set_d (x, -11.5, GMP_RNDN); + s = mpfr_get_str (NULL, &e, 10, 2, x, GMP_RNDD); + if (strcmp (s, "-12")) + { + fprintf (stderr, "Error in mpfr_get_str for x=-11.5 and rnd=GMP_RNDD\n"); + free (s); + mpfr_clear (x); + exit (1); } - free(s); - - s = mpfr_get_str(NULL, &e, 10, 1, x, GMP_RNDU); - if (strcmp(s, "-1")) { - fprintf(stderr, "Error in mpfr_get_str for x=-1.5 and rnd=GMP_RNDU\n"); - free(s); - mpfr_clear(x); - exit(1); - } - - free(s); + free (s); + + s = mpfr_get_str (NULL, &e, 10, 2, x, GMP_RNDU); + if (strcmp (s, "-11")) + { + fprintf (stderr, "Error in mpfr_get_str for x=-11.5 and rnd=GMP_RNDU\n"); + free (s); + mpfr_clear (x); + exit (1); + } + free (s); /* bug found by Jean-Pierre Merlet, produced error in mpfr_get_str */ - mpfr_set_prec(x, 128); - mpfr_set_str_raw(x, "0.10111001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011010E3"); - s = mpfr_get_str(NULL, &e, 10, 0, x, GMP_RNDU); - free(s); + mpfr_set_prec (x, 128); + mpfr_set_str_raw (x, "0.10111001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011010E3"); + s = mpfr_get_str (NULL, &e, 10, 0, x, GMP_RNDU); + free (s); - mpfr_set_prec(x, 381); - mpfr_set_str_raw(x, "0.111111111111111111111111111111111111111111111111111111111111111111101110110000100110011101101101001010111000101111000100100011110101010110101110100000010100001000110100000100011111001000010010000010001010111001011110000001110010111101100001111000101101100000010110000101100100000101010110010110001010100111001111100011100101100000100100111001100010010011110011011010110000001000010"); + mpfr_set_prec (x, 381); + mpfr_set_str_raw (x, "0.111111111111111111111111111111111111111111111111111111111111111111101110110000100110011101101101001010111000101111000100100011110101010110101110100000010100001000110100000100011111001000010010000010001010111001011110000001110010111101100001111000101101100000010110000101100100000101010110010110001010100111001111100011100101100000100100111001100010010011110011011010110000001000010"); s = mpfr_get_str (NULL, &e, 10, 0, x, GMP_RNDD); - if (e != 0) { - fprintf(stderr, "Error in mpfr_get_str for x=0.999999..., exponent is %d instead of 0\n", (int) e); - exit(1); - } - free(s); - - mpfr_clear(x); + if (e != 0) + { + fprintf (stderr, "Error in mpfr_get_str for x=0.999999..., exponent is %d instead of 0\n", (int) e); + exit (1); + } + free (s); + + mpfr_clear (x); } int @@ -126,12 +130,16 @@ main (int argc, char *argv[]) /* random tests */ srand(getpid()); - for (i=0;i<N;i++) { - do { d = drand(); } while (isnan(d)); - r = rand()%4; - p = 2 + rand()%35; - check(d, r, p); - } + for (i=0;i<N;i++) + { + do + { + d = drand(); + } while (isnan(d)); + r = rand() % 4; + p = 2 + rand() % 35; + check (d, r, p); + } return 0; } diff --git a/tests/tpow.c b/tests/tpow.c index dc26b4391..7381a98a5 100644 --- a/tests/tpow.c +++ b/tests/tpow.c @@ -77,7 +77,7 @@ check_inexact (mp_prec_t p) mpfr_init (t); mpfr_random (x); u = lrand48() % 2; - for (q=1; q<=p; q++) + for (q=2; q<=p; q++) for (rnd=0; rnd<4; rnd++) { mpfr_set_prec (y, q); @@ -124,7 +124,7 @@ main (void) check_pow_ui (); - for (p=1; p<100; p++) + for (p=2; p<100; p++) check_inexact (p); return 0; diff --git a/tests/tpow3.c b/tests/tpow3.c index 58fc2f80f..6c2a3c691 100644 --- a/tests/tpow3.c +++ b/tests/tpow3.c @@ -337,7 +337,7 @@ main (int argc, char *argv[]) int inexact, compare, compare2; unsigned int n, err; - int p0=1; + int p0=2; int p1=100; int N=100; diff --git a/tests/tset.c b/tests/tset.c index cca6611e6..9d93f1d7c 100644 --- a/tests/tset.c +++ b/tests/tset.c @@ -41,22 +41,22 @@ main () mpfr_set_prec (y, 11); mpfr_set_str_raw (y, "0.11111111100E-8"); - mpfr_set_prec (x, 1); + mpfr_set_prec (x, 2); mpfr_set (x, y, GMP_RNDN); mpfr_set_str_raw (y, "1.0E-8"); if (mpfr_cmp (x, y)) { - fprintf (stderr, "Error for y=0.11111111100E-8, prec=1, rnd=GMP_RNDN\n"); + fprintf (stderr, "Error for y=0.11111111100E-8, prec=2, rnd=GMP_RNDN\n"); exit (1); } - for (p=1; p<500; p++) + for (p=2; p<500; p++) { mpfr_set_prec (x, p); mpfr_random (x); if (rand () % 2) mpfr_neg (x, x, GMP_RNDN); - for (q=1; q<2*p; q++) + for (q=2; q<2*p; q++) { mpfr_set_prec (y, q); for (rnd=0; rnd<4; rnd++) diff --git a/tests/tset_f.c b/tests/tset_f.c index fe5eeb925..08570c964 100644 --- a/tests/tset_f.c +++ b/tests/tset_f.c @@ -70,15 +70,15 @@ main (void) for (k = 1; k <= 100000; k++) { - pr = 1 + (rand()&255); - mpf_set_prec(z, pr); - mpf_random2(z, z->_mp_prec, 0); - mpfr_init2(x, pr); - mpfr_set_f(x, z, 0); - mpfr_clear(x); + pr = 2 + (rand()&255); + mpf_set_prec (z, pr); + mpf_random2 (z, z->_mp_prec, 0); + mpfr_init2 (x, pr); + mpfr_set_f (x, z, 0); + mpfr_clear (x); } - mpf_clear(y); - mpf_clear(z); + mpf_clear (y); + mpf_clear (z); return 0; } diff --git a/tests/tset_si.c b/tests/tset_si.c index a5da95439..e84b633b3 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -74,14 +74,14 @@ main (int argc, char *argv[]) } } - mpfr_set_prec (x, 1); + mpfr_set_prec (x, 2); if (mpfr_set_si (x, 5, GMP_RNDZ) >= 0) { fprintf (stderr, "Wrong inexact flag for x=5, rnd=GMP_RNDZ\n"); exit (1); } - mpfr_set_prec (x, 1); + mpfr_set_prec (x, 2); if (mpfr_set_si (x, -5, GMP_RNDZ) <= 0) { fprintf (stderr, "Wrong inexact flag for x=-5, rnd=GMP_RNDZ\n"); @@ -106,18 +106,18 @@ main (int argc, char *argv[]) exit(1); } - mpfr_set_prec(x, 1); + mpfr_set_prec(x, 2); inex = mpfr_set_si(x, 33096, GMP_RNDU); - if (mpfr_get_d(x) != 65536.0 || inex <= 0) + if (mpfr_get_d(x) != 49152.0 || inex <= 0) { - fprintf(stderr, "Error in mpfr_set_si, expected 65536, got %lu, inex %d\n", + fprintf(stderr, "Error in mpfr_set_si, expected 49152, got %lu, inex %d\n", (unsigned long) mpfr_get_d(x), inex); exit(1); } inex = mpfr_set_ui(x, 33096, GMP_RNDU); - if (mpfr_get_d(x) != 65536.0) + if (mpfr_get_d(x) != 49152.0) { - fprintf(stderr, "Error in mpfr_set_ui, expected 65536, got %lu, inex %d\n", + fprintf(stderr, "Error in mpfr_set_ui, expected 49152, got %lu, inex %d\n", (unsigned long) mpfr_get_d(x), inex); exit(1); } diff --git a/tests/tsin.c b/tests/tsin.c index 39a1053dc..e2c7eb897 100644 --- a/tests/tsin.c +++ b/tests/tsin.c @@ -69,17 +69,17 @@ main (int argc, char *argv[]) check53 (1.00591265847407274059, 8.446508805292128885e-1, GMP_RNDN); - mpfr_init2 (x, 1); + mpfr_init2 (x, 2); mpfr_set_d (x, 0.5, GMP_RNDN); mpfr_sin (x, x, GMP_RNDD); - if (mpfr_get_d(x) != 0.25) + if (mpfr_get_d(x) != 0.375) { - fprintf (stderr, "mpfr_sin(0.5, GMP_RNDD) failed\n"); + fprintf (stderr, "mpfr_sin(0.5, GMP_RNDD) failed with precision=2\n"); exit (1); } mpfr_clear (x); - test_generic (1, 100, 80); + test_generic (2, 100, 80); return 0; } diff --git a/tests/tsinh.c b/tests/tsinh.c index 2fdd078d5..cdd9c585c 100644 --- a/tests/tsinh.c +++ b/tests/tsinh.c @@ -31,7 +31,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 100); + test_generic (2, 100, 100); return 0; } diff --git a/tests/tsqrt.c b/tests/tsqrt.c index 9be24323c..9a6a9f6ec 100644 --- a/tests/tsqrt.c +++ b/tests/tsqrt.c @@ -183,16 +183,16 @@ void special () exit (1); } - mpfr_set_prec (x, 1); - for (p=1; p<1000; p++) + mpfr_set_prec (x, 2); + for (p=2; p<1000; p++) { mpfr_set_prec (z, p); mpfr_set_ui (z, 1, GMP_RNDN); mpfr_add_one_ulp (z, GMP_RNDN); mpfr_sqrt (x, z, GMP_RNDU); - if (mpfr_cmp_ui (x, 2)) + if (mpfr_get_d (x) != 1.5) { - fprintf (stderr, "Error: sqrt(1+ulp(1), up) should give 2 (prec=%u)\n", (unsigned) p); + fprintf (stderr, "Error: sqrt(1+ulp(1), up) should give 1.5 (prec=%u)\n", (unsigned) p); printf ("got "); mpfr_print_binary (x); putchar ('\n'); exit (1); } @@ -207,8 +207,8 @@ void special () exit (1); } - mpfr_set_prec (x, 1); - mpfr_set_prec (z, 1); + mpfr_set_prec (x, 2); + mpfr_set_prec (z, 2); /* checks the sign is correctly set */ mpfr_set_d (x, 1.0, GMP_RNDN); @@ -223,7 +223,7 @@ void special () mpfr_set_prec (x, 192); mpfr_set_prec (z, 160); mpfr_set_str_raw (z, "0.1011010100000100100100100110011001011100100100000011000111011001011101101101110000110100001000100001100001011000E1"); - mpfr_set_prec(x, 160); + mpfr_set_prec (x, 160); mpfr_sqrt(x, z, GMP_RNDN); mpfr_sqrt(z, x, GMP_RNDN); @@ -291,7 +291,7 @@ main (void) check(a, rand() % 4); } #endif - for (p=1; p<200; p++) + for (p=2; p<200; p++) for (k=0; k<200; k++) check_inexact (p); special (); diff --git a/tests/tsub.c b/tests/tsub.c index cc5d59ad4..8a48024ae 100644 --- a/tests/tsub.c +++ b/tests/tsub.c @@ -232,7 +232,7 @@ check_diverse () exit (1); } - mpfr_set_prec (x, 1); + mpfr_set_prec (x, 2); mpfr_set_prec (y, 10); mpfr_set_prec (z, 10); mpfr_set_ui (y, 0, GMP_RNDN); @@ -348,15 +348,15 @@ check_inexact () mpfr_init (z); mpfr_init (u); - for (px=1; px<MAX_PREC; px++) + for (px=2; px<MAX_PREC; px++) { mpfr_set_prec (x, px); mpfr_random (x); - for (pu=1; pu<MAX_PREC; pu++) + for (pu=2; pu<MAX_PREC; pu++) { mpfr_set_prec (u, pu); mpfr_random (u); - for (py=1; py<MAX_PREC; py++) + for (py=2; py<MAX_PREC; py++) { mpfr_set_prec (y, py); pz = (mpfr_cmp_abs (x, u) >= 0) ? MPFR_EXP(x)-MPFR_EXP(u) @@ -407,7 +407,7 @@ main() check_inexact (); bug_ddefour (); - for (p=1; p<200; p++) + for (p=2; p<200; p++) for (i=0; i<200; i++) check_two_sum (p); diff --git a/tests/tsub_ui.c b/tests/tsub_ui.c index 4d56ce99d..a6167fed5 100644 --- a/tests/tsub_ui.c +++ b/tests/tsub_ui.c @@ -139,7 +139,7 @@ int main(argc,argv) int argc; char *argv[]; } #endif - for (p=1; p<200; p++) + for (p=2; p<200; p++) for (k=0; k<200; k++) check_two_sum (p); check3(0.9999999999, 1, GMP_RNDN, -1.000000082740370999e-10); diff --git a/tests/ttan.c b/tests/ttan.c index b667505c0..3bb2d3189 100644 --- a/tests/ttan.c +++ b/tests/ttan.c @@ -59,17 +59,17 @@ main(int argc, char *argv[]) check53(-1.0/0.0, 0.0/0.0, GMP_RNDN); mpfr_init (x); - mpfr_set_prec (x, 1); + 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.50) + if (mpfr_get_d(x) != 0.5) { fprintf (stderr, "mpfr_tan(0.5, GMP_RNDD) failed\n"); exit (1); } mpfr_clear (x); - test_generic (1, 100, 100); + test_generic (2, 100, 100); return 0; } diff --git a/tests/ttanh.c b/tests/ttanh.c index b83f0b689..90b7c23ae 100644 --- a/tests/ttanh.c +++ b/tests/ttanh.c @@ -31,7 +31,7 @@ MA 02111-1307, USA. */ int main (int argc, char *argv[]) { - test_generic (1, 100, 100); + test_generic (2, 100, 100); return 0; } diff --git a/tests/ttrunc.c b/tests/ttrunc.c index 47752bef8..1f5338409 100644 --- a/tests/ttrunc.c +++ b/tests/ttrunc.c @@ -64,9 +64,9 @@ main (void) for (j=0;j<1000;j++) { mpfr_random(x); - MPFR_EXP(x) = 1; + MPFR_EXP(x) = 2; - for (k = 1; k <= SIZEX; k++) + for (k = 2; k <= SIZEX; k++) { mpfr_set_prec(y, k); mpfr_set_prec(y2, k); diff --git a/tests/tui_div.c b/tests/tui_div.c index 78a98f079..c145aa784 100644 --- a/tests/tui_div.c +++ b/tests/tui_div.c @@ -69,12 +69,12 @@ check_inexact () mpfr_init (y); mpfr_init (z); - for (px=1; px<300; px++) + for (px=2; px<300; px++) { mpfr_set_prec (x, px); mpfr_random (x); u = lrand48 (); - for (py=1; py<300; py++) + for (py=2; py<300; py++) { mpfr_set_prec (y, py); mpfr_set_prec (z, py + px); diff --git a/tests/tui_pow.c b/tests/tui_pow.c index 69cb0dc6a..42dd13739 100644 --- a/tests/tui_pow.c +++ b/tests/tui_pow.c @@ -37,13 +37,14 @@ main (int argc, char *argv[]) mpfr_init (x); mpfr_init (y); - n=abs(random()); + n = abs(random()); + MPFR_CLEAR_NAN(x); MPFR_SET_INF(x); - mpfr_ui_pow (y, n,x, GMP_RNDN); + mpfr_ui_pow (y, n, x, GMP_RNDN); if(!MPFR_IS_INF(y)) { - printf ("evaluation of function in INF does not return INF"); + printf ("evaluation of function in INF does not return INF\n"); exit (1); } @@ -70,7 +71,7 @@ main (int argc, char *argv[]) int inexact, compare, compare2; unsigned int n, err; - int p0=1; + int p0=2; int p1=100; int N=100; diff --git a/tests/tui_sub.c b/tests/tui_sub.c index 4a5a3f6db..ab8ec651c 100644 --- a/tests/tui_sub.c +++ b/tests/tui_sub.c @@ -230,7 +230,7 @@ main (int argc, char *argv[]) } #endif special (); - for (p=1; p<100; p++) + for (p=2; p<100; p++) for (k=0; k<100; k++) check_two_sum (p); check(1, 1.0/0.0, GMP_RNDN, -1.0/0.0); |