a Big Number module

yidabu yidabu.nospam at gmail.com
Sun Nov 4 15:55:28 PST 2007


bearophile Wrote:

> Nice. Can it made to work with Phobos alone too?
> 
> Maybe the function bigintLLCountOnes() can be speed up with this:
> 
> /*********************************
> Quickly return the number of set bits in the given uint
> (functions similar to this one can work on 64 bits too).
> */
> int countBitUint(TyNumber)(TyNumber v) {
>     // This templating trick is useful to avoid processing ulongs
>     static if( is(TyNumber == uint) ) {
>         v = v - ((v >> 1) & 0x55555555);    // reuse input as temporary
>         v = (v & 0x33333333) + ((v >> 2) & 0x33333333);        // temp
>         return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
>     } else
>         assert(false, "countBitUint() works only with uint, not with " ~ typeid(TyNumber).toString);
> }
> 
> Bye,
> bearophile

Thanks!

since Phobos is dead end, I not use it if possible.




More information about the Digitalmars-d mailing list