]> www.ginac.de Git - cln.git/commitdiff
On popular demand (Debian bug #286266, Ubuntu bug #128851):
authorRichard Kreckel <kreckel@ginac.de>
Mon, 1 Oct 2007 22:47:50 +0000 (22:47 +0000)
committerRichard Kreckel <kreckel@ginac.de>
Mon, 1 Oct 2007 22:47:50 +0000 (22:47 +0000)
* examples/pi.cc: Output no more than requested number of digits.

ChangeLog
examples/pi.cc

index 04fb2149071687eb7158845ab3c73c79d62cd4f0..8ab639c316dba34672811a51fc2c77ee79bba42d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-10-02  Richard B. Kreckel  <kreckel@ginac.de>
+
+       On popular demand (Debian bug #286266, Ubuntu bug #128851):
+       * examples/pi.cc: Output no more than requested number of digits.
+
 2007-10-01  Richard B. Kreckel  <kreckel@ginac.de>
 
        * autoconf/config.guess, autoconf/config.sub: updated from automake-1.9.
index 815aea4d07b852f74c209d4bc7f00f658ce6e2c7..93bcbfcec77e3005556d5b2a099f4455ef16ea69 100644 (file)
@@ -6,6 +6,7 @@
 #include <cctype>
 #include <cstdlib>
 #include <cstring>
+#include <sstream>
 
 using namespace std;
 using namespace cln;
@@ -33,7 +34,7 @@ main (int argc, char * argv[])
                        cout << "pi (cln) " << CL_VERSION_MAJOR << "." << CL_VERSION_MINOR << endl;
                        cout << "Written by Bruno Haible." << endl;
                        cout << endl;
-                       cout << "Copyright (C) 1998-2001 Bruno Haible." << endl;
+                       cout << "Copyright (C) 1998-2007 Bruno Haible, 2000-2007 Richard B. Kreckel." << endl;
                        cout << "This is free software; see the source for copying conditions.  There is NO" << endl;
                        cout << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << endl;
                        cout << endl;
@@ -52,14 +53,25 @@ main (int argc, char * argv[])
                        return 1;
                }
        }
-       
-       cl_F p = pi(float_format(digits));
-       // make CLN believe this number has default_float_format to suppress
-       // exponent marker which would be quite boring for 3.1416...
-       cl_print_flags cpf;
-       cpf.default_float_format = float_format(p);
-       print_real(cout, cpf, p);
+
+       if (digits) {
+               cl_F p = pi(float_format(digits));
+               // make CLN believe this number has default_float_format to suppress
+               // exponent marker which would be quite boring for 3.1416...
+               cl_print_flags cpf;
+               cpf.default_float_format = float_format(p);
+               // We cannot print directly because people get dazed and confused
+               // when they see gratuitous digits (Debian Bug #286266.) And we
+               // must not "fix" the output routine because print-read consistency
+               // is at stake. As a workaround, print into a buffer so we can chop
+               // off characters from its end.
+               stringstream buf;
+               print_real(buf, cpf, p);
+               istreambuf_iterator<char> i = buf.rdbuf();
+               while (--digits+2>0)
+                       cout << *(i++);
+       }
        cout << endl;
-       
+
        return 0;
 }