2011-03-14 11:51:54 -04:00
|
|
|
/*
|
|
|
|
mpz_get_ux(mpz z) -- return a uintmax_t integer that is the corresponding
|
|
|
|
least significant integer part of z, ignoring its sign.
|
|
|
|
|
|
|
|
Copyright 2011 Brian Gladman
|
|
|
|
|
|
|
|
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 2.1 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; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
|
|
|
|
2011-03-30 14:15:31 -04:00
|
|
|
#ifdef HAVE_STDINT_H
|
2011-03-19 05:28:07 -04:00
|
|
|
#include <stdint.h>
|
2011-03-30 14:15:31 -04:00
|
|
|
#endif
|
2011-03-14 11:51:54 -04:00
|
|
|
|
|
|
|
#include "mpir.h"
|
|
|
|
#include "gmp-impl.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_UINTMAX_T
|
|
|
|
|
2011-03-14 13:55:58 -04:00
|
|
|
#define NLIMBS ((8 * SIZEOF_UINTMAX_T + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS)
|
2011-03-14 11:51:54 -04:00
|
|
|
|
|
|
|
uintmax_t
|
|
|
|
mpz_get_ux (mpz_srcptr z)
|
|
|
|
{
|
2011-03-19 05:28:07 -04:00
|
|
|
#if NLIMBS == 1
|
2011-03-14 11:51:54 -04:00
|
|
|
return (uintmax_t)(z->_mp_size ? z->_mp_d[0] : 0);
|
|
|
|
#else
|
|
|
|
uintmax_t v = 0, n = MIN(NLIMBS, ABS(z->_mp_size));
|
|
|
|
while(n--)
|
|
|
|
v = (v << GMP_NUMB_BITS) | z->_mp_d[n];
|
|
|
|
return v;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|