1
/* mpn_sqrtrem -- square root and remainder */
1
/* mpn_sqrtrem -- square root and remainder
4
Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
Copyright 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
6
5
This file is part of the GNU MP Library.
18
17
You should have received a copy of the GNU Lesser General Public License
19
18
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
MA 02110-1301, USA. */
25
23
/* Contributed by Paul Zimmermann.
193
191
c = mpn_add_n (np + l, np + l, sp + l, h);
194
192
mpn_sqr_n (np + n, sp, l);
195
193
b = q + mpn_sub_n (np, np, np + n, 2 * l);
196
c -= (l == h) ? b : mpn_sub_1 (np + 2 * l, np + 2 * l, 1, b);
194
c -= (l == h) ? b : mpn_sub_1 (np + 2 * l, np + 2 * l, 1, (mp_limb_t) b);
197
195
q = mpn_add_1 (sp + l, sp + l, h, q);
201
c += mpn_addmul_1 (np, sp, n, 2) + 2 * q;
202
c -= mpn_sub_1 (np, np, n, 1);
203
q -= mpn_sub_1 (sp, sp, n, 1);
199
c += mpn_addmul_1 (np, sp, n, CNST_LIMB(2)) + 2 * q;
200
c -= mpn_sub_1 (np, np, n, CNST_LIMB(1));
201
q -= mpn_sub_1 (sp, sp, n, CNST_LIMB(1));
236
235
c = c / 2; /* we have to shift left by 2c bits to normalize {np, nn} */
237
236
tn = (nn + 1) / 2; /* 2*tn is the smallest even integer >= nn */
240
239
if (nn % 2 != 0 || c > 0)
242
241
tp = TMP_ALLOC_LIMBS (2 * tn);