media-gfx/cgal-ipelets: Add cgal-ipelets-5.6
[shuber-gentoo-overlay.git] / media-gfx / ipe / files / ipe-outputprecision.patch
index eb257021c34cecb5055360e76db0e705d56a0909..2d1b66ae5f842fcce65e0187e382bc1b53bb5ff2 100644 (file)
@@ -1,8 +1,8 @@
-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)
+diff --git a/ipelib/ipebase.cpp b/ipelib/ipebase.cpp
+index 63de035..19226ad 100644
+--- a/ipelib/ipebase.cpp
++++ b/ipelib/ipebase.cpp
+@@ -557,55 +557,50 @@ Stream &Stream::operator<<(int i)
  //! Output double.
  Stream &Stream::operator<<(double d)
  {
@@ -10,7 +10,19 @@ index 63de035..f4f102e 100644
 -  if (d < 0.0) {
 -    putChar('-');
 -    d = -d;
--  }
++  // Maximum number of digits in total
++  const unsigned maxdigits=14;
++
++  const unsigned bufsize=511;
++  char buf[bufsize+1];
++
++  // The number of digits left of '.'
++  int intpartsize = 0;
++  if( fabs(d)>=1.0 )
++  {
++    snprintf(buf, bufsize, "%.0f", fabs(d));
++    intpartsize = strlen(buf);
+   }
 -  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.
@@ -53,10 +65,36 @@ index 63de035..f4f102e 100644
 -      putChar('0' + v / mask);
 -      v = (10 * v) % factor;
 -      }
--    }
--  }
-+  char buf[101];
-+  std::snprintf(buf, 100, "%.20g", d);
++
++  // The nubmer of digits right of '.'
++  int respartsize = maxdigits-intpartsize;
++  if( respartsize < 0 )
++    respartsize = 0;
++
++  // Building the format string and get the string conversion of d
++  char fmt[256];
++  snprintf(fmt, 255, "%%%d.%df", intpartsize, respartsize);
++  snprintf(buf, bufsize, fmt, d);
++
++
++  // Truncate redundant zeros and '.' from the right
++  for(int i = strlen(buf)-1; i>=intpartsize; i--)
++  {
++    // Truncate all zeros from right-hand
++    if( buf[i] == '0' )
++    {
++      buf[i] = '\0';
++      continue;
+     }
++
++    // Remove decimal dot without decimal digits
++    if( buf[i] == '.' )
++      buf[i] = '\0';
++
++    break;
+   }
++
++
 +  putCString(buf);
    return *this;
  }