diff --git a/C/arith1.c b/C/arith1.c index f0e8b22ef..be765abe0 100644 --- a/C/arith1.c +++ b/C/arith1.c @@ -184,6 +184,26 @@ lsb(Int inp) /* calculate the least significant bit for an integer */ return out; } +static Int +popcount(Int inp) /* calculate the least significant bit for an integer */ +{ + /* the obvious solution: do it by using binary search */ + Int c = 0, j = 0, m = 1L; + + if (inp < 0) { + return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(inp), + "popcount/1 received %d", inp); + } + if (inp==0) + return 0L; + for(j=0,c=0; j