xref: /netbsd-src/external/lgpl3/gmp/dist/mpz/array_init.c (revision 72c7faa4dbb41dbb0238d6b4a109da0d4b236dd4)
151c586b8Smrg /* mpz_array_init (array, array_size, size_per_elem) --
251c586b8Smrg 
3*ce543368Smrg Copyright 1991, 1993-1995, 2000-2002, 2012 Free Software Foundation, Inc.
451c586b8Smrg 
551c586b8Smrg This file is part of the GNU MP Library.
651c586b8Smrg 
751c586b8Smrg The GNU MP Library is free software; you can redistribute it and/or modify
8*ce543368Smrg it under the terms of either:
9*ce543368Smrg 
10*ce543368Smrg   * the GNU Lesser General Public License as published by the Free
11*ce543368Smrg     Software Foundation; either version 3 of the License, or (at your
1251c586b8Smrg     option) any later version.
1351c586b8Smrg 
14*ce543368Smrg or
15*ce543368Smrg 
16*ce543368Smrg   * the GNU General Public License as published by the Free Software
17*ce543368Smrg     Foundation; either version 2 of the License, or (at your option) any
18*ce543368Smrg     later version.
19*ce543368Smrg 
20*ce543368Smrg or both in parallel, as here.
21*ce543368Smrg 
2251c586b8Smrg The GNU MP Library is distributed in the hope that it will be useful, but
2351c586b8Smrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24*ce543368Smrg or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25*ce543368Smrg for more details.
2651c586b8Smrg 
27*ce543368Smrg You should have received copies of the GNU General Public License and the
28*ce543368Smrg GNU Lesser General Public License along with the GNU MP Library.  If not,
29*ce543368Smrg see https://www.gnu.org/licenses/.  */
3051c586b8Smrg 
3151c586b8Smrg #include "gmp-impl.h"
3251c586b8Smrg 
3351c586b8Smrg void
mpz_array_init(mpz_ptr arr,mp_size_t arr_size,mp_size_t nbits)3451c586b8Smrg mpz_array_init (mpz_ptr arr, mp_size_t arr_size, mp_size_t nbits)
3551c586b8Smrg {
36*ce543368Smrg   mp_ptr p;
37*ce543368Smrg   mp_size_t i;
3851c586b8Smrg   mp_size_t nlimbs;
3951c586b8Smrg 
40*ce543368Smrg   nlimbs = nbits / GMP_NUMB_BITS + 1;
41*ce543368Smrg   p = __GMP_ALLOCATE_FUNC_LIMBS (arr_size * nlimbs);
4251c586b8Smrg 
4351c586b8Smrg   for (i = 0; i < arr_size; i++)
4451c586b8Smrg     {
45dab47db4Smrg       ALLOC (&arr[i]) = nlimbs + 1; /* Yes, lie a little... */
46dab47db4Smrg       SIZ (&arr[i]) = 0;
47dab47db4Smrg       PTR (&arr[i]) = p + i * nlimbs;
4851c586b8Smrg     }
4951c586b8Smrg }
50