home *** CD-ROM | disk | FTP | other *** search
- /*->c.testecvt */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- /* Definition of ecvt() -- this is not in the ANSI library; this code will
- certainly not be as efficient as the library version */
- static char *ecvt(double x, int ndig, int *dec, int *sign)
- {
- static char * result = "----+----+-";
- char *buf1 = "----+----+----+--";
- char *buf2 = "----+----+-";
- sprintf(buf1,"%- #017.*e", ndig-1, x);
- strcpy(result, strtok(buf1, "-+ .e"));
- if((buf2 = strtok(NULL, "-+ .e")) != NULL) strcat(result, buf2);
- if(x < 0.0) *sign = 0;
- else *sign = 1;
- *dec = 1;
- return(result);
- }
-
- int main()
- {
- int dec, sign;
-
- printf("%s \n", ecvt(3.14159265432, 10, &dec, &sign));
- printf("%s \n", ecvt(-3.14159265432, 10, &dec, &sign));
- printf("%s \n", ecvt(3.0, 10, &dec, &sign));
- printf("%s \n", ecvt(-3.0, 10, &dec, &sign));
- printf("%s \n", ecvt(0.0, 10, &dec, &sign));
- printf("%s \n", ecvt(314159.265432, 10, &dec, &sign));
- printf("%s \n", ecvt(3.14159265432, 3, &dec, &sign));
- printf("%s \n", ecvt(-3.14159265432, 4, &dec, &sign));
- printf("%s \n", ecvt(3.0, 5, &dec, &sign));
- printf("%s \n", ecvt(-3.0, 6, &dec, &sign));
- printf("%s \n", ecvt(0.0, 7, &dec, &sign));
- printf("%s \n", ecvt(314159.265432, 8, &dec, &sign));
- }
-