summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/lib/__dtostr.c
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2001-05-14 14:19:32 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2001-05-14 14:19:32 +0000
commit167217bec15c9c7aa70ba2a3dc9c689b3cd91872 (patch)
tree7c0c62debf8f9f145643102fb52b81afce743594 /mdk-stage1/dietlibc/lib/__dtostr.c
parent9097327dc1c667fc51b8e05cc7c0626fac96665d (diff)
downloaddrakx-backup-do-not-use-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.tar
drakx-backup-do-not-use-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.tar.gz
drakx-backup-do-not-use-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.tar.bz2
drakx-backup-do-not-use-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.tar.xz
drakx-backup-do-not-use-167217bec15c9c7aa70ba2a3dc9c689b3cd91872.zip
import new version of dietlibc
Diffstat (limited to 'mdk-stage1/dietlibc/lib/__dtostr.c')
-rw-r--r--mdk-stage1/dietlibc/lib/__dtostr.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/mdk-stage1/dietlibc/lib/__dtostr.c b/mdk-stage1/dietlibc/lib/__dtostr.c
index def091f16..e9a8a83d3 100644
--- a/mdk-stage1/dietlibc/lib/__dtostr.c
+++ b/mdk-stage1/dietlibc/lib/__dtostr.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
/* convert double to string. Helper for sprintf. */
int __dtostr(double d,char *buf,int maxlen,int prec) {
@@ -14,8 +15,14 @@ int __dtostr(double d,char *buf,int maxlen,int prec) {
char *oldbuf=buf;
int initial=1;
+ if (d==0.0) {
+ *buf='0'; ++buf;
+ goto done;
+ }
if (s) { d=-d; *buf='-'; --maxlen; buf++; }
- if ((i=e10)>=0) {
+/* printf("e=%d e10=%d prec=%d\n",e,e10,prec); */
+ if (e10>=0) {
+ i=e10;
while (i>10) { tmp=tmp*1e10; i-=10; }
while (i>1) { tmp=tmp*10; --i; }
} else {
@@ -52,6 +59,20 @@ int __dtostr(double d,char *buf,int maxlen,int prec) {
}
/* step 5: loop through the digits, inserting the decimal point when
* appropriate */
+ if (d<1.0) {
+ double x=1.0;
+ int first=1;
+ do {
+ if (--maxlen<0) return buf-oldbuf;
+ *buf='0'; ++buf;
+ if (first) {
+ first=0;
+ *buf='.'; ++buf;
+ if (--maxlen<0) return buf-oldbuf;
+ }
+ x/=10.0;
+ } while (x>d);
+ }
for (; prec>0; ) {
double tmp2=d/tmp;
char c;
@@ -77,6 +98,7 @@ int __dtostr(double d,char *buf,int maxlen,int prec) {
} else
tmp/=10.0;
}
+done:
*buf=0;
return buf-oldbuf;
}