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

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

1.1       ohara       1: /* Test mpf_sub.
                      2:
                      3: Copyright 1996, 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:   mp_size_t size;
                     37:   mp_exp_t exp;
                     38:   int reps = 100000;
                     39:   int i;
                     40:   mpf_t u, v, w, wref;
                     41:   mp_size_t bprec = 100;
                     42:   mpf_t rerr, max_rerr, limit_rerr;
                     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_set_ui (limit_rerr, 1);
                     56:   mpf_div_2exp (limit_rerr, limit_rerr, bprec);
                     57: #if VERBOSE
                     58:   mpf_dump (limit_rerr);
                     59: #endif
                     60:   mpf_init (rerr);
                     61:   mpf_init_set_ui (max_rerr, 0);
                     62:
                     63:   mpf_init (u);
                     64:   mpf_init (v);
                     65:   mpf_init (w);
                     66:   mpf_init (wref);
                     67:   for (i = 0; i < reps; i++)
                     68:     {
                     69:       size = urandom () % (2 * SIZE) - SIZE;
                     70:       exp = urandom () % SIZE;
                     71:       mpf_random2 (u, size, exp);
                     72:
                     73:       size = urandom () % (2 * SIZE) - SIZE;
                     74:       exp = urandom () % SIZE;
                     75:       mpf_random2 (v, size, exp);
                     76:
                     77:       if ((urandom () & 1) != 0)
                     78:        mpf_add_ui (u, v, 1);
                     79:       else if ((urandom () & 1) != 0)
                     80:        mpf_sub_ui (u, v, 1);
                     81:
                     82:       mpf_sub (w, u, v);
                     83:       refmpf_sub (wref, u, v);
                     84:
                     85:       mpf_reldiff (rerr, w, wref);
                     86:       if (mpf_cmp (rerr, max_rerr) > 0)
                     87:        {
                     88:          mpf_set (max_rerr, rerr);
                     89: #if VERBOSE
                     90:          mpf_dump (max_rerr);
                     91: #endif
                     92:          if (mpf_cmp (rerr, limit_rerr) > 0)
                     93:            {
                     94:              printf ("ERROR after %d tests\n", i);
                     95:              printf ("   u = "); mpf_dump (u);
                     96:              printf ("   v = "); mpf_dump (v);
                     97:              printf ("wref = "); mpf_dump (wref);
                     98:              printf ("   w = "); mpf_dump (w);
                     99:              abort ();
                    100:            }
                    101:        }
                    102:     }
                    103:
                    104:   mpf_clear (limit_rerr);
                    105:   mpf_clear (rerr);
                    106:   mpf_clear (max_rerr);
                    107:
                    108:   mpf_clear (u);
                    109:   mpf_clear (v);
                    110:   mpf_clear (w);
                    111:   mpf_clear (wref);
                    112:
                    113:   tests_end ();
                    114:   exit (0);
                    115: }

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