diff --git a/doc/gcd/Jamfile.v2 b/doc/gcd/Jamfile.v2 new file mode 100644 index 000000000..ac618e771 --- /dev/null +++ b/doc/gcd/Jamfile.v2 @@ -0,0 +1,75 @@ + +# Copyright John Maddock 2005. Use, modification, and distribution are +# subject to the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +using quickbook ; + +path-constant images_location : html ; + +xml math-gcd : math-gcd.qbk ; +boostbook standalone + : + math-gcd + : + # Path for links to Boost: + boost.root=../../../../.. + # Path for libraries index: + boost.libraries=../../../../../libs/libraries.htm + # Use the main Boost stylesheet: + html.stylesheet=../../../../../doc/html/boostbook.css + + # Some general style settings: + table.footnote.number.format=1 + footnote.number.format=1 + + # HTML options first: + # Use graphics not text for navigation: + navig.graphics=1 + # How far down we chunk nested sections, basically all of them: + chunk.section.depth=10 + # Don't put the first section on the same page as the TOC: + chunk.first.sections=1 + # How far down sections get TOC's + toc.section.depth=10 + # Max depth in each TOC: + toc.max.depth=4 + # How far down we go with TOC's + generate.section.toc.level=10 + #root.filename="sf_dist_and_tools" + + # PDF Options: + # TOC Generation: this is needed for FOP-0.9 and later: + # fop1.extensions=1 + pdf:xep.extensions=1 + # TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9! + pdf:fop.extensions=0 + # No indent on body text: + pdf:body.start.indent=0pt + # Margin size: + pdf:page.margin.inner=0.5in + # Margin size: + pdf:page.margin.outer=0.5in + # Paper type = A4 + pdf:paper.type=A4 + # Yes, we want graphics for admonishments: + admon.graphics=1 + # Set this one for PDF generation *only*: + # default pnd graphics are awful in PDF form, + # better use SVG's instead: + pdf:admon.graphics.extension=".svg" + pdf:use.role.for.mediaobject=1 + pdf:preferred.mediaobject.role=print + pdf:img.src.path=$(images_location)/ + pdf:admon.graphics.path=$(images_location)/../../svg-admon/ + ; + + + + + + + + + + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm.html new file mode 100644 index 000000000..2c75532d6 --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm.html @@ -0,0 +1,57 @@ + + + +Greatest Common Divisor and Least Common Multiple + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/compile_time.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/compile_time.html new file mode 100644 index 000000000..cef742efe --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/compile_time.html @@ -0,0 +1,95 @@ + + + +Compile time GCD and LCM determination + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Header: <boost/math/common_factor_ct.hpp> +

+
+template < unsigned long Value1, unsigned long Value2 >
+struct boost::math::static_gcd
+{
+   static unsigned long const  value = implementation_defined;
+};
+
+template < unsigned long Value1, unsigned long Value2 >
+struct boost::math::static_lcm
+{
+   static unsigned long const  value = implementation_defined;
+};
+
+

+ The boost::math::static_gcd and boost::math::static_lcm class templates take + two value-based template parameters of the unsigned long type and have a + single static constant data member, value, of that same type. The value of + that member is the greatest common factor or least common multiple, respectively, + of the template arguments. A compile-time error will occur if the least common + multiple is beyond the range of an unsigned long. +

+

+ + Example +

+
+#include <boost/math/common_factor.hpp>
+#include <algorithm>
+#include <iterator>
+
+
+int main()
+{
+   using std::cout;
+   using std::endl;
+
+   cout << "The GCD and LCM of 6 and 15 are "
+   << boost::math::gcd(6, 15) << " and "
+   << boost::math::lcm(6, 15) << ", respectively."
+   << endl;
+
+   cout << "The GCD and LCM of 8 and 9 are "
+   << boost::math::static_gcd<8, 9>::value
+   << " and "
+   << boost::math::static_lcm<8, 9>::value
+   << ", respectively." << endl;
+
+   int  a[] = { 4, 5, 6 }, b[] = { 7, 8, 9 }, c[3];
+   std::transform( a, a + 3, b, c, boost::math::gcd_evaluator<int>() );
+   std::copy( c, c + 3, std::ostream_iterator<int>(cout, " ") );
+}
+
+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/credits.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/credits.html new file mode 100644 index 000000000..92717eb6c --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/credits.html @@ -0,0 +1,44 @@ + + + +Credits + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHome +
+
+ +

+ The author of the Boost compilation of GCD and LCM computations is Daryle + Walker. The code was prompted by existing code hiding in the implementations + of Paul Moore's rational library and Steve Cleary's pool library. The code + had updates by Helmut Zeisel. +

+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHome +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/demo.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/demo.html new file mode 100644 index 000000000..e1689eb42 --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/demo.html @@ -0,0 +1,46 @@ + + + +Demonstration Program + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The program common_factor_test.cpp + is a demonstration of the results from instantiating various examples of + the run-time GCD and LCM function templates and the compile-time GCD and + LCM class templates. (The run-time GCD and LCM class templates are tested + indirectly through the run-time function templates.) +

+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/gcd_function_object.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/gcd_function_object.html new file mode 100644 index 000000000..e81b093f7 --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/gcd_function_object.html @@ -0,0 +1,71 @@ + + + +GCD Function Object + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Header: <boost/math/common_factor_rt.hpp> +

+
+template < typename IntegerType >
+class boost::math::gcd_evaluator
+{
+public:
+   // Types
+   typedef IntegerType  result_type;
+   typedef IntegerType  first_argument_type;
+   typedef IntegerType  second_argument_type;
+
+   // Function object interface
+   result_type  operator ()( first_argument_type const &a,
+   second_argument_type const &b ) const;
+};
+
+

+ The boost::math::gcd_evaluator class template defines a function object class + to return the greatest common divisor of two integers. The template is parameterized + by a single type, called IntegerType here. This type should be a numeric + type that represents integers. The result of the function object is always + nonnegative, even if either of the operator arguments is negative. +

+

+ This function object class template is used in the corresponding version + of the GCD function template. If a numeric type wants to customize evaluations + of its greatest common divisors, then the type should specialize on the gcd_evaluator + class template. +

+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/header.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/header.html new file mode 100644 index 000000000..c7a6f19c6 --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/header.html @@ -0,0 +1,48 @@ + + + +Header <boost/math/common_factor.hpp> + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ This header simply includes the headers <boost/math/common_factor_ct.hpp> + and <boost/math/common_factor_rt.hpp>. +

+

+ Note this is a legacy header: it used to contain the actual implementation, + but the compile-time and run-time facilities were moved to separate headers + (since they were independent of each other). +

+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/history.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/history.html new file mode 100644 index 000000000..f55f1836d --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/history.html @@ -0,0 +1,50 @@ + + + +History + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
    +
  • + 17 Dec 2005: Converted documentation to Quickbook Format. +
  • +
  • + 2 Jul 2002: Compile-time and run-time items separated to new headers. +
  • +
  • + 7 Nov 2001: Initial version +
  • +
+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/introduction.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/introduction.html new file mode 100644 index 000000000..85cea5bed --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/introduction.html @@ -0,0 +1,45 @@ + + + +Introduction + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The class and function templates in <boost/math/common_factor.hpp> + provide run-time and compile-time evaluation of the greatest common divisor + (GCD) or least common multiple (LCM) of two integers. These facilities are + useful for many numeric-oriented generic programming problems. +

+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/lcm_function_object.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/lcm_function_object.html new file mode 100644 index 000000000..e0952a6c7 --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/lcm_function_object.html @@ -0,0 +1,73 @@ + + + +LCM Function Object + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Header: <boost/math/common_factor_rt.hpp> +

+
+template < typename IntegerType >
+class boost::math::lcm_evaluator
+{
+public:
+   // Types
+   typedef IntegerType  result_type;
+   typedef IntegerType  first_argument_type;
+   typedef IntegerType  second_argument_type;
+
+   // Function object interface
+   result_type  operator ()( first_argument_type const &a,
+   second_argument_type const &b ) const;
+};
+
+

+ The boost::math::lcm_evaluator class template defines a function object class + to return the least common multiple of two integers. The template is parameterized + by a single type, called IntegerType here. This type should be a numeric + type that represents integers. The result of the function object is always + nonnegative, even if either of the operator arguments is negative. If the + least common multiple is beyond the range of the integer type, the results + are undefined. +

+

+ This function object class template is used in the corresponding version + of the LCM function template. If a numeric type wants to customize evaluations + of its least common multiples, then the type should specialize on the lcm_evaluator + class template. +

+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/rationale.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/rationale.html new file mode 100644 index 000000000..154bd74ff --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/rationale.html @@ -0,0 +1,45 @@ + + + +Rationale + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The greatest common divisor and least common multiple functions are greatly + used in some numeric contexts, including some of the other Boost libraries. + Centralizing these functions to one header improves code factoring and eases + maintainence. +

+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/run_time.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/run_time.html new file mode 100644 index 000000000..8f7f7e25a --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/run_time.html @@ -0,0 +1,59 @@ + + + +Run-time GCD & LCM Determination + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Header: <boost/math/common_factor_rt.hpp> +

+
+template < typename IntegerType >
+IntegerType  boost::math::gcd( IntegerType const &a, IntegerType const &b );
+
+template < typename IntegerType >
+IntegerType  boost::math::lcm( IntegerType const &a, IntegerType const &b );
+
+

+ The boost::math::gcd function template returns the greatest common (nonnegative) + divisor of the two integers passed to it. The boost::math::lcm function template + returns the least common (nonnegative) multiple of the two integers passed + to it. The function templates are parameterized on the function arguments' + IntegerType, which is also the return type. Internally, these function templates + use an object of the corresponding version of the gcd_evaluator and lcm_evaluator + class templates, respectively. +

+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/gcd_and_lcm/gcd_lcm/synopsis.html b/doc/gcd/html/gcd_and_lcm/gcd_lcm/synopsis.html new file mode 100644 index 000000000..0fd106c63 --- /dev/null +++ b/doc/gcd/html/gcd_and_lcm/gcd_lcm/synopsis.html @@ -0,0 +1,63 @@ + + + +Synopsis + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+namespace boost
+{
+namespace math
+{
+
+template < typename IntegerType >
+   class gcd_evaluator;
+template < typename IntegerType >
+   class lcm_evaluator;
+
+template < typename IntegerType >
+   IntegerType  gcd( IntegerType const &a, IntegerType const &b );
+template < typename IntegerType >
+   IntegerType  lcm( IntegerType const &a, IntegerType const &b );
+
+template < unsigned long Value1, unsigned long Value2 >
+   struct static_gcd;
+template < unsigned long Value1, unsigned long Value2 >
+   struct static_lcm;
+
+}
+}
+
+
+ + + +
Copyright © 2001 -2002 Daryle Walker
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/gcd/html/index.html b/doc/gcd/html/index.html new file mode 100644 index 000000000..fff3b81a3 --- /dev/null +++ b/doc/gcd/html/index.html @@ -0,0 +1,71 @@ + + + +GCD and LCM + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
Next
+
+
+
+

+GCD and LCM

+

+Daryle Walker +

+
+
+

+ Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +

+
+
+
+
+ +
+ + + +

Last revised: December 29, 2006 at 11:08:32 +0000

+
+
Next
+ + diff --git a/doc/gcd/math-gcd.qbk b/doc/gcd/math-gcd.qbk new file mode 100644 index 000000000..625b2a534 --- /dev/null +++ b/doc/gcd/math-gcd.qbk @@ -0,0 +1,243 @@ +[article GCD and LCM + [quickbook 1.3] + [copyright 2001-2002 Daryle Walker] + [license + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + [@http://www.boost.org/LICENSE_1_0.txt http://www.boost.org/LICENSE_1_0.txt]) + ] + [authors [Walker, Daryle]] + [category math] + [last-revision $Date: 2006-12-29 11:08:32 +0000 (Fri, 29 Dec 2006) $] +] + + +[section:gcd_lcm Greatest Common Divisor and Least Common Multiple] + +[section Introduction] + +The class and function templates in +provide run-time and compile-time evaluation of the greatest common divisor +(GCD) or least common multiple (LCM) of two integers. +These facilities are useful for many numeric-oriented generic +programming problems. + +[endsect] + +[section Synopsis] + + namespace boost + { + namespace math + { + + template < typename IntegerType > + class gcd_evaluator; + template < typename IntegerType > + class lcm_evaluator; + + template < typename IntegerType > + IntegerType gcd( IntegerType const &a, IntegerType const &b ); + template < typename IntegerType > + IntegerType lcm( IntegerType const &a, IntegerType const &b ); + + template < unsigned long Value1, unsigned long Value2 > + struct static_gcd; + template < unsigned long Value1, unsigned long Value2 > + struct static_lcm; + + } + } + +[endsect] + +[section GCD Function Object] + +[*Header: ] [@../../../../../boost/math/common_factor_rt.hpp ] + + template < typename IntegerType > + class boost::math::gcd_evaluator + { + public: + // Types + typedef IntegerType result_type; + typedef IntegerType first_argument_type; + typedef IntegerType second_argument_type; + + // Function object interface + result_type operator ()( first_argument_type const &a, + second_argument_type const &b ) const; + }; + +The boost::math::gcd_evaluator class template defines a function object +class to return the greatest common divisor of two integers. +The template is parameterized by a single type, called IntegerType here. +This type should be a numeric type that represents integers. +The result of the function object is always nonnegative, even if either of +the operator arguments is negative. + +This function object class template is used in the corresponding version of +the GCD function template. If a numeric type wants to customize evaluations +of its greatest common divisors, then the type should specialize on the +gcd_evaluator class template. + +[endsect] + +[section LCM Function Object] + +[*Header: ] [@../../../../../boost/math/common_factor_rt.hpp ] + + template < typename IntegerType > + class boost::math::lcm_evaluator + { + public: + // Types + typedef IntegerType result_type; + typedef IntegerType first_argument_type; + typedef IntegerType second_argument_type; + + // Function object interface + result_type operator ()( first_argument_type const &a, + second_argument_type const &b ) const; + }; + +The boost::math::lcm_evaluator class template defines a function object +class to return the least common multiple of two integers. The template +is parameterized by a single type, called IntegerType here. This type +should be a numeric type that represents integers. The result of the +function object is always nonnegative, even if either of the operator +arguments is negative. If the least common multiple is beyond the range +of the integer type, the results are undefined. + +This function object class template is used in the corresponding version +of the LCM function template. If a numeric type wants to customize +evaluations of its least common multiples, then the type should +specialize on the lcm_evaluator class template. + +[endsect] + +[section:run_time Run-time GCD & LCM Determination] + +[*Header: ] [@../../../../../boost/math/common_factor_rt.hpp ] + + template < typename IntegerType > + IntegerType boost::math::gcd( IntegerType const &a, IntegerType const &b ); + + template < typename IntegerType > + IntegerType boost::math::lcm( IntegerType const &a, IntegerType const &b ); + +The boost::math::gcd function template returns the greatest common +(nonnegative) divisor of the two integers passed to it. +The boost::math::lcm function template returns the least common +(nonnegative) multiple of the two integers passed to it. +The function templates are parameterized on the function arguments' +IntegerType, which is also the return type. Internally, these function +templates use an object of the corresponding version of the +gcd_evaluator and lcm_evaluator class templates, respectively. + +[endsect] + +[section:compile_time Compile time GCD and LCM determination] + +[*Header: ] [@../../../../../boost/math/common_factor_ct.hpp ] + + template < unsigned long Value1, unsigned long Value2 > + struct boost::math::static_gcd + { + static unsigned long const value = implementation_defined; + }; + + template < unsigned long Value1, unsigned long Value2 > + struct boost::math::static_lcm + { + static unsigned long const value = implementation_defined; + }; + +The boost::math::static_gcd and boost::math::static_lcm class templates +take two value-based template parameters of the unsigned long type +and have a single static constant data member, value, of that same type. +The value of that member is the greatest common factor or least +common multiple, respectively, of the template arguments. +A compile-time error will occur if the least common multiple +is beyond the range of an unsigned long. + +[h3 Example] + + #include + #include + #include + + + int main() + { + using std::cout; + using std::endl; + + cout << "The GCD and LCM of 6 and 15 are " + << boost::math::gcd(6, 15) << " and " + << boost::math::lcm(6, 15) << ", respectively." + << endl; + + cout << "The GCD and LCM of 8 and 9 are " + << boost::math::static_gcd<8, 9>::value + << " and " + << boost::math::static_lcm<8, 9>::value + << ", respectively." << endl; + + int a[] = { 4, 5, 6 }, b[] = { 7, 8, 9 }, c[3]; + std::transform( a, a + 3, b, c, boost::math::gcd_evaluator() ); + std::copy( c, c + 3, std::ostream_iterator(cout, " ") ); + } + +[endsect] + +[section:header Header ] + +This header simply includes the headers +[@../../../../../boost/math/common_factor_ct.hpp ] +and [@../../../../../boost/math/common_factor_rt.hpp ]. + +Note this is a legacy header: it used to contain the actual implementation, +but the compile-time and run-time facilities +were moved to separate headers (since they were independent of each other). + +[endsect] + +[section:demo Demonstration Program] + +The program [@../../../../../libs/math/test/common_factor_test.cpp common_factor_test.cpp] is a demonstration of the results from +instantiating various examples of the run-time GCD and LCM function +templates and the compile-time GCD and LCM class templates. +(The run-time GCD and LCM class templates are tested indirectly through +the run-time function templates.) + +[endsect] + +[section Rationale] + +The greatest common divisor and least common multiple functions are +greatly used in some numeric contexts, including some of the other +Boost libraries. Centralizing these functions to one header improves +code factoring and eases maintainence. + +[endsect] + +[section History] + +* 17 Dec 2005: Converted documentation to Quickbook Format. +* 2 Jul 2002: Compile-time and run-time items separated to new headers. +* 7 Nov 2001: Initial version + +[endsect] + +[section Credits] + +The author of the Boost compilation of GCD and LCM computations is +Daryle Walker. The code was prompted by existing code hiding in the +implementations of Paul Moore's rational library and Steve Cleary's +pool library. The code had updates by Helmut Zeisel. + +[endsect] + +[endsect] +