X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=gmp%2Fmpz%2Fdive_ui.c;fp=gmp%2Fmpz%2Fdive_ui.c;h=53709aa3b7c9db41ea884978e26ff8b5520e29df;hb=6fed43773c9b0ce596dca5686f37ac3fc0fa11c0;hp=0000000000000000000000000000000000000000;hpb=27b11d56b743098deb193d510b337ba22dc52e5c;p=msp430-gcc.git diff --git a/gmp/mpz/dive_ui.c b/gmp/mpz/dive_ui.c new file mode 100644 index 00000000..53709aa3 --- /dev/null +++ b/gmp/mpz/dive_ui.c @@ -0,0 +1,59 @@ +/* mpz_divexact_ui -- exact division mpz by ulong. + +Copyright 2001, 2002 Free Software Foundation, Inc. + +This file is part of the GNU MP Library. + +The GNU MP Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ + +#include "gmp.h" +#include "gmp-impl.h" + +void +mpz_divexact_ui (mpz_ptr dst, mpz_srcptr src, unsigned long divisor) +{ + mp_size_t size, abs_size; + mp_ptr dst_ptr; + + if (divisor == 0) + DIVIDE_BY_ZERO; + + /* For nails don't try to be clever if d is bigger than a limb, just fake + up an mpz_t and go to the main mpz_divexact. */ + if (divisor > GMP_NUMB_MAX) + { + mp_limb_t dlimbs[2]; + mpz_t dz; + ALLOC(dz) = 2; + PTR(dz) = dlimbs; + mpz_set_ui (dz, divisor); + mpz_divexact (dst, src, dz); + return; + } + + size = SIZ(src); + if (size == 0) + { + SIZ(dst) = 0; + return; + } + abs_size = ABS (size); + + MPZ_REALLOC (dst, abs_size); + dst_ptr = PTR(dst); + + MPN_DIVREM_OR_DIVEXACT_1 (dst_ptr, PTR(src), abs_size, (mp_limb_t) divisor); + abs_size -= (dst_ptr[abs_size-1] == 0); + SIZ(dst) = (size >= 0 ? abs_size : -abs_size); +}