40 lines
834 B

25 years ago
25 years ago
25 years ago
25 years ago
  1. // print_integer().
  2. // General includes.
  3. #include "cl_sysdep.h"
  4. // Specification.
  5. #include "cln/integer_io.h"
  6. // Implementation.
  7. #include "cln/io.h"
  8. #include "cl_I.h"
  9. #include "cl_DS.h"
  10. namespace cln {
  11. void print_integer (std::ostream& stream, unsigned int base, const cl_I& z)
  12. {
  13. var cl_I abs_z;
  14. if (minusp(z)) {
  15. // z<0 -> Vorzeichen ausgeben:
  16. fprintchar(stream,'-');
  17. abs_z = -z;
  18. } else
  19. abs_z = z;
  20. CL_ALLOCA_STACK;
  21. var uintL need = cl_digits_need(abs_z,base);
  22. var uintB* ziffern = cl_alloc_array(uintB,need); // Platz f�r die Ziffern
  23. var cl_digits erg; erg.LSBptr = &ziffern[need];
  24. I_to_digits(abs_z,(uintD)base,&erg); // Umwandlung in Ziffern
  25. // Ziffern ausgeben:
  26. {
  27. var uintB* ptr = erg.MSBptr;
  28. var uintL count = erg.len;
  29. do { fprintchar(stream,*ptr++); } until (--count==0);
  30. }
  31. }
  32. } // namespace cln