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

« back to all changes in this revision

Viewing changes to src/gmp/mpz/bin_ui.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
 
/* mpz_bin_uiui - compute n over k.
 
1
/* mpz_bin_ui - compute n over k.
2
2
 
3
3
Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4
4
 
16
16
 
17
17
You should have received a copy of the GNU Lesser General Public License
18
18
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19
 
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
 
MA 02111-1307, USA. */
 
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
MA 02110-1301, USA. */
21
21
 
22
22
#include "gmp.h"
23
23
#include "gmp-impl.h"
32
32
   1 section 1.2.6 part G. */
33
33
 
34
34
 
35
 
/* Enhancement: use mpn_divexact_1 when it exists */
36
 
#define DIVIDE()                                                \
37
 
  do {                                                          \
38
 
    ASSERT (SIZ(r) > 0);                                        \
39
 
    MPN_DIVREM_OR_DIVEXACT_1 (PTR(r), PTR(r), SIZ(r), kacc);    \
40
 
    SIZ(r) -= (PTR(r)[SIZ(r)-1] == 0);                          \
 
35
#define DIVIDE()                                                              \
 
36
  do {                                                                        \
 
37
    ASSERT (SIZ(r) > 0);                                                      \
 
38
    MPN_DIVREM_OR_DIVEXACT_1 (PTR(r), PTR(r), (mp_size_t) SIZ(r), kacc);      \
 
39
    SIZ(r) -= (PTR(r)[SIZ(r)-1] == 0);                                        \
41
40
  } while (0)
42
41
 
43
42
void
89
88
    }
90
89
 
91
90
  kacc = 1;
92
 
  mpz_init_set_ui (nacc, 1);
 
91
  mpz_init_set_ui (nacc, 1L);
93
92
 
94
93
  for (i = 1; i <= k; i++)
95
94
    {
108
107
      mpz_div_2exp (nacc, nacc, c);
109
108
#endif
110
109
 
111
 
      mpz_add_ui (ni, ni, 1);
 
110
      mpz_add_ui (ni, ni, 1L);
112
111
      mpz_mul (nacc, nacc, ni);
113
112
      umul_ppmm (k1, k0, kacc, i << GMP_NAIL_BITS);
114
113
      k0 >>= GMP_NAIL_BITS;
116
115
        {
117
116
          /* Accumulator overflow.  Perform bignum step.  */
118
117
          mpz_mul (r, r, nacc);
119
 
          mpz_set_ui (nacc, 1);
 
118
          mpz_set_ui (nacc, 1L);
120
119
          DIVIDE ();
121
120
          kacc = i;
122
121
        }