Annotation of OpenXM_contrib/gmp/tests/mpf/reuse.c, Revision 1.1
1.1 ! ohara 1: /* Test that routines allow reusing a source variable as destination.
! 2:
! 3: Copyright 1996, 2000, 2001, 2002 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: #include <string.h>
! 25:
! 26: #include "gmp.h"
! 27: #include "gmp-impl.h"
! 28: #include "tests.h"
! 29:
! 30: #if __GMP_LIBGMP_DLL
! 31:
! 32: /* FIXME: When linking to a DLL libgmp, mpf_add etc can't be used as
! 33: initializers for global variables because they're effectively global
! 34: variables (function pointers) themselves. Perhaps calling a test
! 35: function successively with mpf_add etc would be better. */
! 36:
! 37: int
! 38: main (void)
! 39: {
! 40: printf ("Test suppressed for windows DLL\n");
! 41: exit (0);
! 42: }
! 43:
! 44:
! 45: #else /* ! DLL_EXPORT */
! 46:
! 47: #ifndef SIZE
! 48: #define SIZE 16
! 49: #endif
! 50:
! 51: #ifndef EXPO
! 52: #define EXPO 32
! 53: #endif
! 54:
! 55: void dump_abort _PROTO ((char *name, mpf_t res1, mpf_t res2));
! 56:
! 57: typedef void (*dss_func) _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
! 58:
! 59: dss_func dss_funcs[] =
! 60: {
! 61: mpf_div, mpf_add, mpf_mul, mpf_sub,
! 62: };
! 63:
! 64: char *dss_func_names[] =
! 65: {
! 66: "mpf_div", "mpf_add", "mpf_mul", "mpf_sub",
! 67: };
! 68:
! 69: typedef void (*dsi_func) _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
! 70:
! 71: dsi_func dsi_funcs[] =
! 72: {
! 73: mpf_div_ui, mpf_add_ui, mpf_mul_ui, mpf_sub_ui,
! 74: mpf_mul_2exp, mpf_div_2exp
! 75: };
! 76:
! 77: char *dsi_func_names[] =
! 78: {
! 79: "mpf_div_ui", "mpf_add_ui", "mpf_mul_ui", "mpf_sub_ui",
! 80: "mpf_mul_2exp", "mpf_div_2exp"
! 81: };
! 82:
! 83: typedef void (*dis_func) _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
! 84:
! 85: dis_func dis_funcs[] =
! 86: {
! 87: mpf_ui_div, mpf_ui_sub,
! 88: };
! 89:
! 90: char *dis_func_names[] =
! 91: {
! 92: "mpf_ui_div", "mpf_ui_sub",
! 93: };
! 94:
! 95: int
! 96: main (int argc, char **argv)
! 97: {
! 98: int i;
! 99: int pass, reps = 10000;
! 100: mpf_t in1, in2, out1;
! 101: unsigned long int in1i, in2i;
! 102: mpf_t res1, res2, res3;
! 103: mp_size_t bprec = 100;
! 104:
! 105: tests_start ();
! 106:
! 107: if (argc > 1)
! 108: {
! 109: reps = strtol (argv[1], 0, 0);
! 110: if (argc > 2)
! 111: bprec = strtol (argv[2], 0, 0);
! 112: }
! 113:
! 114: mpf_set_default_prec (bprec);
! 115:
! 116: mpf_init (in1);
! 117: mpf_init (in2);
! 118: mpf_init (out1);
! 119: mpf_init (res1);
! 120: mpf_init (res2);
! 121: mpf_init (res3);
! 122:
! 123: for (pass = 1; pass <= reps; pass++)
! 124: {
! 125: mpf_random2 (in1, urandom () % SIZE - SIZE/2, urandom () % EXPO);
! 126: mpf_random2 (in2, urandom () % SIZE - SIZE/2, urandom () % EXPO);
! 127:
! 128: for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
! 129: {
! 130: /* Don't divide by 0. */
! 131: if (i == 0 && mpf_cmp_ui (in2, 0) == 0)
! 132: continue;
! 133:
! 134: (dss_funcs[i]) (res1, in1, in2);
! 135:
! 136: mpf_set (out1, in1);
! 137: (dss_funcs[i]) (out1, out1, in2);
! 138: mpf_set (res2, out1);
! 139:
! 140: mpf_set (out1, in2);
! 141: (dss_funcs[i]) (out1, in1, out1);
! 142: mpf_set (res3, out1);
! 143:
! 144: if (mpf_cmp (res1, res2) != 0)
! 145: dump_abort (dss_func_names[i], res1, res2);
! 146: if (mpf_cmp (res1, res3) != 0)
! 147: dump_abort (dss_func_names[i], res1, res3);
! 148: }
! 149:
! 150: in2i = urandom ();
! 151: for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++)
! 152: {
! 153: /* Don't divide by 0. */
! 154: if (strcmp (dsi_func_names[i], "mpf_div_ui") == 0 && in2i == 0)
! 155: continue;
! 156:
! 157: (dsi_funcs[i]) (res1, in1, in2i);
! 158:
! 159: mpf_set (out1, in1);
! 160: (dsi_funcs[i]) (out1, out1, in2i);
! 161: mpf_set (res2, out1);
! 162:
! 163: if (mpf_cmp (res1, res2) != 0)
! 164: dump_abort (dsi_func_names[i], res1, res2);
! 165: }
! 166:
! 167: in1i = urandom ();
! 168: for (i = 0; i < sizeof (dis_funcs) / sizeof (dis_func); i++)
! 169: {
! 170: /* Don't divide by 0. */
! 171: if (strcmp (dis_func_names[i], "mpf_ui_div") == 0
! 172: && mpf_cmp_ui (in2, 0) == 0)
! 173: continue;
! 174:
! 175: (dis_funcs[i]) (res1, in1i, in2);
! 176:
! 177: mpf_set (out1, in2);
! 178: (dis_funcs[i]) (out1, in1i, out1);
! 179: mpf_set (res2, out1);
! 180:
! 181: if (mpf_cmp (res1, res2) != 0)
! 182: dump_abort (dis_func_names[i], res1, res2);
! 183: }
! 184:
! 185: }
! 186:
! 187: mpf_clear (in1);
! 188: mpf_clear (in2);
! 189: mpf_clear (out1);
! 190: mpf_clear (res1);
! 191: mpf_clear (res2);
! 192: mpf_clear (res3);
! 193:
! 194: tests_end ();
! 195: exit (0);
! 196: }
! 197:
! 198: void
! 199: dump_abort (char *name, mpf_t res1, mpf_t res2)
! 200: {
! 201: printf ("failure in %s:\n", name);
! 202: mpf_dump (res1);
! 203: mpf_dump (res2);
! 204: abort ();
! 205: }
! 206:
! 207: #if 0
! 208: void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr));
! 209: void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr));
! 210: void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr));
! 211: #endif
! 212:
! 213: #endif /* ! DLL_EXPORT */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>