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

Annotation of OpenXM_contrib/gmp/mpz/mul_siui.c, Revision 1.1

1.1     ! maekawa     1: /* mpz_mul_ui/si (product, multiplier, small_multiplicand) -- Set PRODUCT to
        !             2:    MULTIPLICATOR times SMALL_MULTIPLICAND.
        !             3:
        !             4: Copyright (C) 1991, 1993, 1994, 1996, 2000 Free Software Foundation, Inc.
        !             5:
        !             6: This file is part of the GNU MP Library.
        !             7:
        !             8: The GNU MP Library is free software; you can redistribute it and/or modify
        !             9: it under the terms of the GNU Lesser General Public License as published by
        !            10: the Free Software Foundation; either version 2.1 of the License, or (at your
        !            11: option) any later version.
        !            12:
        !            13: The GNU MP Library is distributed in the hope that it will be useful, but
        !            14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            15: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
        !            16: License for more details.
        !            17:
        !            18: You should have received a copy of the GNU Lesser General Public License
        !            19: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
        !            20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
        !            21: MA 02111-1307, USA. */
        !            22:
        !            23: #include "gmp.h"
        !            24: #include "gmp-impl.h"
        !            25:
        !            26:
        !            27: #ifdef OPERATION_mul_ui
        !            28: #define FUNCTION              mpz_mul_ui
        !            29: #define MULTIPLICAND_UNSIGNED unsigned
        !            30: #define MULTIPLICAND_ABS(x)   x
        !            31: #else
        !            32: #ifdef OPERATION_mul_si
        !            33: #define FUNCTION              mpz_mul_si
        !            34: #define MULTIPLICAND_UNSIGNED
        !            35: #define MULTIPLICAND_ABS(x)   ABS(x)
        !            36: #else
        !            37: Error, error, unrecognised OPERATION
        !            38: #endif
        !            39: #endif
        !            40:
        !            41:
        !            42: void
        !            43: #if __STDC__
        !            44: FUNCTION (mpz_ptr prod, mpz_srcptr mult,
        !            45:           MULTIPLICAND_UNSIGNED long int small_mult)
        !            46: #else
        !            47: FUNCTION (prod, mult, small_mult)
        !            48:      mpz_ptr prod;
        !            49:      mpz_srcptr mult;
        !            50:      MULTIPLICAND_UNSIGNED long int small_mult;
        !            51: #endif
        !            52: {
        !            53:   mp_size_t size = mult->_mp_size;
        !            54:   mp_size_t sign_product = size;
        !            55:   mp_limb_t cy;
        !            56:   mp_size_t prod_size;
        !            57:   mp_ptr prod_ptr;
        !            58:
        !            59:   if (size == 0 || small_mult == 0)
        !            60:     {
        !            61:       prod->_mp_size = 0;
        !            62:       return;
        !            63:     }
        !            64:   size = ABS (size);
        !            65:
        !            66:   prod_size = size + 1;
        !            67:   if (prod->_mp_alloc < prod_size)
        !            68:     _mpz_realloc (prod, prod_size);
        !            69:
        !            70:   prod_ptr = prod->_mp_d;
        !            71:
        !            72:   cy = mpn_mul_1 (prod_ptr, mult->_mp_d, size,
        !            73:                   (mp_limb_t) MULTIPLICAND_ABS (small_mult));
        !            74:   if (cy != 0)
        !            75:     {
        !            76:       prod_ptr[size] = cy;
        !            77:       size++;
        !            78:     }
        !            79:
        !            80:   prod->_mp_size = ((sign_product < 0) ^ (small_mult < 0)) ? -size : size;
        !            81: }

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