Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7643 views
1
#include "mupdf/fitz.h"
2
3
/*
4
* compute decimal integer m, exp such that:
5
* f = m*10^exp
6
* m is as short as possible with losing exactness
7
* assumes special cases (NaN, +Inf, -Inf) have been handled.
8
*/
9
void
10
fz_ftoa(float f, char *s, int *exp, int *neg, int *ns)
11
{
12
char buf[40], *p = buf;
13
int i;
14
15
for (i = 0; i < 10; ++i)
16
{
17
sprintf(buf, "%.*e", i, f);
18
if (fz_atof(buf) == f)
19
break;
20
}
21
22
if (*p == '-')
23
{
24
*neg = 1;
25
++p;
26
}
27
else
28
*neg = 0;
29
30
*ns = 0;
31
while (*p && *p != 'e')
32
{
33
if (*p >= '0' && *p <= '9')
34
{
35
*ns += 1;
36
*s++ = *p;
37
}
38
++p;
39
}
40
41
*exp = fz_atoi(p+1) - (*ns) + 1;
42
}
43
44