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

Annotation of OpenXM_contrib/gmp/tests/mpz/t-mul_i.c, Revision 1.1

1.1     ! ohara       1: /* Test mpz_mul_ui and mpz_mul_si.
        !             2:
        !             3: Copyright 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:
        !            25: #include "gmp.h"
        !            26: #include "gmp-impl.h"
        !            27: #include "tests.h"
        !            28:
        !            29:
        !            30: mpz_t got, want, x;
        !            31:
        !            32: void
        !            33: compare_si (long y)
        !            34: {
        !            35:   if (mpz_cmp (got, want) != 0)
        !            36:     {
        !            37:       printf    ("mpz_mul_si wrong\n");
        !            38:       mpz_trace ("  x", x);
        !            39:       printf    ("  y=%ld (0x%lX)\n", y, y);
        !            40:       mpz_trace ("  got ", got);
        !            41:       mpz_trace ("  want", want);
        !            42:       abort ();
        !            43:     }
        !            44: }
        !            45:
        !            46: void
        !            47: compare_ui (unsigned long y)
        !            48: {
        !            49:   if (mpz_cmp (got, want) != 0)
        !            50:     {
        !            51:       printf    ("mpz_mul_ui wrong\n");
        !            52:       mpz_trace ("  x", x);
        !            53:       printf    ("  y=%lu (0x%lX)\n", y, y);
        !            54:       mpz_trace ("  got ", got);
        !            55:       mpz_trace ("  want", want);
        !            56:       abort ();
        !            57:     }
        !            58: }
        !            59:
        !            60: void
        !            61: check_samples (void)
        !            62: {
        !            63:   {
        !            64:     long  y;
        !            65:
        !            66:     mpz_set_ui (x, 1L);
        !            67:     y = 0;
        !            68:     mpz_mul_si (got, x, y);
        !            69:     mpz_set_si (want, y);
        !            70:     compare_si (y);
        !            71:
        !            72:     mpz_set_ui (x, 1L);
        !            73:     y = 1;
        !            74:     mpz_mul_si (got, x, y);
        !            75:     mpz_set_si (want, y);
        !            76:     compare_si (y);
        !            77:
        !            78:     mpz_set_ui (x, 1L);
        !            79:     y = -1;
        !            80:     mpz_mul_si (got, x, y);
        !            81:     mpz_set_si (want, y);
        !            82:     compare_si (y);
        !            83:
        !            84:     mpz_set_ui (x, 1L);
        !            85:     y = LONG_MIN;
        !            86:     mpz_mul_si (got, x, y);
        !            87:     mpz_set_si (want, y);
        !            88:     compare_si (y);
        !            89:
        !            90:     mpz_set_ui (x, 1L);
        !            91:     y = LONG_MAX;
        !            92:     mpz_mul_si (got, x, y);
        !            93:     mpz_set_si (want, y);
        !            94:     compare_si (y);
        !            95:   }
        !            96:
        !            97:   {
        !            98:     unsigned long y;
        !            99:
        !           100:     mpz_set_ui (x, 1L);
        !           101:     y = 0;
        !           102:     mpz_mul_ui (got, x, y);
        !           103:     mpz_set_ui (want, y);
        !           104:     compare_ui (y);
        !           105:
        !           106:     mpz_set_ui (x, 1L);
        !           107:     y = 1;
        !           108:     mpz_mul_ui (got, x, y);
        !           109:     mpz_set_ui (want, y);
        !           110:     compare_ui (y);
        !           111:
        !           112:     mpz_set_ui (x, 1L);
        !           113:     y = ULONG_MAX;
        !           114:     mpz_mul_ui (got, x, y);
        !           115:     mpz_set_ui (want, y);
        !           116:     compare_ui (y);
        !           117:   }
        !           118: }
        !           119:
        !           120: int
        !           121: main (int argc, char **argv)
        !           122: {
        !           123:   tests_start ();
        !           124:
        !           125:   mpz_init (x);
        !           126:   mpz_init (got);
        !           127:   mpz_init (want);
        !           128:
        !           129:   check_samples ();
        !           130:
        !           131:   mpz_clear (x);
        !           132:   mpz_clear (got);
        !           133:   mpz_clear (want);
        !           134:
        !           135:   tests_end ();
        !           136:   exit (0);
        !           137: }

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