~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/mpn/generic/sqrtrem.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-04-09 11:51:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070409115151-ql8cr0kalzx1jmla
Tags: 0.9i-20070324-2
Upload to unstable. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* mpn_sqrtrem -- square root and remainder */
 
1
/* mpn_sqrtrem -- square root and remainder
2
2
 
3
 
/*
4
 
Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
3
Copyright 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
5
4
 
6
5
This file is part of the GNU MP Library.
7
6
 
17
16
 
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,
21
 
MA 02111-1307, USA.
22
 
*/
 
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
MA 02110-1301, USA. */
23
21
 
24
22
 
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);
198
196
 
199
197
      if (c < 0)
200
198
        {
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));
204
202
        }
205
203
    }
206
204
 
214
212
  mp_limb_t *tp, s0[1], cc, high, rl;
215
213
  int c;
216
214
  mp_size_t rn, tn;
217
 
  TMP_DECL (marker);
 
215
  TMP_DECL;
218
216
 
219
217
  ASSERT (nn >= 0);
 
218
  ASSERT_MPN (np, nn);
220
219
 
221
220
  /* If OP is zero, both results are zero.  */
222
221
  if (nn == 0)
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 */
238
237
 
239
 
  TMP_MARK (marker);
 
238
  TMP_MARK;
240
239
  if (nn % 2 != 0 || c > 0)
241
240
    {
242
241
      tp = TMP_ALLOC_LIMBS (2 * tn);
282
281
 
283
282
  MPN_NORMALIZE (rp, rn);
284
283
 
285
 
  TMP_FREE (marker);
 
284
  TMP_FREE;
286
285
  return rn;
287
286
}