[Gnucash-changes] r13751 - gnucash/trunk/src/doc - Move example
from gnc_numeric.h to a separate Doxygen file.
Neil Williams
codehelp at cvs.gnucash.org
Fri Apr 7 14:52:52 EDT 2006
Author: codehelp
Date: 2006-04-07 14:52:51 -0400 (Fri, 07 Apr 2006)
New Revision: 13751
Trac: http://svn.gnucash.org/trac/changeset/13751
Added:
gnucash/trunk/src/doc/gnc-numeric-example.txt
Log:
Move example from gnc_numeric.h to a separate Doxygen file.
Added: gnucash/trunk/src/doc/gnc-numeric-example.txt
===================================================================
--- gnucash/trunk/src/doc/gnc-numeric-example.txt 2006-04-07 18:52:28 UTC (rev 13750)
+++ gnucash/trunk/src/doc/gnc-numeric-example.txt 2006-04-07 18:52:51 UTC (rev 13751)
@@ -0,0 +1,48 @@
+/** \page gncnumericexample gnc_numeric Example
+
+\section example EXAMPLE
+
+The following program finds the best ::gnc_numeric approximation to
+the \a math.h constant \a M_PI given a maximum denominator. For
+large denominators, the ::gnc_numeric approximation is accurate to
+more decimal places than will generally be needed, but in some cases
+this may not be good enough. For example,
+
+ at verbatim
+ M_PI = 3.14159265358979323846
+ 245850922 / 78256779 = 3.14159265358979311599 (16 sig figs)
+ 3126535 / 995207 = 3.14159265358865047446 (12 sig figs)
+ 355 / 113 = 3.14159292035398252096 (7 sig figs)
+ at endverbatim
+
+ at verbatim
+#include <glib.h>
+#include <qof.h>
+#include <math.h>
+
+int
+main(int argc, char ** argv)
+{
+ gnc_numeric approx, best;
+ double err, best_err=1.0;
+ double m_pi = M_PI;
+ gint64 denom;
+ gint64 max;
+
+ sscanf(argv[1], "%Ld", &max);
+
+ for (denom = 1; denom < max; denom++)
+ {
+ approx = double_to_gnc_numeric (m_pi, denom, GNC_RND_ROUND);
+ err = m_pi - gnc_numeric_to_double (approx);
+ if (fabs (err) < fabs (best_err))
+ {
+ best = approx;
+ best_err = err;
+ printf ("%Ld / %Ld = %.30f\n", gnc_numeric_num (best),
+ gnc_numeric_denom (best), gnc_numeric_to_double (best));
+ }
+ }
+}
+ at endverbatim
+*/
More information about the gnucash-changes
mailing list