mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 06:20:23 +02:00
(z_negative_one): New variable.
(scm_init_numbers): Initialize it. (scm_logcount): Use it and mpz_hamdist to count zeros for negatives.
This commit is contained in:
parent
5f653c6a56
commit
713a425913
1 changed files with 7 additions and 13 deletions
|
@ -119,6 +119,7 @@ isinf (double x)
|
||||||
|
|
||||||
|
|
||||||
static SCM abs_most_negative_fixnum;
|
static SCM abs_most_negative_fixnum;
|
||||||
|
static mpz_t z_negative_one;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1396,20 +1397,11 @@ SCM_DEFINE (scm_logcount, "logcount", 1, 0, 0,
|
||||||
else if (SCM_BIGP (n))
|
else if (SCM_BIGP (n))
|
||||||
{
|
{
|
||||||
unsigned long count;
|
unsigned long count;
|
||||||
if (mpz_sgn (SCM_I_BIG_MPZ (n)) < 0)
|
if (mpz_sgn (SCM_I_BIG_MPZ (n)) >= 0)
|
||||||
{
|
count = mpz_popcount (SCM_I_BIG_MPZ (n));
|
||||||
mpz_t z_n;
|
|
||||||
mpz_init (z_n);
|
|
||||||
mpz_com (z_n, SCM_I_BIG_MPZ (n));
|
|
||||||
scm_remember_upto_here_1 (n);
|
|
||||||
count = mpz_popcount (z_n);
|
|
||||||
mpz_clear (z_n);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
count = mpz_hamdist (SCM_I_BIG_MPZ (n), z_negative_one);
|
||||||
count = mpz_popcount (SCM_I_BIG_MPZ (n));
|
scm_remember_upto_here_1 (n);
|
||||||
scm_remember_upto_here_1 (n);
|
|
||||||
}
|
|
||||||
return SCM_MAKINUM (count);
|
return SCM_MAKINUM (count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -4217,6 +4209,8 @@ scm_init_numbers ()
|
||||||
abs_most_negative_fixnum = scm_i_long2big (- SCM_MOST_NEGATIVE_FIXNUM);
|
abs_most_negative_fixnum = scm_i_long2big (- SCM_MOST_NEGATIVE_FIXNUM);
|
||||||
scm_permanent_object (abs_most_negative_fixnum);
|
scm_permanent_object (abs_most_negative_fixnum);
|
||||||
|
|
||||||
|
mpz_init_set_si (z_negative_one, -1);
|
||||||
|
|
||||||
/* It may be possible to tune the performance of some algorithms by using
|
/* It may be possible to tune the performance of some algorithms by using
|
||||||
* the following constants to avoid the creation of bignums. Please, before
|
* the following constants to avoid the creation of bignums. Please, before
|
||||||
* using these values, remember the two rules of program optimization:
|
* using these values, remember the two rules of program optimization:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue