[BACK]Return to reuse.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpz / tests

Annotation of OpenXM_contrib/gmp/mpz/tests/reuse.c, Revision 1.1.1.2

1.1.1.2 ! maekawa     1: /* Test that routines allow reusing a source variable as destination.
        !             2:
        !             3:    Test all relevant functions except:
        !             4:        mpz_bin_ui
        !             5:        mpz_nextprime
        !             6:        mpz_mul_si
        !             7:        mpz_addmul_ui (should this really allow a+=a*c?)
        !             8: Copyright (C) 1996, 1999, 2000 Free Software Foundation, Inc.
        !             9:
        !            10: This file is part of the GNU MP Library.
        !            11:
        !            12: The GNU MP Library is free software; you can redistribute it and/or modify
        !            13: it under the terms of the GNU Lesser General Public License as published by
        !            14: the Free Software Foundation; either version 2.1 of the License, or (at your
        !            15: option) any later version.
        !            16:
        !            17: The GNU MP Library is distributed in the hope that it will be useful, but
        !            18: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            19: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
        !            20: License for more details.
        !            21:
        !            22: You should have received a copy of the GNU Lesser General Public License
        !            23: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
        !            24: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
        !            25: MA 02111-1307, USA. */
        !            26:
1.1       maekawa    27:
                     28: #include <stdio.h>
                     29: #include "gmp.h"
                     30: #include "gmp-impl.h"
                     31: #include "urandom.h"
                     32:
                     33: #ifndef SIZE
1.1.1.2 ! maekawa    34: #define SIZE 50
1.1       maekawa    35: #endif
                     36:
1.1.1.2 ! maekawa    37: typedef void (*dss_func) _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
        !            38: typedef void (*dsi_func) _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
        !            39: typedef unsigned long int (*dsi_div_func) _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
        !            40: typedef unsigned long int (*ddsi_div_func) _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
        !            41: typedef void (*ddss_div_func) _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
        !            42: typedef void (*ds_func) _PROTO ((mpz_ptr, mpz_srcptr));
        !            43:
        !            44:
        !            45: void
1.1       maekawa    46: #if __STDC__
1.1.1.2 ! maekawa    47: mpz_xinvert (mpz_ptr r, mpz_srcptr a, mpz_srcptr b)
1.1       maekawa    48: #else
1.1.1.2 ! maekawa    49: mpz_xinvert (r, a, b)
        !            50:      mpz_ptr    r;
        !            51:      mpz_srcptr a;
        !            52:      mpz_srcptr b;
1.1       maekawa    53: #endif
1.1.1.2 ! maekawa    54: {
        !            55:   int res;
        !            56:   res = mpz_invert (r, a, b);
        !            57:   if (res == 0)
        !            58:     mpz_set_ui (r, 0);
        !            59: }
1.1       maekawa    60:
                     61: dss_func dss_funcs[] =
                     62: {
1.1.1.2 ! maekawa    63:   mpz_add, mpz_sub, mpz_mul,
        !            64:   mpz_cdiv_q, mpz_cdiv_r, mpz_fdiv_q, mpz_fdiv_r, mpz_tdiv_q, mpz_tdiv_r,
        !            65:   mpz_xinvert,
        !            66:   mpz_gcd, mpz_lcm, mpz_and, mpz_ior, mpz_xor
1.1       maekawa    67: };
                     68: char *dss_func_names[] =
                     69: {
1.1.1.2 ! maekawa    70:   "mpz_add", "mpz_sub", "mpz_mul",
        !            71:   "mpz_cdiv_q", "mpz_cdiv_r", "mpz_fdiv_q", "mpz_fdiv_r", "mpz_tdiv_q", "mpz_tdiv_r",
        !            72:   "mpz_xinvert",
        !            73:   "mpz_gcd", "mpz_lcm", "mpz_and", "mpz_ior", "mpz_xor"
        !            74: };
        !            75: char dss_func_division[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
        !            76:
        !            77: dsi_func dsi_funcs[] =
        !            78: {
        !            79:   /* Don't change order here without changing the code in main(). */
        !            80:   mpz_add_ui, mpz_mul_ui, mpz_sub_ui,
        !            81:   mpz_fdiv_q_2exp, mpz_fdiv_r_2exp,
        !            82:   mpz_tdiv_q_2exp, mpz_tdiv_r_2exp,
        !            83:   mpz_mul_2exp,
        !            84:   mpz_pow_ui
        !            85: };
        !            86: char *dsi_func_names[] =
        !            87: {
        !            88:   "mpz_add_ui", "mpz_mul_ui", "mpz_sub_ui",
        !            89:   "mpz_fdiv_q_2exp", "mpz_fdiv_r_2exp",
        !            90:   "mpz_tdiv_q_2exp", "mpz_tdiv_r_2exp",
        !            91:   "mpz_mul_2exp",
        !            92:   "mpz_pow_ui"
1.1       maekawa    93: };
                     94:
1.1.1.2 ! maekawa    95: dsi_div_func dsi_div_funcs[] =
        !            96: {
        !            97:   mpz_cdiv_q_ui, mpz_cdiv_r_ui,
        !            98:   mpz_fdiv_q_ui, mpz_fdiv_r_ui,
        !            99:   mpz_tdiv_q_ui, mpz_tdiv_r_ui
        !           100: };
        !           101: char *dsi_div_func_names[] =
        !           102: {
        !           103:   "mpz_cdiv_q_ui", "mpz_cdiv_r_ui",
        !           104:   "mpz_fdiv_q_ui", "mpz_fdiv_r_ui",
        !           105:   "mpz_tdiv_q_ui", "mpz_tdiv_r_ui"
        !           106: };
        !           107:
        !           108: ddsi_div_func ddsi_div_funcs[] =
        !           109: {
        !           110:   mpz_cdiv_qr_ui,
        !           111:   mpz_fdiv_qr_ui,
        !           112:   mpz_tdiv_qr_ui
        !           113: };
        !           114: char *ddsi_div_func_names[] =
        !           115: {
        !           116:   "mpz_cdiv_qr_ui",
        !           117:   "mpz_fdiv_qr_ui",
        !           118:   "mpz_tdiv_qr_ui"
        !           119: };
1.1       maekawa   120:
1.1.1.2 ! maekawa   121: ddss_div_func ddss_div_funcs[] =
        !           122: {
        !           123:   mpz_cdiv_qr,
        !           124:   mpz_fdiv_qr,
        !           125:   mpz_tdiv_qr
        !           126: };
        !           127: char *ddss_div_func_names[] =
        !           128: {
        !           129:   "mpz_cdiv_qr",
        !           130:   "mpz_fdiv_qr",
        !           131:   "mpz_tdiv_qr"
        !           132: };
        !           133:
        !           134: ds_func ds_funcs[] =
        !           135: {
        !           136:   mpz_abs, mpz_com, mpz_neg, mpz_sqrt
        !           137: };
        !           138: char *ds_func_names[] =
        !           139: {
        !           140:   "mpz_abs", "mpz_com", "mpz_neg", "mpz_sqrt"
        !           141: };
        !           142:
        !           143:
        !           144: /* Really use `defined (__STDC__)' here; we want it to be true for Sun C */
        !           145: #if defined (__STDC__) || defined (__cplusplus)
        !           146: #define FAIL(class,indx,op1,op2,op3) \
        !           147:   do {                                                                 \
        !           148:   class##_funcs[indx] = 0;                                             \
        !           149:   dump_abort (class##_func_names[indx], op1, op2, op3);                        \
        !           150:   failures++;                                                          \
        !           151:   } while (0)
        !           152: #else
        !           153: #define FAIL(class,indx,op1,op2,op3) \
        !           154:   do {                                                                 \
        !           155:   class/**/_funcs[indx] = 0;                                           \
        !           156:   dump_abort (class/**/_func_names[indx], op1, op2, op3);              \
        !           157:   failures++;                                                          \
        !           158:   } while (0)
1.1       maekawa   159: #endif
                    160:
1.1.1.2 ! maekawa   161:
1.1       maekawa   162: main (argc, argv)
                    163:      int argc;
                    164:      char **argv;
                    165: {
                    166:   int i;
1.1.1.2 ! maekawa   167:   int pass, reps = 1000;
        !           168:   mpz_t in1, in2, in3;
        !           169:   unsigned long int in2i;
1.1       maekawa   170:   mpz_t res1, res2, res3;
1.1.1.2 ! maekawa   171:   mpz_t ref1, ref2, ref3;
        !           172:   mpz_t t;
        !           173:   unsigned long int r1, r2;
        !           174:   long failures = 0;
1.1       maekawa   175:
                    176:   if (argc == 2)
                    177:      reps = atoi (argv[1]);
                    178:
                    179:   mpz_init (in1);
                    180:   mpz_init (in2);
1.1.1.2 ! maekawa   181:   mpz_init (in3);
        !           182:   mpz_init (ref1);
        !           183:   mpz_init (ref2);
        !           184:   mpz_init (ref3);
1.1       maekawa   185:   mpz_init (res1);
                    186:   mpz_init (res2);
                    187:   mpz_init (res3);
1.1.1.2 ! maekawa   188:   mpz_init (t);
1.1       maekawa   189:
                    190:   for (pass = 1; pass <= reps; pass++)
                    191:     {
1.1.1.2 ! maekawa   192:       mpz_random2 (in1, urandom () % (2 * SIZE) - SIZE);
        !           193:       mpz_random2 (in2, urandom () % (2 * SIZE) - SIZE);
        !           194:       mpz_random2 (in3, urandom () % (2 * SIZE) - SIZE);
1.1       maekawa   195:
                    196:       for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
                    197:        {
1.1.1.2 ! maekawa   198:          if (dss_funcs[i] == 0)
        !           199:            continue;
        !           200:          if (dss_func_division[i] && mpz_sgn (in2) == 0)
1.1       maekawa   201:            continue;
                    202:
1.1.1.2 ! maekawa   203:          (dss_funcs[i]) (ref1, in1, in2);
1.1       maekawa   204:
1.1.1.2 ! maekawa   205:          mpz_set (res1, in1);
        !           206:          (dss_funcs[i]) (res1, res1, in2);
        !           207:          if (mpz_cmp (ref1, res1) != 0)
        !           208:            FAIL (dss, i, in1, in2, NULL);
        !           209:
        !           210:          mpz_set (res1, in2);
        !           211:          (dss_funcs[i]) (res1, in1, res1);
        !           212:          if (mpz_cmp (ref1, res1) != 0)
        !           213:            FAIL (dss, i, in1, in2, NULL);
        !           214:        }
        !           215:
        !           216:       for (i = 0; i < sizeof (ddss_div_funcs) / sizeof (ddss_div_func); i++)
        !           217:        {
        !           218:          if (ddss_div_funcs[i] == 0)
        !           219:            continue;
        !           220:          if (mpz_sgn (in2) == 0)
        !           221:            continue;
        !           222:
        !           223:          (ddss_div_funcs[i]) (ref1, ref2, in1, in2);
        !           224:
        !           225:          mpz_set (res1, in1);
        !           226:          (ddss_div_funcs[i]) (res1, res2, res1, in2);
        !           227:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0)
        !           228:            FAIL (ddss_div, i, in1, in2, NULL);
        !           229:
        !           230:          mpz_set (res2, in1);
        !           231:          (ddss_div_funcs[i]) (res1, res2, res2, in2);
        !           232:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0)
        !           233:            FAIL (ddss_div, i, in1, in2, NULL);
        !           234:
        !           235:          mpz_set (res1, in2);
        !           236:          (ddss_div_funcs[i]) (res1, res2, in1, res1);
        !           237:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0)
        !           238:            FAIL (ddss_div, i, in1, in2, NULL);
        !           239:
        !           240:          mpz_set (res2, in2);
        !           241:          (ddss_div_funcs[i]) (res1, res2, in1, res2);
        !           242:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0)
        !           243:            FAIL (ddss_div, i, in1, in2, NULL);
        !           244:        }
        !           245:
        !           246:       for (i = 0; i < sizeof (ds_funcs) / sizeof (ds_func); i++)
        !           247:        {
        !           248:          if (ds_funcs[i] == 0)
        !           249:            continue;
        !           250:          if (strcmp (ds_func_names[i], "mpz_sqrt") == 0
        !           251:              && mpz_sgn (in1) < 0)
        !           252:            continue;
1.1       maekawa   253:
1.1.1.2 ! maekawa   254:          (ds_funcs[i]) (ref1, in1);
1.1       maekawa   255:
1.1.1.2 ! maekawa   256:          mpz_set (res1, in1);
        !           257:          (ds_funcs[i]) (res1, res1);
        !           258:          if (mpz_cmp (ref1, res1) != 0)
        !           259:            FAIL (ds, i, in1, in2, NULL);
1.1       maekawa   260:        }
1.1.1.2 ! maekawa   261:
        !           262:       in2i = mpz_get_ui (in2);
        !           263:
        !           264:       for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++)
        !           265:        {
        !           266:          if (dsi_funcs[i] == 0)
        !           267:            continue;
        !           268:          if (strcmp (dsi_func_names[i], "mpz_fdiv_q_2exp") == 0)
        !           269:            /* Limit exponent to something reasonable for the division
        !           270:               functions.  Without this, we'd  normally shift things off
        !           271:               the end and just generate the trivial values 1, 0, -1.  */
        !           272:            in2i %= 0x1000;
        !           273:          if (strcmp (dsi_func_names[i], "mpz_mul_2exp") == 0)
        !           274:            /* Limit exponent more for mpz_mul_2exp to save time.  */
        !           275:            in2i %= 0x100;
        !           276:          if (strcmp (dsi_func_names[i], "mpz_pow_ui") == 0)
        !           277:            /* Limit exponent yet more for mpz_pow_ui to save time.  */
        !           278:            in2i %= 0x10;
        !           279:
        !           280:          (dsi_funcs[i]) (ref1, in1, in2i);
        !           281:
        !           282:          mpz_set (res1, in1);
        !           283:          (dsi_funcs[i]) (res1, res1, in2i);
        !           284:          if (mpz_cmp (ref1, res1) != 0)
        !           285:            FAIL (dsi, i, in1, in2, NULL);
        !           286:        }
        !           287:
        !           288:       if (in2i != 0)     /* Don't divide by 0.  */
        !           289:        {
        !           290:          for (i = 0; i < sizeof (dsi_div_funcs) / sizeof (dsi_div_funcs); i++)
        !           291:            {
        !           292:              r1 = (dsi_div_funcs[i]) (ref1, in1, in2i);
        !           293:
        !           294:              mpz_set (res1, in1);
        !           295:              r2 = (dsi_div_funcs[i]) (res1, res1, in2i);
        !           296:              if (mpz_cmp (ref1, res1) != 0 || r1 != r2)
        !           297:                FAIL (dsi_div, i, in1, in2, NULL);
        !           298:            }
        !           299:
        !           300:          for (i = 0; i < sizeof (ddsi_div_funcs) / sizeof (ddsi_div_funcs); i++)
        !           301:            {
        !           302:              r1 = (ddsi_div_funcs[i]) (ref1, ref2, in1, in2i);
        !           303:
        !           304:              mpz_set (res1, in1);
        !           305:              r2 = (ddsi_div_funcs[i]) (res1, res2, res1, in2i);
        !           306:              if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 || r1 != r2)
        !           307:                FAIL (ddsi_div, i, in1, in2, NULL);
        !           308:
        !           309:              mpz_set (res2, in1);
        !           310:              (ddsi_div_funcs[i]) (res1, res2, res2, in2i);
        !           311:              if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0 || r1 != r2)
        !           312:                FAIL (ddsi_div, i, in1, in2, NULL);
        !           313:            }
        !           314:        }
        !           315:
        !           316:       if (mpz_sgn (in1) >= 0)
        !           317:        {
        !           318:          mpz_sqrtrem (ref1, ref2, in1);
        !           319:
        !           320:          mpz_set (res1, in1);
        !           321:          mpz_sqrtrem (res1, res2, res1);
        !           322:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0)
        !           323:            dump_abort ("mpz_sqrtrem", in1, NULL, NULL);
        !           324:
        !           325:          mpz_set (res2, in1);
        !           326:          mpz_sqrtrem (res1, res2, res2);
        !           327:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0)
        !           328:            dump_abort ("mpz_sqrtrem", in1, NULL, NULL);
        !           329:        }
        !           330:
        !           331:       if (mpz_sgn (in1) >= 0)
        !           332:        {
        !           333:          mpz_root (ref1, in1, in2i % 0x100 + 1);
        !           334:
        !           335:          mpz_set (res1, in1);
        !           336:          mpz_root (res1, res1, in2i % 0x100 + 1);
        !           337:          if (mpz_cmp (ref1, res1) != 0)
        !           338:            dump_abort ("mpz_root", in1, in2, NULL);
        !           339:        }
        !           340:
        !           341:       if (pass < reps / 2)     /* run fewer tests since gcdext lots of time */
        !           342:        {
        !           343:          mpz_gcdext (ref1, ref2, ref3, in1, in2);
        !           344:
        !           345:          mpz_set (res1, in1);
        !           346:          mpz_gcdext (res1, res2, res3, res1, in2);
        !           347:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           348:              || mpz_cmp (ref3, res3) != 0)
        !           349:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           350:
        !           351:          mpz_set (res2, in1);
        !           352:          mpz_gcdext (res1, res2, res3, res2, in2);
        !           353:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           354:              || mpz_cmp (ref3, res3) != 0)
        !           355:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           356:
        !           357:          mpz_set (res3, in1);
        !           358:          mpz_gcdext (res1, res2, res3, res3, in2);
        !           359:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           360:              || mpz_cmp (ref3, res3) != 0)
        !           361:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           362:
        !           363:          mpz_set (res1, in2);
        !           364:          mpz_gcdext (res1, res2, res3, in1, res1);
        !           365:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           366:              || mpz_cmp (ref3, res3) != 0)
        !           367:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           368:
        !           369:          mpz_set (res2, in2);
        !           370:          mpz_gcdext (res1, res2, res3, in1, res2);
        !           371:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           372:              || mpz_cmp (ref3, res3) != 0)
        !           373:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           374:
        !           375:          mpz_set (res3, in2);
        !           376:          mpz_gcdext (res1, res2, res3, in1, res3);
        !           377:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           378:              || mpz_cmp (ref3, res3) != 0)
        !           379:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           380:
        !           381:          mpz_set (res1, in1);
        !           382:          mpz_gcdext (res1, res2, NULL, res1, in2);
        !           383:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           384:              || mpz_cmp (ref3, res3) != 0)
        !           385:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           386:
        !           387:          mpz_set (res2, in1);
        !           388:          mpz_gcdext (res1, res2, NULL, res2, in2);
        !           389:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           390:              || mpz_cmp (ref3, res3) != 0)
        !           391:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           392:
        !           393:          mpz_set (res1, in2);
        !           394:          mpz_gcdext (res1, res2, NULL, in1, res1);
        !           395:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           396:              || mpz_cmp (ref3, res3) != 0)
        !           397:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           398:
        !           399:          mpz_set (res2, in2);
        !           400:          mpz_gcdext (res1, res2, NULL, in1, res2);
        !           401:          if (mpz_cmp (ref1, res1) != 0 || mpz_cmp (ref2, res2) != 0
        !           402:              || mpz_cmp (ref3, res3) != 0)
        !           403:            dump_abort ("mpz_gcdext", in1, in2, NULL);
        !           404:        }
        !           405:
        !           406:       /* Don't run mpz_powm for huge exponents or when undefined.  */
        !           407:       if (mpz_sizeinbase (in2, 2) < 250 && mpz_sgn (in3) != 0)
        !           408:        {
        !           409:          mpz_powm (ref1, in1, in2, in3);
        !           410:
        !           411:          mpz_set (res1, in1);
        !           412:          mpz_powm (res1, res1, in2, in3);
        !           413:          if (mpz_cmp (ref1, res1) != 0)
        !           414:            dump_abort ("mpz_powm", in1, in2, in3);
        !           415:
        !           416:          mpz_set (res1, in2);
        !           417:          mpz_powm (res1, in1, res1, in3);
        !           418:          if (mpz_cmp (ref1, res1) != 0)
        !           419:            dump_abort ("mpz_powm", in1, in2, in3);
        !           420:
        !           421:          mpz_set (res1, in3);
        !           422:          mpz_powm (res1, in1, in2, res1);
        !           423:          if (mpz_cmp (ref1, res1) != 0)
        !           424:            dump_abort ("mpz_powm", in1, in2, in3);
        !           425:        }
        !           426:
        !           427:       /* Don't run mpz_powm_ui when undefined.  */
        !           428:       if (mpz_sgn (in3) != 0)
        !           429:        {
        !           430:          mpz_powm_ui (ref1, in1, in2i, in3);
        !           431:
        !           432:          mpz_set (res1, in1);
        !           433:          mpz_powm_ui (res1, res1, in2i, in3);
        !           434:          if (mpz_cmp (ref1, res1) != 0)
        !           435:            dump_abort ("mpz_powm_ui", in1, in2, in3);
        !           436:
        !           437:          mpz_set (res1, in3);
        !           438:          mpz_powm_ui (res1, in1, in2i, res1);
        !           439:          if (mpz_cmp (ref1, res1) != 0)
        !           440:            dump_abort ("mpz_powm_ui", in1, in2, in3);
        !           441:        }
        !           442:
        !           443:       {
        !           444:        r1 = mpz_gcd_ui (ref1, in1, in2i);
        !           445:
        !           446:        mpz_set (res1, in1);
        !           447:        r2 = mpz_gcd_ui (res1, res1, in2i);
        !           448:        if (mpz_cmp (ref1, res1) != 0)
        !           449:          dump_abort ("mpz_gcd_ui", in1, in2, NULL);
        !           450:       }
        !           451:
        !           452:       if (mpz_cmp_ui (in2, 1L) > 0 && mpz_sgn (in1) != 0)
        !           453:        {
        !           454:          /* Test mpz_remove */
        !           455:          mpz_remove (ref1, in1, in2);
        !           456:
        !           457:          mpz_set (res1, in1);
        !           458:          mpz_remove (res1, res1, in2);
        !           459:          if (mpz_cmp (ref1, res1) != 0)
        !           460:            dump_abort ("mpz_remove", in1, in2, NULL);
        !           461:
        !           462:          mpz_set (res1, in2);
        !           463:          mpz_remove (res1, in1, res1);
        !           464:          if (mpz_cmp (ref1, res1) != 0)
        !           465:            dump_abort ("mpz_remove", in1, in2, NULL);
        !           466:        }
        !           467:
        !           468:       if (mpz_sgn (in2) != 0)
        !           469:        {
        !           470:          /* Test mpz_divexact */
        !           471:          mpz_mul (t, in1, in2);
        !           472:          mpz_divexact (ref1, t, in2);
        !           473:
        !           474:          mpz_set (res1, t);
        !           475:          mpz_divexact (res1, res1, in2);
        !           476:          if (mpz_cmp (ref1, res1) != 0)
        !           477:            dump_abort ("mpz_divexact", t, in2, NULL);
        !           478:
        !           479:          mpz_set (res1, in2);
        !           480:          mpz_divexact (res1, t, res1);
        !           481:          if (mpz_cmp (ref1, res1) != 0)
        !           482:            dump_abort ("mpz_divexact", t, in2, NULL);
        !           483:        }
        !           484:     }
        !           485:
        !           486:   if (failures != 0)
        !           487:     {
        !           488:       fprintf (stderr, "mpz/reuse: %d error%s\n", failures, "s" + (failures == 1));
        !           489:       exit (1);
1.1       maekawa   490:     }
                    491:
                    492:   exit (0);
                    493: }
                    494:
1.1.1.2 ! maekawa   495: dump_abort (name, in1, in2, in3)
1.1       maekawa   496:      char *name;
1.1.1.2 ! maekawa   497:      mpz_t in1, in2, in3;
1.1       maekawa   498: {
                    499:   printf ("failure in %s (", name);
                    500:   mpz_out_str (stdout, -16, in1);
1.1.1.2 ! maekawa   501:   if (in2 != NULL)
        !           502:     {
        !           503:       printf (" ");
        !           504:       mpz_out_str (stdout, -16, in2);
        !           505:     }
        !           506:   if (in3 != NULL)
        !           507:     {
        !           508:       printf (" ");
        !           509:       mpz_out_str (stdout, -16, in3);
        !           510:     }
1.1       maekawa   511:   printf (")\n");
                    512: }

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