fmtlib.c 865 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* @(#)fmtlib.c 1.2 */
  2. #define MAXINTLENGTH 23
  3. #include "f2c.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #ifndef Allow_TYQUAD
  8. #undef longint
  9. #define longint long
  10. #undef ulongint
  11. #define ulongint unsigned long
  12. #endif
  13. #ifdef KR_headers
  14. char *f__icvt(value,ndigit,sign, base) longint value; int *ndigit,*sign;
  15. register int base;
  16. #else
  17. char *f__icvt(longint value, int *ndigit, int *sign, int base)
  18. #endif
  19. {
  20. static char buf[MAXINTLENGTH+1];
  21. register int i;
  22. ulongint uvalue;
  23. if(value > 0) {
  24. uvalue = value;
  25. *sign = 0;
  26. }
  27. else if (value < 0) {
  28. uvalue = -value;
  29. *sign = 1;
  30. }
  31. else {
  32. *sign = 0;
  33. *ndigit = 1;
  34. buf[MAXINTLENGTH-1] = '0';
  35. return &buf[MAXINTLENGTH-1];
  36. }
  37. i = MAXINTLENGTH;
  38. do {
  39. buf[--i] = (uvalue%base) + '0';
  40. uvalue /= base;
  41. }
  42. while(uvalue > 0);
  43. *ndigit = MAXINTLENGTH - i;
  44. return &buf[i];
  45. }
  46. #ifdef __cplusplus
  47. }
  48. #endif