ipe-7.0.11: add prec patch
[shuber-gentoo-overlay.git] / media-gfx / ipe / files / ipe-outputprecision.patch
diff --git a/media-gfx/ipe/files/ipe-outputprecision.patch b/media-gfx/ipe/files/ipe-outputprecision.patch
new file mode 100644 (file)
index 0000000..eb25702
--- /dev/null
@@ -0,0 +1,63 @@
+diff --git a/src/ipelib/ipebase.cpp b/src/ipelib/ipebase.cpp
+index 63de035..f4f102e 100644
+--- a/src/ipelib/ipebase.cpp
++++ b/src/ipelib/ipebase.cpp
+@@ -557,55 +557,9 @@ Stream &Stream::operator<<(int i)
+ //! Output double.
+ Stream &Stream::operator<<(double d)
+ {
+-  char buf[30];
+-  if (d < 0.0) {
+-    putChar('-');
+-    d = -d;
+-  }
+-  if (d >= 1e9) {
+-    // PDF will not be able to read this, but we have to write something.
+-    // Such large numbers should only happen if something is wrong.
+-    std::sprintf(buf, "%g", d);
+-    putCString(buf);
+-  } else if (d < 1e-8) {
+-    putChar('0');
+-  } else {
+-    // Print six significant digits, but omit trailing zeros.
+-    // Probably I'll want to have adjustable precision later.
+-    int factor;
+-    if (d > 1000.0)
+-      factor = 100L;
+-    else if (d > 100.0)
+-      factor = 1000L;
+-    else if (d > 10.0)
+-      factor = 10000L;
+-    else if (d > 1.0)
+-      factor = 100000L;
+-    else if (d > 0.1)
+-      factor = 1000000L;
+-    else if (d > 0.01)
+-      factor = 10000000L;
+-    else
+-      factor = 100000000L;
+-    double dd = trunc(d);
+-    int intpart = int(dd + 0.5);
+-    // 10^9 < 2^31
+-    int v = int(factor * (d - dd) + 0.5);
+-    if (v >= factor) {
+-      ++intpart;
+-      v -= factor;
+-    }
+-    std::sprintf(buf, "%d", intpart);
+-    putCString(buf);
+-    int mask = factor / 10;
+-    if (v != 0) {
+-      putChar('.');
+-      while (v != 0) {
+-      putChar('0' + v / mask);
+-      v = (10 * v) % factor;
+-      }
+-    }
+-  }
++  char buf[101];
++  std::snprintf(buf, 100, "%.20g", d);
++  putCString(buf);
+   return *this;
+ }