forked from genialis/gotea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatters.cpp
51 lines (47 loc) · 810 Bytes
/
formatters.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifdef TEST
# include<stdio.h>
# include<stdlib.h>
# include<string.h>
#endif
/* handles only unsigned integers up to 1e9 */
static int size_to_string(char *where, size_t what)
{
static const size_t lims[]={
1,
10,
100,
1000,
10000,
100000,
1000000,
10000000,
100000000,
1000000000
};
int lim,i;
for (lim=0;lims[lim+1]<=what;lim++) ;
for (i=0;lim>=0;i++)
{
where[i]=what/lims[lim]+'0';
what%=lims[lim];
lim--;
}
return i;
}
#include"dtoa_milo.h"
static inline int double_to_string(char *where, double what)
{
return dtoa_milo(what,where);
}
#ifdef TEST
int main()
{
char buf1[20],buf2[20];
for (int i=0;i<=1000000000;i++)
{
sprintf(buf1,"%d",i);
buf2[ size_to_string(buf2,(size_t)i) ]=0;
if (strcmp(buf1,buf2)) { printf("%s -- %s\n",buf1,buf2); }
}
}
#endif