diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tabs.c | 4 | ||||
-rw-r--r-- | tests/tatan.c | 7 | ||||
-rw-r--r-- | tests/tcmp2.c | 13 | ||||
-rw-r--r-- | tests/tconst_log2.c | 4 | ||||
-rw-r--r-- | tests/tdiv.c | 22 | ||||
-rw-r--r-- | tests/tdiv_ui.c | 12 | ||||
-rw-r--r-- | tests/teq.c | 4 | ||||
-rw-r--r-- | tests/texceptions.c | 6 | ||||
-rw-r--r-- | tests/texp.c | 73 | ||||
-rw-r--r-- | tests/tgeneric.c | 6 | ||||
-rw-r--r-- | tests/tget_d.c | 42 | ||||
-rw-r--r-- | tests/tget_str.c | 28 | ||||
-rw-r--r-- | tests/thyperbolic.c | 765 | ||||
-rw-r--r-- | tests/tlog.c | 247 | ||||
-rw-r--r-- | tests/tmul_ui.c | 29 | ||||
-rw-r--r-- | tests/tout_str.c | 7 | ||||
-rw-r--r-- | tests/tpow.c | 19 | ||||
-rw-r--r-- | tests/trandom.c | 204 | ||||
-rw-r--r-- | tests/tset_ld.c | 4 | ||||
-rw-r--r-- | tests/tset_q.c | 16 | ||||
-rw-r--r-- | tests/tset_z.c | 26 | ||||
-rw-r--r-- | tests/tsqrt.c | 36 | ||||
-rw-r--r-- | tests/tsqrt_ui.c | 4 | ||||
-rw-r--r-- | tests/tsub.c | 13 | ||||
-rw-r--r-- | tests/tsub_ui.c | 2 | ||||
-rw-r--r-- | tests/tui_div.c | 14 |
26 files changed, 772 insertions, 835 deletions
diff --git a/tests/tabs.c b/tests/tabs.c index 7ec390f9e..8c86a0f63 100644 --- a/tests/tabs.c +++ b/tests/tabs.c @@ -26,9 +26,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void check_inexact _PROTO((void)); - -void +static void check_inexact (void) { mp_prec_t p, q; diff --git a/tests/tatan.c b/tests/tatan.c index f2a6101ad..dbf0d4d2b 100644 --- a/tests/tatan.c +++ b/tests/tatan.c @@ -1,6 +1,6 @@ /* Test file for mpfr_arctan. -Copyright 2001, 2002 Free Software Foundation. +Copyright 2001, 2002, 2003 Free Software Foundation. Written by Paul Zimmermann, INRIA Lorraine. This file is part of the MPFR Library. @@ -26,10 +26,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void worst_cases _PROTO((void)); -int mpfr_arctan_aux2 _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t)); - -void +static void worst_cases (void) { mpfr_t x, y, z; diff --git a/tests/tcmp2.c b/tests/tcmp2.c index b290c9b92..e26f3b426 100644 --- a/tests/tcmp2.c +++ b/tests/tcmp2.c @@ -26,13 +26,8 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -void tcmp2 _PROTO ((double, double, int)); -void special _PROTO ((void)); -void worst_cases _PROTO ((void)); -void set_bit _PROTO ((mpfr_t, unsigned int, int)); - /* set bit n of x to b, where bit 0 is the most significant one */ -void +static void set_bit (mpfr_t x, unsigned int n, int b) { unsigned l; @@ -52,7 +47,7 @@ set_bit (mpfr_t x, unsigned int n, int b) y = 1.u 0 v 1^k low(y) mpfr_cmp2 (x, y) returns 1 + |u| + |v| + k for low(x) >= low(y), and 1 + |u| + |v| + k + 1 otherwise */ -void +static void worst_cases (void) { mpfr_t x, y; @@ -146,7 +141,7 @@ worst_cases (void) mpfr_clear (y); } -void +static void tcmp2 (double x, double y, int i) { mpfr_t xx, yy; @@ -186,7 +181,7 @@ tcmp2 (double x, double y, int i) mpfr_clear(xx); mpfr_clear(yy); } -void +static void special (void) { mpfr_t x, y; diff --git a/tests/tconst_log2.c b/tests/tconst_log2.c index 43b577ea0..47840cb9d 100644 --- a/tests/tconst_log2.c +++ b/tests/tconst_log2.c @@ -29,9 +29,7 @@ MA 02111-1307, USA. */ /* tlog2 [prec] [rnd] [0 = no print] */ -void check _PROTO ((mp_prec_t, mp_prec_t)); - -void +static void check (mp_prec_t p0, mp_prec_t p1) { mpfr_t x, y, z; diff --git a/tests/tdiv.c b/tests/tdiv.c index 5a5a8b70a..9ceb89981 100644 --- a/tests/tdiv.c +++ b/tests/tdiv.c @@ -30,16 +30,8 @@ MA 02111-1307, USA. */ #define check53(n, d, rnd, res) check4(n, d, rnd, 53, res) -void check4 _PROTO((double, double, mp_rnd_t, int, double)); -void check24 _PROTO((float, float, mp_rnd_t, float)); -void check_float _PROTO((void)); -void check_convergence _PROTO((void)); -void check_lowr _PROTO((void)); -void check_inexact _PROTO((void)); -void check_nan _PROTO((void)); - /* if Q is not zero, then it is the correct result */ -void +static void check4 (double N, double D, mp_rnd_t rnd_mode, int p, double Q) { mpfr_t q, n, d; @@ -65,7 +57,7 @@ check4 (double N, double D, mp_rnd_t rnd_mode, int p, double Q) mpfr_clear (d); } -void +static void check24 (float N, float D, mp_rnd_t rnd_mode, float Q) { mpfr_t q, n, d; float Q2; @@ -86,7 +78,7 @@ check24 (float N, float D, mp_rnd_t rnd_mode, float Q) /* the following examples come from the paper "Number-theoretic Test Generation for Directed Rounding" from Michael Parks, Table 2 */ -void +static void check_float(void) { float b=8388608.0; /* 2^23 */ @@ -132,7 +124,7 @@ check_float(void) check24(b*12582913.0, 8388610.0, GMP_RNDD, 1.258291e7); } -void +static void check_convergence (void) { mpfr_t x, y; int i, j; @@ -175,7 +167,7 @@ check_convergence (void) mpfr_clear(x); mpfr_clear(y); } -void +static void check_lowr (void) { mpfr_t x, y, z, z2, z3, tmp; @@ -305,7 +297,7 @@ check_lowr (void) #define MAX_PREC 100 -void +static void check_inexact (void) { mpfr_t x, y, z, u; @@ -388,7 +380,7 @@ check_inexact (void) mpfr_clear (u); } -void +static void check_nan (void) { mpfr_t a, d, q; diff --git a/tests/tdiv_ui.c b/tests/tdiv_ui.c index 2feecaf07..5a30e779e 100644 --- a/tests/tdiv_ui.c +++ b/tests/tdiv_ui.c @@ -27,11 +27,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void check _PROTO((double, unsigned long, mp_rnd_t, double)); -void special _PROTO((void)); -void check_inexact _PROTO((void)); - -void +static void check (double d, unsigned long u, mp_rnd_t rnd, double e) { mpfr_t x, y; @@ -49,12 +45,12 @@ check (double d, unsigned long u, mp_rnd_t rnd, double e) printf ("expected result is %1.20e, got %1.20e, dif=%d ulp\n", e, f, ulp (e,f)); exit (1); - } + } mpfr_clear (x); mpfr_clear (y); } -void +static void special (void) { mpfr_t x, y; @@ -119,7 +115,7 @@ special (void) mpfr_clear (y); } -void +static void check_inexact (void) { mpfr_t x, y, z; diff --git a/tests/teq.c b/tests/teq.c index 79933dd9b..6a63f8311 100644 --- a/tests/teq.c +++ b/tests/teq.c @@ -26,9 +26,7 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -void teq _PROTO ((mpfr_t)); - -void +static void teq (mpfr_t x) { mpfr_t y; long k, px, mx; diff --git a/tests/texceptions.c b/tests/texceptions.c index d822d7ddb..7f2fd829e 100644 --- a/tests/texceptions.c +++ b/tests/texceptions.c @@ -1,6 +1,6 @@ /* Test file for exceptions. -Copyright 2001, 2002 Free Software Foundation. +Copyright 2001, 2002, 2003 Free Software Foundation. This file is part of the MPFR Library. @@ -25,9 +25,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void mpfr_set_double_range _PROTO((void)); - -void +static void mpfr_set_double_range (void) { mpfr_set_default_prec (53); diff --git a/tests/texp.c b/tests/texp.c index c5af39d69..00d4e9301 100644 --- a/tests/texp.c +++ b/tests/texp.c @@ -28,18 +28,12 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -int check3 _PROTO((double, mp_rnd_t, double)); -int check_large _PROTO((double, int, mp_rnd_t)); -int check_worst_case _PROTO((double, double)); -int check_worst_cases _PROTO((void)); -void compare_exp2_exp3 _PROTO((int)); - int maxu=0; #define check(d, r) check3(d, r, 0.0) /* returns the number of ulp of error */ -int +static int check3 (double d, mp_rnd_t rnd, double e) { mpfr_t x, y; @@ -75,38 +69,42 @@ check3 (double d, mp_rnd_t rnd, double e) } /* computes n bits of exp(d) */ -int +static int check_large (double d, int n, mp_rnd_t rnd) { mpfr_t x; mpfr_t y; mpfr_init2(x, n); mpfr_init2(y, n); - if (d==0.0) { /* try exp(Pi*sqrt(163)/3)-640320 */ - mpfr_set_d(x, 163.0, rnd); - mpfr_sqrt(x, x, rnd); - mpfr_const_pi(y, rnd); - mpfr_mul(x, x, y, rnd); - mpfr_div_ui(x, x, 3, rnd); - } + if (d==0.0) + { /* try exp(Pi*sqrt(163)/3)-640320 */ + mpfr_set_d(x, 163.0, rnd); + mpfr_sqrt(x, x, rnd); + mpfr_const_pi(y, rnd); + mpfr_mul(x, x, y, rnd); + mpfr_div_ui(x, x, 3, rnd); + } else mpfr_set_d(x, d, rnd); mpfr_exp (y, x, rnd); - if (d==0.0) { - mpfr_set_d(x, 640320.0, rnd); - mpfr_sub(y, y, x, rnd); - printf("exp(Pi*sqrt(163)/3)-640320="); - } - else printf("exp(%1.20e)=",d); + if (d==0.0) + { + mpfr_set_d(x, 640320.0, rnd); + mpfr_sub(y, y, x, rnd); + printf("exp(Pi*sqrt(163)/3)-640320="); + } + else + printf("exp(%1.20e)=",d); mpfr_out_str(stdout, 10, 0, y, rnd); putchar('\n'); printf(" ="); mpfr_print_binary(y); putchar('\n'); - if (n==53) printf(" =%1.20e\n", mpfr_get_d1 (y)); + if (n==53) + printf(" =%1.20e\n", mpfr_get_d1 (y)); mpfr_clear(x); mpfr_clear(y); return 0; } /* expx is the value of exp(X) rounded towards -infinity */ -int +static int check_worst_case (double X, double expx) { mpfr_t x, y; @@ -114,22 +112,26 @@ check_worst_case (double X, double expx) mpfr_init2(x, 53); mpfr_init2(y, 53); mpfr_set_d(x, X, GMP_RNDN); mpfr_exp(y, x, GMP_RNDD); - if (mpfr_get_d1 (y) != expx) { - fprintf(stderr, "exp(x) rounded towards -infinity is wrong\n"); exit(1); - } + if (mpfr_get_d1 (y) != expx) + { + fprintf(stderr, "exp(x) rounded towards -infinity is wrong\n"); + exit(1); + } mpfr_exp(x, x, GMP_RNDN); mpfr_set_d(x, X, GMP_RNDN); mpfr_exp(x, x, GMP_RNDU); mpfr_add_one_ulp(y, GMP_RNDN); - if (mpfr_cmp(x,y)) { - fprintf(stderr, "exp(x) rounded towards +infinity is wrong\n"); exit(1); - } + if (mpfr_cmp(x,y)) + { + fprintf(stderr, "exp(x) rounded towards +infinity is wrong\n"); + exit(1); + } mpfr_clear(x); mpfr_clear(y); return 0; } /* worst cases communicated by Jean-Michel Muller and Vincent Lefevre */ -int +static int check_worst_cases (void) { mpfr_t x; mpfr_t y; @@ -159,17 +161,18 @@ check_worst_cases (void) mpfr_init2 (y, 601); mpfr_exp_2 (y, x, GMP_RNDD); mpfr_exp3 (x, x, GMP_RNDD); - if (mpfr_cmp (x, y)) { - fprintf (stderr, "mpfr_exp_2 and mpfr_exp3 for prec=601\n"); - exit (1); - } + if (mpfr_cmp (x, y)) + { + fprintf (stderr, "mpfr_exp_2 and mpfr_exp3 for prec=601\n"); + exit (1); + } mpfr_clear (x); mpfr_clear (y); return 0; } -void +static void compare_exp2_exp3 (int n) { mpfr_t x, y, z; int prec; mp_rnd_t rnd; diff --git a/tests/tgeneric.c b/tests/tgeneric.c index 1176f1ace..70a8a7903 100644 --- a/tests/tgeneric.c +++ b/tests/tgeneric.c @@ -1,6 +1,6 @@ /* Generic test file for functions with one mpfr_t argument. -Copyright 2001, 2002 Free Software Foundation. +Copyright 2001, 2002, 2003 Free Software Foundation. This file is part of the MPFR Library. @@ -19,9 +19,7 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -void test_generic _PROTO((int, int, int)); - -void +static void test_generic (int p0, int p1, int N) { mp_prec_t prec, yprec; diff --git a/tests/tget_d.c b/tests/tget_d.c index 081d4537d..a1dc1e0a4 100644 --- a/tests/tget_d.c +++ b/tests/tget_d.c @@ -28,9 +28,7 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -int check_denorms _PROTO ((void)); - -int +static int check_denorms () { mp_rnd_t rnd_mode; @@ -46,29 +44,29 @@ check_denorms () mpfr_init2 (x, BITS_PER_MP_LIMB); - rnd_mode = GMP_RNDN; - for (k = -17; k <= 17; k += 2) + rnd_mode = GMP_RNDN; + for (k = -17; k <= 17; k += 2) + { + d = (double) k * dbl_min; /* k * 2^(-1022) */ + f = 1.0; + mpfr_set_si (x, k, GMP_RNDN); + mpfr_div_2exp (x, x, 1022, GMP_RNDN); /* k * 2^(-1022) */ + for (n = 0; n <= 58; n++) { - d = (double) k * dbl_min; /* k * 2^(-1022) */ - f = 1.0; - mpfr_set_si (x, k, GMP_RNDN); - mpfr_div_2exp (x, x, 1022, GMP_RNDN); /* k * 2^(-1022) */ - for (n = 0; n <= 58; n++) + d2 = d * f; + dd = mpfr_get_d (x, rnd_mode); + if (d2 != dd) /* should be k * 2^(-1022-n) for n < 53 */ { - d2 = d * f; - dd = mpfr_get_d (x, rnd_mode); - if (d2 != dd) /* should be k * 2^(-1022-n) for n < 53 */ - { - fprintf (stderr, - "Wrong result for %d * 2^(%d), rnd_mode %d\n", - k, -1022-n, rnd_mode); - fprintf (stderr, "got %.20e instead of %.20e\n", dd, d2); - fail = 1; - } - f *= 0.5; - mpfr_div_2exp (x, x, 1, GMP_RNDN); + fprintf (stderr, + "Wrong result for %d * 2^(%d), rnd_mode %d\n", + k, -1022-n, rnd_mode); + fprintf (stderr, "got %.20e instead of %.20e\n", dd, d2); + fail = 1; } + f *= 0.5; + mpfr_div_2exp (x, x, 1, GMP_RNDN); } + } mpfr_clear (x); return fail; diff --git a/tests/tget_str.c b/tests/tget_str.c index a15a141f1..dd573daa1 100644 --- a/tests/tget_str.c +++ b/tests/tget_str.c @@ -28,27 +28,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void check _PROTO((double, mp_rnd_t)); -void check3 _PROTO((double, mp_rnd_t, char *)); -void check_small _PROTO((void)); -void check_large _PROTO((void)); -void check_special _PROTO((int, mp_prec_t)); - -void -check (double d, mp_rnd_t rnd) -{ - 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); - mpfr_clear (x); - (*__gmp_free_func) (str, strlen (str) + 1); -} - -void +static void check3 (double d, mp_rnd_t rnd, char *res) { mpfr_t x; @@ -68,7 +48,7 @@ check3 (double d, mp_rnd_t rnd, char *res) (*__gmp_free_func) (str, strlen (str) + 1); } -void +static void check_small (void) { mpfr_t x; @@ -204,7 +184,7 @@ check_small (void) } /* bugs found by Alain Delplanque */ -void +static void check_large (void) { mpfr_t x; @@ -293,7 +273,7 @@ check_large (void) #define MAX_DIGITS 100 -void +static void check_special (int b, mp_prec_t p) { mpfr_t x; diff --git a/tests/thyperbolic.c b/tests/thyperbolic.c index c827750db..2e2a8208b 100644 --- a/tests/thyperbolic.c +++ b/tests/thyperbolic.c @@ -1,6 +1,6 @@ /* Test file for hyperbolic function : mpfr_cosh, mpfr_sinh, mpfr_tanh, mpfr_acosh, mpfr_asinh, mpfr_atanh. -Copyright 2001, 2002 Free Software Foundation, Inc. +Copyright 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -25,119 +25,110 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" - -int check_O _PROTO((void)); -int check_NAN _PROTO((void)); -int check_zero _PROTO((void)); -int check_INF _PROTO((void)); - - - -int +static int check_NAN (void) { + mpfr_t t, ch,sh,th,ach,ash,ath; + int tester; - mpfr_t t, ch,sh,th,ach,ash,ath; - int tester; - - mpfr_init2(t,200); - mpfr_init2(ch,200); - mpfr_init2(sh,200); - mpfr_init2(th,200); - mpfr_init2(ach,200); - mpfr_init2(ash,200); - mpfr_init2(ath,200); + mpfr_init2(t,200); + mpfr_init2(ch,200); + mpfr_init2(sh,200); + mpfr_init2(th,200); + mpfr_init2(ach,200); + mpfr_init2(ash,200); + mpfr_init2(ath,200); - MPFR_SET_NAN(t); + MPFR_SET_NAN(t); /******cosh********/ tester=mpfr_cosh(ch,t,GMP_RNDD); - if (!MPFR_IS_NAN(ch) || tester!=0 ) - { - printf("cosh NAN \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_NAN(ch) || tester!=0) + { + printf("cosh NAN \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******sinh********/ tester=mpfr_sinh(sh,t,GMP_RNDD); - if (!MPFR_IS_NAN(sh) || tester!=0 ) - { - printf("sinh NAN \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_NAN(sh) || tester!=0) + { + printf("sinh NAN \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******tanh********/ tester=mpfr_tanh(th,t,GMP_RNDD); - if (!MPFR_IS_NAN(th) || tester!=0 ) - { - printf("tanh NAN \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_NAN(th) || tester!=0) + { + printf("tanh NAN \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******acosh********/ tester=mpfr_acosh(ach,t,GMP_RNDD); - if (!MPFR_IS_NAN(ach) || tester!=0 ) - { - printf("acosh NAN \n"); - return(1); - } + if (!MPFR_IS_NAN(ach) || tester!=0) + { + printf("acosh NAN \n"); + return(1); + } /******asinh********/ tester=mpfr_asinh(ash,t,GMP_RNDD); - if (!MPFR_IS_NAN(ash) || tester!=0 ) - { - printf("asinh NAN \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_NAN(ash) || tester!=0) + { + printf("asinh NAN \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******atanh********/ tester=mpfr_atanh(ath,t,GMP_RNDD); - if (!MPFR_IS_NAN(ath) || tester!=0 ) - { - printf("atanh NAN \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_NAN(ath) || tester!=0) + { + printf("atanh NAN \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } mpfr_clear(t); mpfr_clear(ch); @@ -148,121 +139,120 @@ check_NAN (void) mpfr_clear(ath); return(0); - } -int + +#if 0 +static int check_zero (void) { + mpfr_t t, ch,sh,th,ach,ash,ath; + int tester; - mpfr_t t, ch,sh,th,ach,ash,ath; - int tester; + mpfr_init2(t,200); + mpfr_init2(ch,200); + mpfr_init2(sh,200); + mpfr_init2(th,200); + mpfr_init2(ach,200); + mpfr_init2(ash,200); + mpfr_init2(ath,200); - mpfr_init2(t,200); - mpfr_init2(ch,200); - mpfr_init2(sh,200); - mpfr_init2(th,200); - mpfr_init2(ach,200); - mpfr_init2(ash,200); - mpfr_init2(ath,200); - - - mpfr_set_ui(t,0,GMP_RNDD); + mpfr_set_ui(t,0,GMP_RNDD); /******cosh********/ tester=mpfr_cosh(ch,t,GMP_RNDD); - if (!mpfr_cmp_ui(ch,1) || !tester ) - { - printf("cosh(0) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!mpfr_cmp_ui(ch,1) || !tester) + { + printf("cosh(0) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******sinh********/ tester=mpfr_sinh(sh,t,GMP_RNDD); - if (!MPFR_IS_ZERO(sh) || !tester ) - { - printf("sinh(0) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_ZERO(sh) || !tester) + { + printf("sinh(0) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******tanh********/ tester=mpfr_tanh(th,t,GMP_RNDD); - if (!MPFR_IS_ZERO(th) || !tester ) - { - printf("tanh(0) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_ZERO(th) || !tester) + { + printf("tanh(0) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******acosh********/ tester=mpfr_acosh(ach,t,GMP_RNDD); - if (!MPFR_IS_NAN(ach) || tester != -1 ) - { - printf("acosh(0) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_NAN(ach) || tester != -1) + { + printf("acosh(0) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******asinh********/ tester=mpfr_asinh(ash,t,GMP_RNDD); - if (!MPFR_IS_ZERO(ash) || !tester ) - { - printf("asinh(0) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_ZERO(ash) || !tester) + { + printf("asinh(0) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******atanh********/ tester=mpfr_atanh(ath,t,GMP_RNDD); - if (!MPFR_IS_ZERO(ath) || !tester ) - { - printf("atanh(0) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_ZERO(ath) || !tester) + { + printf("atanh(0) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } mpfr_clear(t); mpfr_clear(ch); @@ -273,224 +263,222 @@ check_zero (void) mpfr_clear(ath); return(0); - } +#endif -int +static int check_INF (void) { + mpfr_t t, ch,sh,th,ach,ash,ath; + int tester; - mpfr_t t, ch,sh,th,ach,ash,ath; - int tester; - - - mpfr_init2(t,200); - mpfr_init2(ch,200); - mpfr_init2(sh,200); - mpfr_init2(th,200); - mpfr_init2(ach,200); - mpfr_init2(ash,200); - mpfr_init2(ath,200); + mpfr_init2(t,200); + mpfr_init2(ch,200); + mpfr_init2(sh,200); + mpfr_init2(th,200); + mpfr_init2(ach,200); + mpfr_init2(ash,200); + mpfr_init2(ath,200); - MPFR_CLEAR_NAN(t); - MPFR_SET_INF(t); + MPFR_CLEAR_NAN(t); + MPFR_SET_INF(t); - if(MPFR_SIGN(t)<0) - MPFR_CHANGE_SIGN(t); + if(MPFR_SIGN(t)<0) + MPFR_CHANGE_SIGN(t); /******cosh********/ tester = mpfr_cosh(ch,t,GMP_RNDD); - if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0 ) - { - printf("cosh(INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0) + { + printf("cosh(INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******sinh********/ tester=mpfr_sinh(sh,t,GMP_RNDD); - if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) < 0 || tester!=0 ) - { - printf("sinh(INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) < 0 || tester!=0) + { + printf("sinh(INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******tanh********/ tester=mpfr_tanh(th,t,GMP_RNDD); - if (mpfr_cmp_ui(th,1) != 0 || tester!=0 ) - { - printf("tanh(INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (mpfr_cmp_ui(th,1) != 0 || tester!=0) + { + printf("tanh(INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******acosh********/ tester=mpfr_acosh(ach,t,GMP_RNDD); - if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0 || tester!=0 ) - { - printf("acosh(INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0 || tester!=0) + { + printf("acosh(INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******asinh********/ tester=mpfr_asinh(ash,t,GMP_RNDD); - if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) < 0 || tester!=0 ) - { - printf("asinh(INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) < 0 || tester!=0) + { + printf("asinh(INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******atanh********/ tester=mpfr_atanh(ath,t,GMP_RNDD); if (!MPFR_IS_INF(ath) || tester != 0) - { - printf("atanh(INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } - - MPFR_CHANGE_SIGN(t); + { + printf("atanh(INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } + + MPFR_CHANGE_SIGN(t); /******cosh********/ tester=mpfr_cosh(ch,t,GMP_RNDD); - if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0 ) - { - printf("cosh(-INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0) + { + printf("cosh(-INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******sinh********/ tester=mpfr_sinh(sh,t,GMP_RNDD); - if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) > 0 || tester!=0 ) - { - printf("sinh(-INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) > 0 || tester!=0) + { + printf("sinh(-INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******tanh********/ tester=mpfr_tanh(th,t,GMP_RNDD); - if (!mpfr_cmp_ui(th,-1) || tester!=0 ) - { - printf("tanh(-INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!mpfr_cmp_ui(th,-1) || tester!=0) + { + printf("tanh(-INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******acosh********/ tester=mpfr_acosh(ach,t,GMP_RNDD); - if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0 || tester!=0 ) - { - printf("acosh(-INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0 || tester!=0) + { + printf("acosh(-INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******asinh********/ tester=mpfr_asinh(ash,t,GMP_RNDD); - if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) > 0 || tester!=0 ) - { - printf("asinh(-INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) > 0 || tester!=0) + { + printf("asinh(-INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******atanh********/ tester=mpfr_atanh(ath,t,GMP_RNDD); - if (!MPFR_IS_INF(ath) || MPFR_SIGN(ath) > 0 || tester != 0 ) - { - printf("atanh(-INF) \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + if (!MPFR_IS_INF(ath) || MPFR_SIGN(ath) > 0 || tester != 0) + { + printf("atanh(-INF) \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } mpfr_clear(t); mpfr_clear(ch); @@ -500,61 +488,58 @@ check_INF (void) mpfr_clear(ash); mpfr_clear(ath); - return(0); - } -int +#if 0 +static int check_O (void) { + mpfr_t t, ch,sh,th,ach,ash,ath; - mpfr_t t, ch,sh,th,ach,ash,ath; + mpfr_init2(t,20); + mpfr_init2(ch,40); + mpfr_init2(sh,40); + mpfr_init2(th,40); + mpfr_init2(ach,40); + mpfr_init2(ash,40); + mpfr_init2(ath,40); - mpfr_init2(t,20); - mpfr_init2(ch,40); - mpfr_init2(sh,40); - mpfr_init2(th,40); - mpfr_init2(ach,40); - mpfr_init2(ash,40); - mpfr_init2(ath,40); - - mpfr_set_ui(t,2,GMP_RNDD); + mpfr_set_ui(t,2,GMP_RNDD); /******acosh o cosh********/ mpfr_cosh(ch,t,GMP_RNDN); mpfr_acosh(ach,ch,GMP_RNDN); if(mpfr_cmp_ui(ach,2)!=0) - { - printf("cosh o acosh \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + { + printf("cosh o acosh \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******asinh o sinh********/ mpfr_sinh(sh,t,GMP_RNDN); mpfr_asinh(ash,sh,GMP_RNDN); if(mpfr_cmp_ui(ash,2)!=0) - { - printf("sinh o asinh \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } - + { + printf("sinh o asinh \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } /******atanh o tanh********/ @@ -570,17 +555,17 @@ check_O (void) */ if(mpfr_cmp_ui(ath,2)!=0) - { - printf("tanh o atanh \n"); - mpfr_clear(t); - mpfr_clear(ch); - mpfr_clear(sh); - mpfr_clear(th); - mpfr_clear(ach); - mpfr_clear(ash); - mpfr_clear(ath); - return(1); - } + { + printf("tanh o atanh \n"); + mpfr_clear(t); + mpfr_clear(ch); + mpfr_clear(sh); + mpfr_clear(th); + mpfr_clear(ach); + mpfr_clear(ash); + mpfr_clear(ath); + return(1); + } mpfr_clear(t); mpfr_clear(ch); @@ -590,21 +575,23 @@ check_O (void) mpfr_clear(ash); mpfr_clear(ath); - return(0); - + return(0); } +#endif int main(void) { -tests_start_mpfr (); + tests_start_mpfr (); -if (check_INF())printf("Error in evaluation of INF\n"); -if (check_NAN())printf("Error in evaluation of NAN\n"); -/*if (check_O())printf("Error in evaluation of composition hyperbolic function\n");*/ + if (check_INF()) + printf("Error in evaluation of INF\n"); -tests_end_mpfr (); -return(0); + if (check_NAN()) + printf("Error in evaluation of NAN\n"); +/*if (check_O())printf("Error in evaluation of composition hyperbolic function\n");*/ + tests_end_mpfr (); + return(0); } diff --git a/tests/tlog.c b/tests/tlog.c index df5d26c62..92deb86fc 100644 --- a/tests/tlog.c +++ b/tests/tlog.c @@ -26,31 +26,24 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -double drand_log _PROTO((void)); -int check1 _PROTO((double, mp_rnd_t, double, int, int)); -void check3 _PROTO((double, unsigned long, mp_rnd_t)); -void check4 _PROTO((int)); -void slave _PROTO((int, int)); -void check_worst_cases _PROTO((void)); -void special _PROTO((void)); - #if (BITS_PER_LONGINT == 32) #define INT32 long int #else #define INT32 int #endif - -double +static double drand_log (void) { double d; INT32 *i; i = (INT32*) &d; - do { - i[0] = LONG_RAND(); - i[1] = LONG_RAND(); - } while ((d<1e-153) || (d>1e153)); /* to avoid underflow or overflow + do + { + i[0] = LONG_RAND(); + i[1] = LONG_RAND(); + } + while ((d<1e-153) || (d>1e153)); /* to avoid underflow or overflow in double calculus in sqrt(u*v) */ return d; } @@ -58,7 +51,7 @@ drand_log (void) #define check2(a,rnd,res) check1(a,rnd,res,1,0) #define check(a,r) check2(a,r,0.0) -int +static int check1 (double a, mp_rnd_t rnd_mode, double res1, int ck, int max_ulp) { mpfr_t ta, tres; @@ -89,7 +82,7 @@ check1 (double a, mp_rnd_t rnd_mode, double res1, int ck, int max_ulp) return 0; } -void +static void check3 (double d, unsigned long prec, mp_rnd_t rnd) { mpfr_t x, y; @@ -102,28 +95,29 @@ check3 (double d, unsigned long prec, mp_rnd_t rnd) mpfr_clear(x); mpfr_clear(y); } -void +static void check4 (int N) { int i, max=0, sum=0, cur; double d; mp_rnd_t rnd; - for(i=0;i<N;i++) { - d = drand_log (); - rnd = LONG_RAND() % 4; - cur=check1 (d, rnd, 0.0, 0, max); - if (cur<0) - cur = -cur; - if (cur > max) - max=cur; - sum+=cur; - } - d=(double)sum / (double)N; + for(i=0;i<N;i++) + { + d = drand_log (); + rnd = LONG_RAND() % 4; + cur = check1 (d, rnd, 0.0, 0, max); + if (cur < 0) + cur = -cur; + if (cur > max) + max = cur; + sum += cur; + } + d = (double)sum / (double)N; fprintf(stderr, "max error : %i \t mean error : %f (in ulps)\n",max,d); } -void +static void slave (int N, int p) { int i; @@ -132,11 +126,12 @@ slave (int N, int p) mpfr_init2(ta, 53); mpfr_init2(tres, p); - for(i=0;i<N;i++) { - d = drand_log(); - mpfr_set_d (ta, d, GMP_RNDN); - mpfr_log (tres, ta, LONG_RAND() % 4 ); - } + for(i=0;i<N;i++) + { + d = drand_log(); + mpfr_set_d (ta, d, GMP_RNDN); + mpfr_log (tres, ta, LONG_RAND() % 4 ); + } mpfr_clear(ta); mpfr_clear(tres); printf("fin\n"); } @@ -145,9 +140,9 @@ slave (int N, int p) Cf http://www.ens-lyon.fr/~jmmuller/Intro-to-TMD.htm */ -void +static void check_worst_cases (void) -{ +{ check2(1.00089971802309629645, GMP_RNDD, 8.99313519443722736088e-04); check2(1.00089971802309629645, GMP_RNDN, 8.99313519443722844508e-04); check2(1.00089971802309629645, GMP_RNDU, 8.99313519443722844508e-04); @@ -229,7 +224,7 @@ check_worst_cases (void) check2(428.315247165198229595, GMP_RNDU, 6.05985948325268353187); } -void +static void special (void) { mpfr_t x, y; @@ -238,10 +233,11 @@ special (void) mpfr_init2 (y, 53); mpfr_set_ui (x, 3, GMP_RNDD); mpfr_log (y, x, GMP_RNDD); - if (mpfr_get_d1 (y) != 1.09861228866810956) { - fprintf (stderr, "Error in mpfr_log(3) for GMP_RNDD\n"); - exit (1); - } + if (mpfr_get_d1 (y) != 1.09861228866810956) + { + fprintf (stderr, "Error in mpfr_log(3) for GMP_RNDD\n"); + exit (1); + } /* check large precision */ mpfr_set_prec (x, 3322); @@ -266,89 +262,94 @@ main (int argc, char *argv[]) tests_start_mpfr (); SEED_RAND (time(NULL)); - if (argc==4) { /* tlog x prec rnd */ - check3(atof(argv[1]), atoi(argv[2]), atoi(argv[3])); - goto done; - } - - if (argc==3) { /* tlog N p : N calculus with precision p*/ - printf("Doing %d random tests in %d precision\n",atoi(argv[1]),atoi(argv[2])); - slave(atoi(argv[1]),atoi(argv[2])); - goto done; - } - - if (argc==2) { /* tlog N: N tests with random double's */ - N=atoi(argv[1]); - printf("Doing %d random tests in double precision\n", N); - check4(N); - } - else { - special (); - check_worst_cases(); + if (argc==4) + { /* tlog x prec rnd */ + check3(atof(argv[1]), atoi(argv[2]), atoi(argv[3])); + goto done; + } - check2(1.01979300812244555452, GMP_RNDN, 1.95996734891603664741e-02); - check2(10.0,GMP_RNDU,2.30258509299404590110e+00); - check2(6.0,GMP_RNDU,1.79175946922805517936); - check2(1.0,GMP_RNDZ,0.0); - check2(62.0,GMP_RNDU,4.12713438504509166905); - check2(0.5,GMP_RNDZ,-6.93147180559945286226e-01); - check2(3.0,GMP_RNDZ,1.09861228866810956006e+00); - check2(234375765.0,GMP_RNDU,1.92724362186836231104e+01); - check2(8.0,GMP_RNDZ,2.07944154167983574765e+00); - check2(44.0,GMP_RNDU,3.78418963391826146392e+00); - check2(1.01979300812244555452, GMP_RNDN, 1.95996734891603664741e-02); - /* bugs found by Vincent Lefe`vre */ - d = -4723773766428415.0 / 1180591620717411303424.0; - check2(0.99999599881598921769, GMP_RNDN, d); - check2(9.99995576063808955247e-01, GMP_RNDZ, -4.42394597667932383816e-06); - check2(9.99993687357856209097e-01, GMP_RNDN, -6.31266206860017342601e-06); - check2(9.99995223520736886691e-01, GMP_RNDN, -4.77649067052670982220e-06); - check2(9.99993025794720935551e-01, GMP_RNDN, -6.97422959894716163837e-06); - check2(9.99987549017837484833e-01, GMP_RNDN, -1.24510596766369924330e-05); - check2(9.99985901426543311032e-01, GMP_RNDN, -1.40986728425098585229e-05); - d = -8232353813100321.0 / 590295810358705651712.0; - check2(9.99986053947420794330e-01, GMP_RNDN, d); - check2(9.99971938247442126979e-01, GMP_RNDN, -2.80621462962173414790e-05); - /* other bugs found by Vincent Lefe`vre */ - check2(1.18615436389927785905e+77, GMP_RNDN, 1.77469768607706015473e+02); - check2(9.48868723578399476187e+77, GMP_RNDZ, 1.79549152432275803903e+02); - check2(2.31822210096938820854e+89, GMP_RNDN, 2.05770873832573869322e+02); - /* further bugs found by Vincent Lefe`vre */ - check2(9.99999989485669482647e-01, GMP_RNDZ, -1.05143305726283042331e-08); - check2(9.99999989237970177136e-01, GMP_RNDZ, -1.07620298807745377934e-08); - check2(9.99999989239339082125e-01, GMP_RNDN, -1.07606609757704445430e-08); - - check2(7.3890560989306504,GMP_RNDU,2.0000000000000004); /* exp(2.0) */ - check2(7.3890560989306495,GMP_RNDU,2.0); /* exp(2.0) */ - check2(7.53428236571286402512e+34,GMP_RNDZ,8.03073567492226345621e+01); - check2(6.18784121531737948160e+19,GMP_RNDZ,4.55717030391710693493e+01); - check2(1.02560267603047283735e+00,GMP_RNDD,2.52804164149448735987e-02); - check2(7.53428236571286402512e+34,GMP_RNDZ,8.03073567492226345621e+01); - d = 497773706319601.0 / 4398046511104.0; - check2(1.42470900831881198052e+49, GMP_RNDZ, d); - - check2(1.08013816255293777466e+11,GMP_RNDN,2.54055249841782604392e+01); - check2(6.72783635300509015581e-37,GMP_RNDU,-8.32893948416799503320e+01); - check2(2.25904918906057891180e-52,GMP_RNDU,-1.18919480823735682406e+02); - check2(1.48901209246462951085e+00,GMP_RNDD,3.98112874867437460668e-01); - check2(1.70322470467612341327e-01,GMP_RNDN,-1.77006175364294615626); - check2(1.94572026316065240791e+01,GMP_RNDD,2.96821731676437838842); - check2(4.01419512207026418764e+04,GMP_RNDD,1.06001772315501128218e+01); - check2(9.47077365236487591672e-04,GMP_RNDZ,-6.96212977303956748187e+00); - check2(3.95906157687589643802e-109,GMP_RNDD,-2.49605768114704119399e+02); - check2(2.73874914516503004113e-02,GMP_RNDD,-3.59766888618655977794e+00); - check2(9.18989072589566467669e-17,GMP_RNDZ,-3.69258425351464083519e+01); - check2(dbl(2830750724514701.0,131),GMP_RNDZ,dbl(1111664301085491.0,-43)); - check2(1.74827399630587801934e-23,GMP_RNDZ,-5.24008281254547156891e+01); - check2(4.35302958401482307665e+22,GMP_RNDD,5.21277441046519527390e+01); - check2(9.70791868689332915209e+00,GMP_RNDD,2.27294191194272210410e+00); - check2(2.22183639799464011100e-01,GMP_RNDN,-1.50425103275253957413e+00); - check2(2.27313466156682375540e+00,GMP_RNDD,8.21159787095675608448e-01); - check2(6.58057413965851156767e-01,GMP_RNDZ,-4.18463096196088235600e-01); - d = 7107588635148285.0 / 70368744177664.0; - check2 (7.34302197248998461006e+43, GMP_RNDZ, d); - check2(6.09969788341579732815e+00,GMP_RNDD,1.80823924264386204363e+00); - } + if (argc==3) + { /* tlog N p : N calculus with precision p*/ + printf("Doing %d random tests in %d precision\n", + atoi(argv[1]),atoi(argv[2])); + slave(atoi(argv[1]),atoi(argv[2])); + goto done; + } + + if (argc==2) + { /* tlog N: N tests with random double's */ + N=atoi(argv[1]); + printf("Doing %d random tests in double precision\n", N); + check4(N); + } + else + { + special (); + check_worst_cases(); + + check2(1.01979300812244555452, GMP_RNDN, 1.95996734891603664741e-02); + check2(10.0,GMP_RNDU,2.30258509299404590110e+00); + check2(6.0,GMP_RNDU,1.79175946922805517936); + check2(1.0,GMP_RNDZ,0.0); + check2(62.0,GMP_RNDU,4.12713438504509166905); + check2(0.5,GMP_RNDZ,-6.93147180559945286226e-01); + check2(3.0,GMP_RNDZ,1.09861228866810956006e+00); + check2(234375765.0,GMP_RNDU,1.92724362186836231104e+01); + check2(8.0,GMP_RNDZ,2.07944154167983574765e+00); + check2(44.0,GMP_RNDU,3.78418963391826146392e+00); + check2(1.01979300812244555452, GMP_RNDN, 1.95996734891603664741e-02); + /* bugs found by Vincent Lefe`vre */ + d = -4723773766428415.0 / 1180591620717411303424.0; + check2(0.99999599881598921769, GMP_RNDN, d); + check2(9.99995576063808955247e-01, GMP_RNDZ, -4.42394597667932383816e-06); + check2(9.99993687357856209097e-01, GMP_RNDN, -6.31266206860017342601e-06); + check2(9.99995223520736886691e-01, GMP_RNDN, -4.77649067052670982220e-06); + check2(9.99993025794720935551e-01, GMP_RNDN, -6.97422959894716163837e-06); + check2(9.99987549017837484833e-01, GMP_RNDN, -1.24510596766369924330e-05); + check2(9.99985901426543311032e-01, GMP_RNDN, -1.40986728425098585229e-05); + d = -8232353813100321.0 / 590295810358705651712.0; + check2(9.99986053947420794330e-01, GMP_RNDN, d); + check2(9.99971938247442126979e-01, GMP_RNDN, -2.80621462962173414790e-05); + /* other bugs found by Vincent Lefe`vre */ + check2(1.18615436389927785905e+77, GMP_RNDN, 1.77469768607706015473e+02); + check2(9.48868723578399476187e+77, GMP_RNDZ, 1.79549152432275803903e+02); + check2(2.31822210096938820854e+89, GMP_RNDN, 2.05770873832573869322e+02); + /* further bugs found by Vincent Lefe`vre */ + check2(9.99999989485669482647e-01, GMP_RNDZ, -1.05143305726283042331e-08); + check2(9.99999989237970177136e-01, GMP_RNDZ, -1.07620298807745377934e-08); + check2(9.99999989239339082125e-01, GMP_RNDN, -1.07606609757704445430e-08); + + check2(7.3890560989306504,GMP_RNDU,2.0000000000000004); /* exp(2.0) */ + check2(7.3890560989306495,GMP_RNDU,2.0); /* exp(2.0) */ + check2(7.53428236571286402512e+34,GMP_RNDZ,8.03073567492226345621e+01); + check2(6.18784121531737948160e+19,GMP_RNDZ,4.55717030391710693493e+01); + check2(1.02560267603047283735e+00,GMP_RNDD,2.52804164149448735987e-02); + check2(7.53428236571286402512e+34,GMP_RNDZ,8.03073567492226345621e+01); + d = 497773706319601.0 / 4398046511104.0; + check2(1.42470900831881198052e+49, GMP_RNDZ, d); + + check2(1.08013816255293777466e+11,GMP_RNDN,2.54055249841782604392e+01); + check2(6.72783635300509015581e-37,GMP_RNDU,-8.32893948416799503320e+01); + check2(2.25904918906057891180e-52,GMP_RNDU,-1.18919480823735682406e+02); + check2(1.48901209246462951085e+00,GMP_RNDD,3.98112874867437460668e-01); + check2(1.70322470467612341327e-01,GMP_RNDN,-1.77006175364294615626); + check2(1.94572026316065240791e+01,GMP_RNDD,2.96821731676437838842); + check2(4.01419512207026418764e+04,GMP_RNDD,1.06001772315501128218e+01); + check2(9.47077365236487591672e-04,GMP_RNDZ,-6.96212977303956748187e+00); + check2(3.95906157687589643802e-109,GMP_RNDD,-2.49605768114704119399e+02); + check2(2.73874914516503004113e-02,GMP_RNDD,-3.59766888618655977794e+00); + check2(9.18989072589566467669e-17,GMP_RNDZ,-3.69258425351464083519e+01); + check2(dbl(2830750724514701.0,131),GMP_RNDZ,dbl(1111664301085491.0,-43)); + check2(1.74827399630587801934e-23,GMP_RNDZ,-5.24008281254547156891e+01); + check2(4.35302958401482307665e+22,GMP_RNDD,5.21277441046519527390e+01); + check2(9.70791868689332915209e+00,GMP_RNDD,2.27294191194272210410e+00); + check2(2.22183639799464011100e-01,GMP_RNDN,-1.50425103275253957413e+00); + check2(2.27313466156682375540e+00,GMP_RNDD,8.21159787095675608448e-01); + check2(6.58057413965851156767e-01,GMP_RNDZ,-4.18463096196088235600e-01); + d = 7107588635148285.0 / 70368744177664.0; + check2 (7.34302197248998461006e+43, GMP_RNDZ, d); + check2(6.09969788341579732815e+00,GMP_RNDD,1.80823924264386204363e+00); + } test_generic (2, 100, 40); diff --git a/tests/tmul_ui.c b/tests/tmul_ui.c index ee4bf9f3d..aaeaf952a 100644 --- a/tests/tmul_ui.c +++ b/tests/tmul_ui.c @@ -27,9 +27,7 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -void check_inexact _PROTO((mp_prec_t)); - -void +static void check_inexact (mp_prec_t p) { mpfr_t x, y, z; @@ -108,8 +106,7 @@ main (int argc, char *argv[]) printf ("y= "); mpfr_print_binary (y); putchar ('\n'); printf ("1*y="); mpfr_print_binary (x); putchar ('\n'); exit (1); - } - + } mpfr_set_inf (x, 1); mpfr_mul_ui (x, x, 3, GMP_RNDU); @@ -147,12 +144,13 @@ main (int argc, char *argv[]) mpfr_set_d(x, -2.0, GMP_RNDZ); mpfr_set_d(y, 3.0, GMP_RNDZ); mpfr_mul_ui(x, y, 4, GMP_RNDZ); - if (mpfr_cmp_ui(x, 0) <= 0) { - fprintf(stderr, "Error in mpfr_mul_ui: 4*3.0 does not give a positive result:\n"); - mpfr_print_binary(x); putchar('\n'); - printf("mpfr_cmp_ui(x, 0) = %d\n", mpfr_cmp_ui(x, 0)); - exit(1); - } + if (mpfr_cmp_ui(x, 0) <= 0) + { + fprintf(stderr, "Error in mpfr_mul_ui: 4*3.0 does not give a positive result:\n"); + mpfr_print_binary(x); putchar('\n'); + printf("mpfr_cmp_ui(x, 0) = %d\n", mpfr_cmp_ui(x, 0)); + exit(1); + } mpfr_set_prec (x, 9); mpfr_set_prec (y, 9); @@ -173,10 +171,11 @@ main (int argc, char *argv[]) mpfr_mul_ui(x, y, 121, GMP_RNDD); /* 121*y = 145173518207904485376, representable exactly */ mpfr_set_str_raw(y, "0.1111101111010101111111100011010010111010111110110011001E67"); - if (mpfr_cmp(x, y)) { - printf("Error for 121*y: expected result is:\n"); - mpfr_print_binary(y); putchar('\n'); - } + if (mpfr_cmp(x, y)) + { + printf("Error for 121*y: expected result is:\n"); + mpfr_print_binary(y); putchar('\n'); + } mpfr_set_prec (x, 32); mpfr_set_str_raw (x, "0.10000000000000000000000000000000E1"); diff --git a/tests/tout_str.c b/tests/tout_str.c index 440c9c872..c694948d6 100644 --- a/tests/tout_str.c +++ b/tests/tout_str.c @@ -33,10 +33,7 @@ FILE *fout; #define check(d,r,b) check4(d,r,b,53) -void check4 _PROTO((double, mp_rnd_t, int, int)); -void check_large _PROTO((void)); - -void +static void check4 (double d, mp_rnd_t rnd, int base, int prec) { mpfr_t x; @@ -49,7 +46,7 @@ check4 (double d, mp_rnd_t rnd, int base, int prec) mpfr_clear (x); } -void +static void check_large (void) { mpfr_t x; mp_exp_t e; char *s; diff --git a/tests/tpow.c b/tests/tpow.c index 72192bfcc..78fd3d041 100644 --- a/tests/tpow.c +++ b/tests/tpow.c @@ -26,11 +26,7 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -void check_pow_ui _PROTO ((void)); -void check_inexact _PROTO ((mp_prec_t)); -void special _PROTO ((void)); - -void +static void check_pow_ui (void) { mpfr_t a, b; @@ -42,9 +38,11 @@ check_pow_ui (void) mpfr_set_d (b, 0.6926773, GMP_RNDN); mpfr_pow_ui (a, b, 10, GMP_RNDN); mpfr_pow_ui (b, b, 10, GMP_RNDN); - if (mpfr_cmp (a, b)) { - fprintf (stderr, "Error for mpfr_pow_ui (b, b, ...)\n"); exit (1); - } + if (mpfr_cmp (a, b)) + { + fprintf (stderr, "Error for mpfr_pow_ui (b, b, ...)\n"); + exit (1); + } /* check large exponents */ mpfr_set_d (b, 1, GMP_RNDN); @@ -70,7 +68,7 @@ check_pow_ui (void) mpfr_clear (b); } -void +static void check_inexact (mp_prec_t p) { mpfr_t x, y, z, t; @@ -133,7 +131,7 @@ check_inexact (mp_prec_t p) mpfr_clear (t); } -void +static void special () { mpfr_t x, y, z, t; @@ -224,4 +222,3 @@ main (void) tests_end_mpfr (); return 0; } - diff --git a/tests/trandom.c b/tests/trandom.c index a1c5663d2..933f8524c 100644 --- a/tests/trandom.c +++ b/tests/trandom.c @@ -27,11 +27,7 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -void test_random _PROTO ((unsigned long, unsigned long, int)); -void test_random2 _PROTO ((unsigned long, unsigned long, int)); -void test_urandomb _PROTO ((unsigned long, unsigned long, int)); - -void +static void test_random (unsigned long nbtests, unsigned long prec, int verbose) { mpfr_t x; @@ -42,16 +38,22 @@ test_random (unsigned long nbtests, unsigned long prec, int verbose) size_tab = (nbtests >= 1000 ? nbtests / 50 : 20); tab = (int *) malloc (size_tab * sizeof(int)); - for (k = 0; k < size_tab; ++k) tab[k] = 0; + for (k = 0; k < size_tab; ++k) + tab[k] = 0; - for (k = 0; k < nbtests; k++) { - mpfr_random(x); - d = mpfr_get_d1 (x); av += d; var += d*d; - tab[(int)(size_tab * d)]++; - } + for (k = 0; k < nbtests; k++) + { + mpfr_random(x); + d = mpfr_get_d1 (x); av += d; var += d*d; + tab[(int)(size_tab * d)]++; + } mpfr_clear(x); - if (!verbose) { free(tab); return; } + if (!verbose) + { + free(tab); + return; + } av /= nbtests; var = (var /nbtests) - av*av; @@ -62,14 +64,16 @@ test_random (unsigned long nbtests, unsigned long prec, int verbose) printf("Repartition for random. Each integer should be close to %d.\n", (int)th); - for (k = 0; k < size_tab; k++) { - chi2 += (tab[k] - th) * (tab[k] - th) / th; - printf("%d ", tab[k]); - if (((k+1) & 7) == 0) printf("\n"); - } + for (k = 0; k < size_tab; k++) + { + chi2 += (tab[k] - th) * (tab[k] - th) / th; + printf("%d ", tab[k]); + if (((k+1) & 7) == 0) + printf("\n"); + } - printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", - size_tab - 1, chi2); + printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", + size_tab - 1, chi2); printf("\n"); @@ -77,12 +81,12 @@ test_random (unsigned long nbtests, unsigned long prec, int verbose) return; } -void +static void test_random2 (unsigned long nbtests, unsigned long prec, int verbose) { mpfr_t x; int *tab, size_tab, k, sh, xn; - double d, av = 0, var = 0, chi2 = 0, th; + double d, av = 0, var = 0, chi2 = 0, th; mpfr_init2 (x, prec); xn = 1 + (prec - 1) / mp_bits_per_limb; @@ -90,53 +94,61 @@ test_random2 (unsigned long nbtests, unsigned long prec, int verbose) size_tab = (nbtests >= 1000 ? nbtests / 50 : 20); tab = (int *) malloc (size_tab * sizeof(int)); - for (k = 0; k < size_tab; ++k) tab[k] = 0; - - for (k = 0; k < nbtests; k++) { - mpfr_random2 (x, xn, 0); - /* check that lower bits are zero */ - if (MPFR_MANT(x)[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE)) - { - fprintf (stderr, "Error: mpfr_random2() returns invalid numbers:\n"); - mpfr_print_binary (x); putchar ('\n'); - exit (1); - } - /* check that exponent is in correct range */ - if (mpfr_get_exp (x) != 0) - { - fprintf (stderr, "Error: mpfr_random2 (.., .., 0) does not return a 0 exponent:\n"); - mpfr_print_binary (x); putchar ('\n'); - exit (1); - } - d = mpfr_get_d1 (x); av += d; var += d*d; - if (d < 1) - tab[(int)(size_tab * d)]++; - } + for (k = 0; k < size_tab; ++k) + tab[k] = 0; + + for (k = 0; k < nbtests; k++) + { + mpfr_random2 (x, xn, 0); + /* check that lower bits are zero */ + if (MPFR_MANT(x)[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE)) + { + fprintf (stderr, "Error: mpfr_random2() returns invalid numbers:\n"); + mpfr_print_binary (x); putchar ('\n'); + exit (1); + } + /* check that exponent is in correct range */ + if (mpfr_get_exp (x) != 0) + { + fprintf (stderr, "Error: mpfr_random2 (.., .., 0) does not return a 0 exponent:\n"); + mpfr_print_binary (x); putchar ('\n'); + exit (1); + } + d = mpfr_get_d1 (x); av += d; var += d*d; + if (d < 1) + tab[(int)(size_tab * d)]++; + } mpfr_clear (x); - if (!verbose) { free(tab); return; } + if (!verbose) + { + free(tab); + return; + } - av /= nbtests; - var = (var /nbtests) - av*av; + av /= nbtests; + var = (var /nbtests) - av*av; - th = (double)nbtests / size_tab; - printf("Average = %.5f\nVariance = %.5f\n", av, var); - printf("Repartition for random2 (taking only values < 1 into account.\n"); + th = (double)nbtests / size_tab; + printf("Average = %.5f\nVariance = %.5f\n", av, var); + printf("Repartition for random2 (taking only values < 1 into account.\n"); - for (k = 0; k < size_tab; k++) { - chi2 += (tab[k] - th) * (tab[k] - th) / th; - printf("%d ", tab[k]); - if (((k+1) & 7) == 0) printf("\n"); - } + for (k = 0; k < size_tab; k++) + { + chi2 += (tab[k] - th) * (tab[k] - th) / th; + printf("%d ", tab[k]); + if (((k+1) & 7) == 0) + printf("\n"); + } - printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", - size_tab - 1, chi2); + printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", + size_tab - 1, chi2); - free(tab); + free(tab); return; } -void +static void test_urandomb (unsigned long nbtests, unsigned long prec, int verbose) { mpfr_t x; @@ -150,46 +162,54 @@ test_urandomb (unsigned long nbtests, unsigned long prec, int verbose) size_tab = (nbtests >= 1000 ? nbtests / 50 : 20); tab = (int *) malloc (size_tab * sizeof(int)); - for (k = 0; k < size_tab; ++k) tab[k] = 0; + for (k = 0; k < size_tab; ++k) + tab[k] = 0; - gmp_randinit (state, GMP_RAND_ALG_LC, 128); + gmp_randinit (state, GMP_RAND_ALG_LC, 128); gmp_randseed_ui (state, time(NULL)); - for (k = 0; k < nbtests; k++) { - mpfr_urandomb (x, state); - /* check that lower bits are zero */ - if (MPFR_MANT(x)[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE)) - { - fprintf (stderr, "Error: mpfr_urandomb() returns invalid numbers:\n"); - mpfr_print_binary (x); putchar ('\n'); - exit (1); - } - d = mpfr_get_d1 (x); av += d; var += d*d; - tab[(int)(size_tab * d)]++; - } + for (k = 0; k < nbtests; k++) + { + mpfr_urandomb (x, state); + /* check that lower bits are zero */ + if (MPFR_MANT(x)[0] & ((MP_LIMB_T_ONE << sh) - MP_LIMB_T_ONE)) + { + fprintf (stderr, "Error: mpfr_urandomb() returns invalid numbers:\n"); + mpfr_print_binary (x); putchar ('\n'); + exit (1); + } + d = mpfr_get_d1 (x); av += d; var += d*d; + tab[(int)(size_tab * d)]++; + } mpfr_clear(x); gmp_randclear(state); - if (!verbose) { free(tab); return; } + if (!verbose) + { + free(tab); + return; + } - av /= nbtests; - var = (var /nbtests) - av*av; + av /= nbtests; + var = (var /nbtests) - av*av; - th = (double)nbtests / size_tab; - printf("Average = %.5f\nVariance = %.5f\n", av, var); - printf("Repartition for urandomb. Each integer should be close to %d.\n", - (int)th); + th = (double)nbtests / size_tab; + printf("Average = %.5f\nVariance = %.5f\n", av, var); + printf("Repartition for urandomb. Each integer should be close to %d.\n", + (int)th); - for (k = 0; k < size_tab; k++) { - chi2 += (tab[k] - th) * (tab[k] - th) / th; - printf("%d ", tab[k]); - if (((k+1) & 7) == 0) printf("\n"); - } + for (k = 0; k < size_tab; k++) + { + chi2 += (tab[k] - th) * (tab[k] - th) / th; + printf("%d ", tab[k]); + if (((k+1) & 7) == 0) + printf("\n"); + } - printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", - size_tab - 1, chi2); + printf("\nChi2 statistics value (with %d degrees of freedom) : %.5f\n\n", + size_tab - 1, chi2); - free(tab); + free(tab); return; } @@ -200,7 +220,8 @@ main (int argc, char *argv[]) tests_start_mpfr (); - if (argc > 1) verbose = 1; + if (argc > 1) + verbose = 1; nbtests = 10000; if (argc > 1) @@ -210,7 +231,10 @@ main (int argc, char *argv[]) nbtests = a; } - if (argc <= 2) { prec = 1000; } else prec = atoi(argv[2]); + if (argc <= 2) + prec = 1000; + else + prec = atoi(argv[2]); test_random (nbtests, prec, verbose); test_random2 (nbtests, prec, verbose); @@ -219,7 +243,7 @@ main (int argc, char *argv[]) if (argc == 1) /* check also small precision */ { test_random (nbtests, 2, 0); - test_random2 (nbtests, 2, 0); + test_random2 (nbtests, 2, 0); test_urandomb (nbtests, 2, 0); } diff --git a/tests/tset_ld.c b/tests/tset_ld.c index c1b974c0f..88b49a0b5 100644 --- a/tests/tset_ld.c +++ b/tests/tset_ld.c @@ -27,13 +27,11 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void check_set_get _PROTO((long double, mpfr_t)); - /* checks that a long double converted to a mpfr (with precision >=113), then converted back to a long double gives the initial value, or in other words mpfr_get_ld(mpfr_set_ld(d)) = d. */ -void +static void check_set_get (long double d, mpfr_t x) { mp_rnd_t r; diff --git a/tests/tset_q.c b/tests/tset_q.c index a60b46b9d..7d6528f7b 100644 --- a/tests/tset_q.c +++ b/tests/tset_q.c @@ -1,6 +1,6 @@ /* Test file for mpfr_set_q. -Copyright 2000, 2001, 2002 Free Software Foundation, Inc. +Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -26,9 +26,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void check _PROTO((long int, long int, mp_rnd_t, double)); - -void +static void check (long int n, long int d, mp_rnd_t rnd, double y) { mpq_t q; @@ -46,11 +44,11 @@ check (long int n, long int d, mp_rnd_t rnd, double y) /* check values */ if (y != z) { - fprintf (stderr, "Error for q=%ld/%lu and rnd=%s\n", n, d, - mpfr_print_rnd_mode (rnd)); - fprintf (stderr, "correct result is %1.20e, mpfr_set_q gives %1.20e\n", - y, z); - exit (1); + fprintf (stderr, "Error for q=%ld/%lu and rnd=%s\n", n, d, + mpfr_print_rnd_mode (rnd)); + fprintf (stderr, "correct result is %1.20e, mpfr_set_q gives %1.20e\n", + y, z); + exit (1); } /* check inexact flag */ diff --git a/tests/tset_z.c b/tests/tset_z.c index f67a8ee45..0acb9af3a 100644 --- a/tests/tset_z.c +++ b/tests/tset_z.c @@ -1,6 +1,6 @@ /* Test file for mpfr_set_z. -Copyright 1999, 2001, 2002 Free Software Foundation, Inc. +Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -26,10 +26,7 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void check _PROTO((long, unsigned char)); -void check_large _PROTO((void)); - -void +static void check(long i, unsigned char rnd) { mpfr_t f; mpz_t z; @@ -37,14 +34,15 @@ check(long i, unsigned char rnd) mpfr_init2(f, 53); mpz_init(z); mpz_set_ui(z, i); mpfr_set_z(f, z, rnd); - if ((long)mpfr_get_d1 (f) != i) { - printf("Error in mpfr_set_z for i=%ld rnd_mode=%d\n",i,rnd); - exit(1); - } + if ((long)mpfr_get_d1 (f) != i) + { + printf("Error in mpfr_set_z for i=%ld rnd_mode=%d\n",i,rnd); + exit(1); + } mpfr_clear(f); mpz_clear(z); } -void +static void check_large (void) { mpz_t z; mpfr_t x,y; @@ -53,9 +51,11 @@ check_large (void) mpz_set_str(z, "77031627725494291259359895954016675357279104942148788042", 10); mpfr_set_z(x, z, GMP_RNDN); mpfr_set_str_raw(y, "0.1100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001001E186"); - if (mpfr_cmp(x,y)) { - fprintf(stderr, "Error in mpfr_set_z on large input\n"); exit(1); - } + if (mpfr_cmp(x,y)) + { + fprintf(stderr, "Error in mpfr_set_z on large input\n"); + exit(1); + } mpz_clear(z); mpfr_clear(x); mpfr_clear(y); } diff --git a/tests/tsqrt.c b/tests/tsqrt.c index aaadd6452..ce06d1f8e 100644 --- a/tests/tsqrt.c +++ b/tests/tsqrt.c @@ -32,15 +32,7 @@ MA 02111-1307, USA. */ int maxulp=0; -void check3 _PROTO((double, mp_rnd_t, double)); -void check4 _PROTO((double, mp_rnd_t, char *)); -void check24 _PROTO((float, mp_rnd_t, float)); -void check_float _PROTO((void)); -void special _PROTO((void)); -void check_inexact _PROTO((mp_prec_t)); -void check_nan _PROTO((void)); - -void +static void check3 (double a, mp_rnd_t rnd_mode, double Q) { mpfr_t q; @@ -63,7 +55,7 @@ check3 (double a, mp_rnd_t rnd_mode, double Q) mpfr_clear (q); } -void +static void check4 (double a, mp_rnd_t rnd_mode, char *Q) { mpfr_t q, res; @@ -72,7 +64,8 @@ check4 (double a, mp_rnd_t rnd_mode, char *Q) mpfr_set_d(q, a, rnd_mode); mpfr_sqrt(q, q, rnd_mode); mpfr_set_str(res, Q, 16, GMP_RNDN); - if (mpfr_cmp(q, res)) { + if (mpfr_cmp(q, res)) + { printf("mpfr_sqrt failed for a=%1.20e, rnd_mode=%s\n", a, mpfr_print_rnd_mode(rnd_mode)); printf("expected "); mpfr_print_binary(res); putchar('\n'); @@ -84,7 +77,7 @@ check4 (double a, mp_rnd_t rnd_mode, char *Q) mpfr_clear(q); } -void +static void check24 (float a, mp_rnd_t rnd_mode, float Q) { mpfr_t q; float Q2; @@ -104,7 +97,7 @@ check24 (float a, mp_rnd_t rnd_mode, float Q) /* the following examples come from the paper "Number-theoretic Test Generation for Directed Rounding" from Michael Parks, Table 3 */ -void +static void check_float (void) { float b = 8388608.0; /* 2^23 */ @@ -154,7 +147,7 @@ check_float (void) check24(b*10873622.0, GMP_RNDD, 9.550631e6); } -void +static void special (void) { mpfr_t x, z; @@ -203,11 +196,12 @@ special (void) mpfr_set_d (x, 1.0, GMP_RNDN); mpfr_set_d (z, -1.0, GMP_RNDN); mpfr_sqrt (z, x, GMP_RNDN); - if (mpfr_cmp_ui (z, 0) < 0) { - fprintf (stderr, "Error: square root of %e gives %e\n", - mpfr_get_d1 (x), mpfr_get_d1 (z)); - exit (1); - } + if (mpfr_cmp_ui (z, 0) < 0) + { + fprintf (stderr, "Error: square root of %e gives %e\n", + mpfr_get_d1 (x), mpfr_get_d1 (z)); + exit (1); + } mpfr_set_prec (x, 192); mpfr_set_prec (z, 160); @@ -220,7 +214,7 @@ special (void) mpfr_clear (z); } -void +static void check_inexact (mp_prec_t p) { mpfr_t x, y, z; @@ -257,7 +251,7 @@ check_inexact (mp_prec_t p) mpfr_clear (z); } -void +static void check_nan (void) { mpfr_t x, got; diff --git a/tests/tsqrt_ui.c b/tests/tsqrt_ui.c index 558515507..82e564c65 100644 --- a/tests/tsqrt_ui.c +++ b/tests/tsqrt_ui.c @@ -26,11 +26,9 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-test.h" -void check _PROTO((unsigned long, mp_rnd_t, double)); - int maxulp=0; -void +static void check (unsigned long a, mp_rnd_t rnd_mode, double Q) { mpfr_t q; diff --git a/tests/tsub.c b/tests/tsub.c index 8ecf858ea..27b0acafb 100644 --- a/tests/tsub.c +++ b/tests/tsub.c @@ -26,12 +26,7 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -void check_diverse _PROTO((void)); -void bug_ddefour _PROTO((void)); -void check_two_sum _PROTO((mp_prec_t)); -void check_inexact _PROTO((void)); - -void +static void check_diverse (void) { mpfr_t x, y, z; @@ -252,7 +247,7 @@ check_diverse (void) mpfr_clear (z); } -void +static void bug_ddefour(void) { mpfr_t ex, ex1, ex2, ex3, tot, tot1; @@ -289,7 +284,7 @@ bug_ddefour(void) } /* if u = o(x-y), v = o(u-x), w = o(v+y), then x-y = u-w */ -void +static void check_two_sum (mp_prec_t p) { mpfr_t x, y, u, v, w; @@ -334,7 +329,7 @@ check_two_sum (mp_prec_t p) #define MAX_PREC 100 -void +static void check_inexact (void) { mpfr_t x, y, z, u; diff --git a/tests/tsub_ui.c b/tests/tsub_ui.c index 4b7b2aaee..c6e7e5998 100644 --- a/tests/tsub_ui.c +++ b/tests/tsub_ui.c @@ -52,7 +52,7 @@ check3 (double x, unsigned long y, mp_rnd_t rnd_mode, double z1) printf ("mpfr_sub_ui failed for x=%1.20e y=%lu with rnd_mode=%s\n", x, y, mpfr_print_rnd_mode (rnd_mode)); exit (1); - } + } mpfr_clear (xx); mpfr_clear (zz); } diff --git a/tests/tui_div.c b/tests/tui_div.c index 033d95d3b..773638689 100644 --- a/tests/tui_div.c +++ b/tests/tui_div.c @@ -28,13 +28,9 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" #include "mpfr-test.h" -void check _PROTO((unsigned long, double, mp_rnd_t, double)); -void check_inexact _PROTO((void)); -void check_nan _PROTO((void)); - /* checks that y/x gives the same results in double and with mpfr with 53 bits of precision */ -void +static void check (unsigned long y, double x, mp_rnd_t rnd_mode, double z1) { double z2; @@ -51,12 +47,12 @@ check (unsigned long y, double x, mp_rnd_t rnd_mode, double z1) printf ("mpfr_ui_div failed for y=%lu x=%1.20e with rnd_mode=%s\n", y, x, mpfr_print_rnd_mode (rnd_mode)); exit (1); - } + } mpfr_clear (xx); mpfr_clear (zz); } -void +static void check_inexact (void) { mpfr_t x, y, z; @@ -108,7 +104,8 @@ check_inexact (void) mpfr_clear (z); } -void +#if 0 +static void check_nan (void) { mpfr_t d, q; @@ -145,6 +142,7 @@ check_nan (void) mpfr_clear (d); mpfr_clear (q); } +#endif int main (int argc, char *argv[]) |