]> www.ginac.de Git - cln.git/commitdiff
* examples/pi.cc and examples/pi.1: New files.
authorRichard Kreckel <kreckel@ginac.de>
Sun, 2 May 2004 19:47:33 +0000 (19:47 +0000)
committerRichard Kreckel <kreckel@ginac.de>
Sun, 2 May 2004 19:47:33 +0000 (19:47 +0000)
* examples/Makefile.in: Build the pi executable.

ChangeLog
examples/Makefile.in
examples/pi.1 [new file with mode: 0644]
examples/pi.cc [new file with mode: 0644]

index f78520fdbd095977440efbc4a4295acd66e69cdc..78a1ce61c51271b3c22977f9fb621cd3276c3730 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-05-02  Richard B. Kreckel  <kreckel@ginac.de>
+
+       * examples/pi.cc and examples/pi.1: New files.
+       * examples/Makefile.in: Build the pi executable.
+
 2004-05-01  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        * src/Makefile.in: Fix for parallel build: wait for subdir objects to
index 51fb7223c0d06f4d77a15e962fe07dbf7ad58e72..a69ec789c401f9de4d2bdde739bb7abcdc4a130c 100644 (file)
@@ -50,7 +50,7 @@ OBJECTS = $(FILES_O)
 LIBS = ../src/libcln.la -lm
 LIBDEPS = ../src/libcln.la
 
-PROGRAMS = contfrac e fibonacci legendre lucaslehmer nextprime perfnum
+PROGRAMS = contfrac e fibonacci legendre lucaslehmer nextprime perfnum pi
 MODULES_contfrac = contfrac
 MODULES_e = e
 MODULES_fibonacci = fibonacci
@@ -58,8 +58,9 @@ MODULES_legendre = legendre
 MODULES_lucaslehmer = lucaslehmer
 MODULES_nextprime = nextprime
 MODULES_perfnum = perfnum
+MODULES_pi = pi
 
-all : contfrac e fibonacci legendre lucaslehmer nextprime perfnum
+all : contfrac e fibonacci legendre lucaslehmer nextprime perfnum pi
 
 %.s : %.c
        $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -S $< -o $@
@@ -86,6 +87,7 @@ legendre : $(patsubst %,%.o,$(MODULES_legendre))
 lucaslehmer : $(patsubst %,%.o,$(MODULES_lucaslehmer))
 nextprime : $(patsubst %,%.o,$(MODULES_nextprime))
 perfnum : $(patsubst %,%.o,$(MODULES_perfnum))
+pi : $(patsubst %,%.o,$(MODULES_pi))
 $(PROGRAMS) : % : $(LIBDEPS)
        $(LIBTOOL_LINK) $(CXX) $(CXXFLAGS) $(TARGET_ARCH) $(patsubst %,%.o,$(MODULES_$(*F))) $(LDFLAGS) $(LIBS) -o $@
 
diff --git a/examples/pi.1 b/examples/pi.1
new file mode 100644 (file)
index 0000000..fb412d8
--- /dev/null
@@ -0,0 +1,29 @@
+.TH PI 1
+.SH NAME
+pi \- compute decimal Archimedes' constant Pi to arbitrary accuracy.
+.SH SYNOPSIS
+.B pi
+.I "[digits]"
+.br
+.SH "DESCRIPTION"
+The
+.BR pi 
+command prints 100 decimal digits of Archimedes' constant pi or
+a number of digits specified by an integer parameter on the command
+line.
+.TP
+.B \-\-help
+Show summary of options.
+.TP
+.B \-\-version
+Show version of program and exit.
+.TP
+.B \-\-bibliography
+Output recommended readings and exit.
+.SH "SEE ALSO"
+The CLN library is documented fully by
+.IR "cln" ,
+available via the Info system.
+.SH AUTHOR
+CLN was written by Bruno Haible <haible@gnu.org> and is 
+maintained by Richard Kreckel <kreckel@ginac.de>.
diff --git a/examples/pi.cc b/examples/pi.cc
new file mode 100644 (file)
index 0000000..f91a912
--- /dev/null
@@ -0,0 +1,65 @@
+// Compute decimal Archimedes' constant Pi to arbitrary accuracy.
+
+#include <cln/output.h>
+#include <cln/real.h>
+#include <cln/real_io.h>
+#include <ctype.h>
+#include <stdlib.h>
+//#include <string.h>
+
+using namespace std;
+using namespace cln;
+
+static void
+usage (ostream &os)
+{
+       os << "Usage: pi [digits]\n";
+       os << "Compute decimal Archimedes' constant Pi to arbitrary accuracy.\n\n";
+       os << "      --help                 display this help and exit\n";
+       os << "      --version              output version information and exit\n";
+       os << "      --bibliography         output recommended readings and exit\n";
+}
+
+int
+main (int argc, char * argv[])
+{
+       int digits = 100;
+       if (argc > 1) {
+               if (argc == 2 && !strcmp(argv[1],"--help")) {
+                       usage(cout);
+                       return 0;
+               }
+               if (argc == 2 && !strcmp(argv[1],"--version")) {
+                       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 << "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;
+                       return 0;
+               }
+               if (argc == 2 && !strcmp(argv[1],"--bibliography")) {
+                       cout << "Recommended readings:\n";
+                       cout << "\"Pi\", by Joerg Arndt and Christoph Haenel (1999)\n";
+                       cout << "\"Pi: A Source Book\" by Lennart Berggren, Jonathan Borwein, Peter Borwein (1997)" << endl;
+                       return 0;
+               }
+               if (argc == 2 && isdigit(argv[1][0])) {
+                       digits = atoi(argv[1]);
+               } else {
+                       usage(cerr);
+                       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);
+       cout << endl;
+       
+       return 0;
+}