home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / h / hp11 / Amiga_Code / c / testecvt < prev    next >
Encoding:
Text File  |  1992-05-07  |  1.2 KB  |  39 lines

  1. /*->c.testecvt */
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. /* Definition of ecvt() -- this is not in the ANSI library; this code will
  7.    certainly not be as efficient as the library version */
  8. static char *ecvt(double x, int ndig, int *dec, int *sign)
  9. {
  10.   static char * result = "----+----+-";
  11.   char *buf1 = "----+----+----+--";
  12.   char *buf2 = "----+----+-";
  13.   sprintf(buf1,"%- #017.*e", ndig-1, x);
  14.   strcpy(result, strtok(buf1, "-+ .e"));
  15.   if((buf2 = strtok(NULL, "-+ .e")) != NULL) strcat(result, buf2);
  16.   if(x < 0.0) *sign = 0;
  17.   else *sign = 1;
  18.   *dec = 1;
  19.   return(result);
  20. }
  21.  
  22. int main()
  23. {
  24.   int dec, sign;
  25.  
  26.   printf("%s \n", ecvt(3.14159265432, 10, &dec, &sign));
  27.   printf("%s \n", ecvt(-3.14159265432, 10, &dec, &sign));
  28.   printf("%s \n", ecvt(3.0, 10, &dec, &sign));
  29.   printf("%s \n", ecvt(-3.0, 10, &dec, &sign));
  30.   printf("%s \n", ecvt(0.0, 10, &dec, &sign));
  31.   printf("%s \n", ecvt(314159.265432, 10, &dec, &sign));
  32.   printf("%s \n", ecvt(3.14159265432, 3, &dec, &sign));
  33.   printf("%s \n", ecvt(-3.14159265432, 4, &dec, &sign));
  34.   printf("%s \n", ecvt(3.0, 5, &dec, &sign));
  35.   printf("%s \n", ecvt(-3.0, 6, &dec, &sign));
  36.   printf("%s \n", ecvt(0.0, 7, &dec, &sign));
  37.   printf("%s \n", ecvt(314159.265432, 8, &dec, &sign));
  38. }
  39.