1 1.1 mrg /* Test mpf_add. 2 1.1 mrg 3 1.1 mrg Copyright 1996, 2001 Free Software Foundation, Inc. 4 1.1 mrg 5 1.1.1.2 mrg This file is part of the GNU MP Library test suite. 6 1.1 mrg 7 1.1.1.2 mrg The GNU MP Library test suite is free software; you can redistribute it 8 1.1.1.2 mrg and/or modify it under the terms of the GNU General Public License as 9 1.1.1.2 mrg published by the Free Software Foundation; either version 3 of the License, 10 1.1.1.2 mrg or (at your option) any later version. 11 1.1.1.2 mrg 12 1.1.1.2 mrg The GNU MP Library test suite is distributed in the hope that it will be 13 1.1.1.2 mrg useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1.1.2 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15 1.1.1.2 mrg Public License for more details. 16 1.1 mrg 17 1.1.1.2 mrg You should have received a copy of the GNU General Public License along with 18 1.1.1.3 mrg the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ 19 1.1 mrg 20 1.1 mrg #include <stdio.h> 21 1.1 mrg #include <stdlib.h> 22 1.1 mrg 23 1.1 mrg #include "gmp-impl.h" 24 1.1 mrg #include "tests.h" 25 1.1 mrg 26 1.1 mrg #ifndef SIZE 27 1.1 mrg #define SIZE 16 28 1.1 mrg #endif 29 1.1 mrg 30 1.1 mrg int 31 1.1 mrg main (int argc, char **argv) 32 1.1 mrg { 33 1.1 mrg mp_size_t size; 34 1.1 mrg mp_exp_t exp; 35 1.1 mrg int reps = 20000; 36 1.1 mrg int i; 37 1.1 mrg mpf_t u, v, w, wref; 38 1.1 mrg mp_size_t bprec = 100; 39 1.1 mrg mpf_t rerr, max_rerr, limit_rerr; 40 1.1 mrg 41 1.1 mrg tests_start (); 42 1.1 mrg 43 1.1 mrg if (argc > 1) 44 1.1 mrg { 45 1.1 mrg reps = strtol (argv[1], 0, 0); 46 1.1 mrg if (argc > 2) 47 1.1 mrg bprec = strtol (argv[2], 0, 0); 48 1.1 mrg } 49 1.1 mrg 50 1.1 mrg mpf_set_default_prec (bprec); 51 1.1 mrg 52 1.1 mrg mpf_init_set_ui (limit_rerr, 1); 53 1.1 mrg mpf_div_2exp (limit_rerr, limit_rerr, bprec); 54 1.1 mrg #if VERBOSE 55 1.1 mrg mpf_dump (limit_rerr); 56 1.1 mrg #endif 57 1.1 mrg mpf_init (rerr); 58 1.1 mrg mpf_init_set_ui (max_rerr, 0); 59 1.1 mrg 60 1.1 mrg mpf_init (u); 61 1.1 mrg mpf_init (v); 62 1.1 mrg mpf_init (w); 63 1.1 mrg mpf_init (wref); 64 1.1 mrg for (i = 0; i < reps; i++) 65 1.1 mrg { 66 1.1 mrg size = urandom () % (2 * SIZE) - SIZE; 67 1.1 mrg exp = urandom () % SIZE; 68 1.1 mrg mpf_random2 (u, size, exp); 69 1.1 mrg 70 1.1 mrg size = urandom () % (2 * SIZE) - SIZE; 71 1.1 mrg exp = urandom () % SIZE; 72 1.1 mrg mpf_random2 (v, size, exp); 73 1.1 mrg 74 1.1 mrg mpf_add (w, u, v); 75 1.1 mrg refmpf_add (wref, u, v); 76 1.1 mrg 77 1.1 mrg mpf_reldiff (rerr, w, wref); 78 1.1 mrg if (mpf_cmp (rerr, max_rerr) > 0) 79 1.1 mrg { 80 1.1 mrg mpf_set (max_rerr, rerr); 81 1.1 mrg #if VERBOSE 82 1.1 mrg mpf_dump (max_rerr); 83 1.1 mrg #endif 84 1.1 mrg if (mpf_cmp (rerr, limit_rerr) > 0) 85 1.1 mrg { 86 1.1 mrg printf ("ERROR after %d tests\n", i); 87 1.1 mrg printf (" u = "); mpf_dump (u); 88 1.1 mrg printf (" v = "); mpf_dump (v); 89 1.1 mrg printf ("wref = "); mpf_dump (wref); 90 1.1 mrg printf (" w = "); mpf_dump (w); 91 1.1 mrg abort (); 92 1.1 mrg } 93 1.1 mrg } 94 1.1 mrg } 95 1.1 mrg 96 1.1 mrg mpf_clear (limit_rerr); 97 1.1 mrg mpf_clear (rerr); 98 1.1 mrg mpf_clear (max_rerr); 99 1.1 mrg 100 1.1 mrg mpf_clear (u); 101 1.1 mrg mpf_clear (v); 102 1.1 mrg mpf_clear (w); 103 1.1 mrg mpf_clear (wref); 104 1.1 mrg 105 1.1 mrg tests_end (); 106 1.1 mrg exit (0); 107 1.1 mrg } 108