[BACK]Return to t-dm2exp.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / tests / mpf

Annotation of OpenXM_contrib/gmp/tests/mpf/t-dm2exp.c, Revision 1.1.1.1

1.1       ohara       1: /* Test mpf_div, mpf_div_2exp, mpf_mul_2exp.
                      2:
                      3: Copyright 1996, 2000, 2001 Free Software Foundation, Inc.
                      4:
                      5: This file is part of the GNU MP Library.
                      6:
                      7: The GNU MP Library is free software; you can redistribute it and/or modify
                      8: it under the terms of the GNU Lesser General Public License as published by
                      9: the Free Software Foundation; either version 2.1 of the License, or (at your
                     10: option) any later version.
                     11:
                     12: The GNU MP Library is distributed in the hope that it will be useful, but
                     13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
                     15: License for more details.
                     16:
                     17: You should have received a copy of the GNU Lesser General Public License
                     18: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     20: MA 02111-1307, USA. */
                     21:
                     22: #include <stdio.h>
                     23: #include <stdlib.h>
                     24:
                     25: #include "gmp.h"
                     26: #include "gmp-impl.h"
                     27: #include "tests.h"
                     28:
                     29: #ifndef SIZE
                     30: #define SIZE 16
                     31: #endif
                     32:
                     33: int
                     34: main (int argc, char **argv)
                     35: {
                     36:   int reps = 100000;
                     37:   int i;
                     38:   mpf_t u, v, w1, w2, w3;
                     39:   mp_size_t bprec = 100;
                     40:   mpf_t rerr, limit_rerr;
                     41:   mp_size_t un;
                     42:   mp_exp_t ue;
                     43:
                     44:   tests_start ();
                     45:
                     46:   if (argc > 1)
                     47:     {
                     48:       reps = strtol (argv[1], 0, 0);
                     49:       if (argc > 2)
                     50:        bprec = strtol (argv[2], 0, 0);
                     51:     }
                     52:
                     53:   mpf_set_default_prec (bprec);
                     54:
                     55:   mpf_init (rerr);
                     56:   mpf_init (limit_rerr);
                     57:
                     58:   mpf_init (u);
                     59:   mpf_init (v);
                     60:   mpf_init (w1);
                     61:   mpf_init (w2);
                     62:   mpf_init (w3);
                     63:
                     64:   for (i = 0; i < reps; i++)
                     65:     {
                     66:       unsigned long int res_prec;
                     67:       unsigned long int pow2;
                     68:
                     69:       res_prec = urandom () % (bprec + 100);
                     70:       mpf_set_prec (w1, res_prec);
                     71:       mpf_set_prec (w2, res_prec);
                     72:       mpf_set_prec (w3, res_prec);
                     73:
                     74:       mpf_set_ui (limit_rerr, 1);
                     75:       mpf_div_2exp (limit_rerr, limit_rerr, res_prec);
                     76:
                     77:       pow2 = urandom () % 0x10000;
                     78:       mpf_set_ui (v, 1);
                     79:       mpf_mul_2exp (v, v, pow2);
                     80:
                     81:       un = urandom () % (2 * SIZE) - SIZE;
                     82:       ue = urandom () % SIZE;
                     83:       mpf_random2 (u, un, ue);
                     84:
                     85:       mpf_div_2exp (w1, u, pow2);
                     86:       mpf_div (w2, u, v);
                     87:       mpf_reldiff (rerr, w1, w2);
                     88:       if (mpf_cmp (rerr, limit_rerr) > 0)
                     89:        {
                     90:          printf ("ERROR in mpf_div or mpf_div_2exp after %d tests\n", i);
                     91:          printf ("   u = "); mpf_dump (u);
                     92:          printf ("   v = "); mpf_dump (v);
                     93:          printf ("  w1 = "); mpf_dump (w1);
                     94:          printf ("  w2 = "); mpf_dump (w2);
                     95:          abort ();
                     96:        }
                     97:       mpf_mul_2exp (w3, w1, pow2);
                     98:       mpf_reldiff (rerr, u, w3);
                     99:       if (mpf_cmp (rerr, limit_rerr) > 0)
                    100:        {
                    101:          printf ("ERROR in mpf_mul_2exp after %d tests\n", i);
                    102:          printf ("   u = "); mpf_dump (u);
                    103:          printf ("   v = "); mpf_dump (v);
                    104:          printf ("  w1 = "); mpf_dump (w1);
                    105:          printf ("  w3 = "); mpf_dump (w3);
                    106:          abort ();
                    107:        }
                    108:     }
                    109:
                    110:   mpf_clear (rerr);
                    111:   mpf_clear (limit_rerr);
                    112:
                    113:   mpf_clear (u);
                    114:   mpf_clear (v);
                    115:   mpf_clear (w1);
                    116:   mpf_clear (w2);
                    117:   mpf_clear (w3);
                    118:
                    119:   tests_end ();
                    120:   exit (0);
                    121: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>