1 // Compute decimal Archimedes' constant Pi to arbitrary accuracy.
3 #include <cln/output.h>
5 #include <cln/real_io.h>
6 #include <cln/version.h>
18 os << "Usage: pi [digits]\n";
19 os << "Compute decimal Archimedes' constant Pi to arbitrary accuracy.\n\n";
20 os << " --help display this help and exit\n";
21 os << " --version output version information and exit\n";
22 os << " --bibliography output recommended readings and exit\n";
26 main (int argc, char * argv[])
30 if (argc == 2 && !strcmp(argv[1],"--help")) {
34 if (argc == 2 && !strcmp(argv[1],"--version")) {
36 << version_major << "." << version_minor << "." << version_patchlevel
38 cout << "Written by Bruno Haible and Richard B. Kreckel." << endl;
40 cout << "Copyright (C) 1988-2008 Bruno Haible, 2000-2008 Richard B. Kreckel." << endl;
41 cout << "This is free software; see the source for copying conditions. There is NO" << endl;
42 cout << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << endl;
46 if (argc == 2 && !strcmp(argv[1],"--bibliography")) {
47 cout << "Recommended readings:\n";
48 cout << "\"Pi\", by Joerg Arndt and Christoph Haenel (1999)\n";
49 cout << "\"Pi: A Source Book\" by Lennart Berggren, Jonathan Borwein, Peter Borwein (1997)" << endl;
52 if (argc == 2 && isdigit(argv[1][0])) {
53 digits = atol(argv[1]);
61 cl_F p = pi(float_format(digits));
62 // make CLN believe this number has default_float_format to suppress
63 // exponent marker which would be quite boring for 3.1416...
65 cpf.default_float_format = float_format(p);
66 // We cannot print directly because people get dazed and confused
67 // when they see gratuitous digits (Debian Bug #286266.) And we
68 // must not "fix" the output routine because print-read consistency
69 // is at stake. As a workaround, print into a buffer so we can chop
70 // off characters from its end.
72 print_real(buf, cpf, p);
73 istreambuf_iterator<char> i = buf.rdbuf();