diff options
author | tege <tege@gmplib.org> | 2002-04-16 19:26:53 +0200 |
---|---|---|
committer | tege <tege@gmplib.org> | 2002-04-16 19:26:53 +0200 |
commit | fd52c03ccfb6a6216ef8404774e286cbb114e95c (patch) | |
tree | 95faeacbd9568b439cb21b92ff4dc31c6c3b900d /mpz/iset_si.c | |
parent | a553bd5b63fb37787a3b030339161b0ae8cf4542 (diff) | |
download | gmp-fd52c03ccfb6a6216ef8404774e286cbb114e95c.tar.gz |
Nailify.
Diffstat (limited to 'mpz/iset_si.c')
-rw-r--r-- | mpz/iset_si.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/mpz/iset_si.c b/mpz/iset_si.c index 5db5ed2f3..a095b9c32 100644 --- a/mpz/iset_si.c +++ b/mpz/iset_si.c @@ -1,5 +1,5 @@ -/* mpz_init_set_si(val) -- Make a new multiple precision number with - value val. +/* mpz_init_set_si(dest,val) -- Make a new multiple precision in DEST and + assign VAL to the new number. Copyright 1991, 1993, 1994, 1995, 2000, 2001, 2002 Free Software Foundation, Inc. @@ -25,10 +25,27 @@ MA 02111-1307, USA. */ #include "gmp-impl.h" void -mpz_init_set_si (mpz_ptr x, signed long int val) +mpz_init_set_si (mpz_ptr dest, signed long int val) { - x->_mp_alloc = 1; - x->_mp_d = (mp_ptr) (*__gmp_allocate_func) (BYTES_PER_MP_LIMB); - x->_mp_d[0] = (unsigned long) (val >= 0 ? val : -val); - x->_mp_size = (val > 0 ? 1 : val == 0 ? 0 : -1); + mp_size_t size; + mp_limb_t vl; + + dest->_mp_alloc = 1; + dest->_mp_d = (mp_ptr) (*__gmp_allocate_func) (BYTES_PER_MP_LIMB); + + vl = val >= 0 ? val : -val; + + dest->_mp_d[0] = vl & GMP_NUMB_MASK; + size = vl != 0; + +#if GMP_NAIL_BITS != 0 + if (vl > GMP_NUMB_MAX) + { + MPZ_REALLOC (dest, 2); + dest->_mp_d[1] = vl >> GMP_NUMB_BITS; + size = 2; + } +#endif + + dest->_mp_size = val >= 0 ? size : -size; } |