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

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

1.1     ! ohara       1: /* Test mpz_set_si and mpz_init_set_si.
        !             2:
        !             3: Copyright 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 "gmp.h"
        !            25: #include "gmp-impl.h"
        !            26: #include "tests.h"
        !            27:
        !            28:
        !            29: void
        !            30: check_data (void)
        !            31: {
        !            32: #if GMP_NUMB_BITS <= BITS_PER_ULONG
        !            33: #define ENTRY(n)   { n, { n, 0 } }
        !            34: #else
        !            35: #define ENTRY(n)   { n, { (n) & GMP_NUMB_MASK, (n) >> GMP_NUMB_BITS } }
        !            36: #endif
        !            37:
        !            38:   static const struct {
        !            39:     long       n;
        !            40:     mp_size_t  want_size;
        !            41:     mp_limb_t  want_data[2];
        !            42:   } data[] = {
        !            43:
        !            44:     {  0L,  0 },
        !            45:     {  1L,  1, { 1 } },
        !            46:     { -1L, -1, { 1 } },
        !            47:
        !            48: #if GMP_NUMB_BITS >= BITS_PER_ULONG
        !            49:     { LONG_MAX,  1, { LONG_MAX, 0 } },
        !            50:     { -LONG_MAX,  -1, { LONG_MAX, 0 } },
        !            51:     { LONG_HIGHBIT,  -1, { ULONG_HIGHBIT, 0 } },
        !            52: #else
        !            53:     { LONG_MAX,  2, { LONG_MAX & GMP_NUMB_MASK, LONG_MAX >> GMP_NUMB_BITS } },
        !            54:     { -LONG_MAX,  -2, { LONG_MAX & GMP_NUMB_MASK, LONG_MAX >> GMP_NUMB_BITS }},
        !            55:     { LONG_HIGHBIT,  -2, { 0, ULONG_HIGHBIT >> GMP_NUMB_BITS } },
        !            56: #endif
        !            57:   };
        !            58:
        !            59:   mpz_t  n;
        !            60:   int    i;
        !            61:
        !            62:   for (i = 0; i < numberof (data); i++)
        !            63:     {
        !            64:       mpz_init (n);
        !            65:       mpz_set_si (n, data[i].n);
        !            66:       MPZ_CHECK_FORMAT (n);
        !            67:       if (n->_mp_size != data[i].want_size
        !            68:           || refmpn_cmp_allowzero (n->_mp_d, data[i].want_data,
        !            69:                                    ABS (data[i].want_size)) != 0)
        !            70:         {
        !            71:           printf ("mpz_set_si wrong on data[%d]\n", i);
        !            72:           abort();
        !            73:         }
        !            74:       mpz_clear (n);
        !            75:
        !            76:       mpz_init_set_si (n, data[i].n);
        !            77:       MPZ_CHECK_FORMAT (n);
        !            78:       if (n->_mp_size != data[i].want_size
        !            79:           || refmpn_cmp_allowzero (n->_mp_d, data[i].want_data,
        !            80:                                    ABS (data[i].want_size)) != 0)
        !            81:         {
        !            82:           printf ("mpz_init_set_si wrong on data[%d]\n", i);
        !            83:           abort();
        !            84:         }
        !            85:       mpz_clear (n);
        !            86:     }
        !            87: }
        !            88:
        !            89:
        !            90: int
        !            91: main (void)
        !            92: {
        !            93:   tests_start ();
        !            94:
        !            95:   check_data ();
        !            96:
        !            97:   tests_end ();
        !            98:   exit (0);
        !            99: }

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