summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/string.h4
-rw-r--r--source/fitz/ftoa.c36
-rw-r--r--source/fitz/printf.c16
3 files changed, 15 insertions, 41 deletions
diff --git a/include/mupdf/fitz/string.h b/include/mupdf/fitz/string.h
index 010dc46a..0c1789bc 100644
--- a/include/mupdf/fitz/string.h
+++ b/include/mupdf/fitz/string.h
@@ -108,11 +108,11 @@ int fz_runelen(int rune);
double fz_strtod(const char *s, char **es);
/*
- fz_ftoa: Compute decimal integer m, exp such that:
+ fz_grisu: Compute decimal integer m, exp such that:
f = m * 10^exp
m is as short as possible without losing exactness
Assumes special cases (NaN, +Inf, -Inf) have been handled.
*/
-void fz_ftoa(float f, char *s, int *exp, int *neg, int *ns);
+int fz_grisu(float f, char *s, int *exp);
#endif
diff --git a/source/fitz/ftoa.c b/source/fitz/ftoa.c
index eb6f750b..d58cfce9 100644
--- a/source/fitz/ftoa.c
+++ b/source/fitz/ftoa.c
@@ -17,38 +17,6 @@
http://florian.loitsch.com/publications/bench.tar.gz?attredirects=0
*/
-static int grisu2(float v, char* buffer, int* K);
-
-/*
- * compute decimal integer m, exp such that:
- * f = m*10^exp
- * m is as short as possible without losing exactness
- * assumes special cases (NaN, +Inf, -Inf) have been handled.
- */
-void
-fz_ftoa(float f, char *s, int *exp, int *neg, int *ns)
-{
- /* Handle zero. */
- if (f == 0)
- {
- /* f is either +0 or -0. */
- *neg = 0;
- *exp = 0;
- *ns = 1;
- s[0] = '0';
- s[1] = 0;
- return;
- }
-
- if (f > 0)
- *neg = 0;
- else
- *neg = 1;
-
- *ns = grisu2(f, s, exp);
- return;
-}
-
/*
Copyright (c) 2009 Florian Loitsch
@@ -303,8 +271,8 @@ digit_gen_mix_grisu2(diy_fp_t D_upper, diy_fp_t delta, char* buffer, int* K)
return len;
}
-static int
-grisu2(float v, char* buffer, int* K)
+int
+fz_grisu(float v, char* buffer, int* K)
{
diy_fp_t w_lower, w_upper, D_upper, D_lower, c_mk, delta;
int length, mk, alpha = -DIY_SIGNIFICAND_SIZE + 4;
diff --git a/source/fitz/printf.c b/source/fitz/printf.c
index dcc89952..baa1aa3a 100644
--- a/source/fitz/printf.c
+++ b/source/fitz/printf.c
@@ -23,17 +23,23 @@ static void fmtputc(struct fmtbuf *out, int c)
static void fmtfloat(struct fmtbuf *out, float f)
{
char digits[40], *s = digits;
- int exp, neg, ndigits, point;
+ int exp, ndigits, point;
if (isnan(f)) f = 0;
if (isinf(f)) f = f < 0 ? -FLT_MAX : FLT_MAX;
- fz_ftoa(f, digits, &exp, &neg, &ndigits);
- point = exp + ndigits;
-
- if (neg)
+ if (signbit(f))
fmtputc(out, '-');
+ if (f == 0)
+ {
+ fmtputc(out, '0');
+ return;
+ }
+
+ ndigits = fz_grisu(f, digits, &exp);
+ point = exp + ndigits;
+
if (point <= 0)
{
fmtputc(out, '.');