ipe-7.0.11: add prec patch
[shuber-gentoo-overlay.git] / media-gfx / ipe / files / ipe-outputprecision.patch
1 diff --git a/src/ipelib/ipebase.cpp b/src/ipelib/ipebase.cpp
2 index 63de035..f4f102e 100644
3 --- a/src/ipelib/ipebase.cpp
4 +++ b/src/ipelib/ipebase.cpp
5 @@ -557,55 +557,9 @@ Stream &Stream::operator<<(int i)
6 //! Output double.
7 Stream &Stream::operator<<(double d)
8 {
9 - char buf[30];
10 - if (d < 0.0) {
11 - putChar('-');
12 - d = -d;
13 - }
14 - if (d >= 1e9) {
15 - // PDF will not be able to read this, but we have to write something.
16 - // Such large numbers should only happen if something is wrong.
17 - std::sprintf(buf, "%g", d);
18 - putCString(buf);
19 - } else if (d < 1e-8) {
20 - putChar('0');
21 - } else {
22 - // Print six significant digits, but omit trailing zeros.
23 - // Probably I'll want to have adjustable precision later.
24 - int factor;
25 - if (d > 1000.0)
26 - factor = 100L;
27 - else if (d > 100.0)
28 - factor = 1000L;
29 - else if (d > 10.0)
30 - factor = 10000L;
31 - else if (d > 1.0)
32 - factor = 100000L;
33 - else if (d > 0.1)
34 - factor = 1000000L;
35 - else if (d > 0.01)
36 - factor = 10000000L;
37 - else
38 - factor = 100000000L;
39 - double dd = trunc(d);
40 - int intpart = int(dd + 0.5);
41 - // 10^9 < 2^31
42 - int v = int(factor * (d - dd) + 0.5);
43 - if (v >= factor) {
44 - ++intpart;
45 - v -= factor;
46 - }
47 - std::sprintf(buf, "%d", intpart);
48 - putCString(buf);
49 - int mask = factor / 10;
50 - if (v != 0) {
51 - putChar('.');
52 - while (v != 0) {
53 - putChar('0' + v / mask);
54 - v = (10 * v) % factor;
55 - }
56 - }
57 - }
58 + char buf[101];
59 + std::snprintf(buf, 100, "%.20g", d);
60 + putCString(buf);
61 return *this;
62 }
63