1 /* mpz_mul_ui/si (product, multiplier, small_multiplicand) -- Set PRODUCT to
2 MULTIPLICATOR times SMALL_MULTIPLICAND.
4 Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2002, 2005, 2008 Free Software
7 This file is part of the GNU MP Library.
9 The GNU MP Library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
14 The GNU MP Library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
26 #ifdef OPERATION_mul_si
27 #define FUNCTION mpz_mul_si
28 #define MULTIPLICAND_UNSIGNED
29 #define MULTIPLICAND_ABS(x) ABS_CAST(unsigned long, (x))
32 #ifdef OPERATION_mul_ui
33 #define FUNCTION mpz_mul_ui
34 #define MULTIPLICAND_UNSIGNED unsigned
35 #define MULTIPLICAND_ABS(x) x
39 Error, error, unrecognised OPERATION
44 FUNCTION (mpz_ptr prod, mpz_srcptr mult,
45 MULTIPLICAND_UNSIGNED long int small_mult)
47 mp_size_t size = SIZ(mult);
48 mp_size_t sign_product = size;
53 if (size == 0 || small_mult == 0)
61 sml = MULTIPLICAND_ABS (small_mult);
63 if (sml <= GMP_NUMB_MAX)
65 MPZ_REALLOC (prod, size + 1);
67 cy = mpn_mul_1 (pp, PTR(mult), size, sml & GMP_NUMB_MASK);
71 #if GMP_NAIL_BITS != 0
74 /* Operand too large for the current nails size. Use temporary for
75 intermediate products, to allow prod and mult being identical. */
80 tp = TMP_ALLOC_LIMBS (size + 2);
82 cy = mpn_mul_1 (tp, PTR(mult), size, sml & GMP_NUMB_MASK);
84 cy = mpn_addmul_1 (tp + 1, PTR(mult), size, sml >> GMP_NUMB_BITS);
87 MPN_NORMALIZE_NOT_ZERO (tp, size); /* too general, need to trim one or two limb */
88 MPZ_REALLOC (prod, size);
90 MPN_COPY (pp, tp, size);
95 SIZ(prod) = ((sign_product < 0) ^ (small_mult < 0)) ? -size : size;