You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1004 B

25 years ago
  1. // logcount().
  2. // General includes.
  3. #include "cl_sysdep.h"
  4. // Specification.
  5. #include "cl_integer.h"
  6. // Implementation.
  7. #include "cl_I.h"
  8. #include "cl_DS.h"
  9. #include "cl_D.h"
  10. #include "cl_low.h"
  11. uintL logcount (const cl_I& x)
  12. {
  13. if (fixnump(x))
  14. { var uint32 x32 = FN_to_L(x); // x als 32-Bit-Zahl
  15. if (FN_L_minusp(x,(sint32)x32)) { x32 = ~ x32; } // falls <0, komplementieren
  16. logcount_32(); // Bits von x32 z�hlen
  17. return x32;
  18. }
  19. else
  20. { var const uintD* MSDptr;
  21. var uintC len;
  22. BN_to_NDS_nocopy(x, MSDptr=,len=,); // DS zu x bilden, len>0.
  23. var uintL bitcount = 0; // Bitz�hler
  24. var const uintD* ptr = MSDptr; // l�uft durch die Digits durch
  25. var uintD sign = sign_of_sintD(mspref(ptr,0)); // Vorzeichen
  26. dotimespC(len,len,
  27. { bitcount += (uintL)logcountD(msprefnext(ptr) ^ sign); });
  28. // 0 <= bitcount < intDsize*2^intCsize.
  29. return bitcount;
  30. }
  31. }