Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67362 - trunk/boost/math/special_functions
From: pbristow_at_[hidden]
Date: 2010-12-20 10:16:20


Author: pbristow
Date: 2010-12-20 10:16:19 EST (Mon, 20 Dec 2010)
New Revision: 67362
URL: http://svn.boost.org/trac/boost/changeset/67362

Log:
Add comment after assert for integer template type
Text files modified:
   trunk/boost/math/special_functions/factorials.hpp | 21 ++++++++++++++-------
   1 files changed, 14 insertions(+), 7 deletions(-)

Modified: trunk/boost/math/special_functions/factorials.hpp
==============================================================================
--- trunk/boost/math/special_functions/factorials.hpp (original)
+++ trunk/boost/math/special_functions/factorials.hpp 2010-12-20 10:16:19 EST (Mon, 20 Dec 2010)
@@ -1,4 +1,4 @@
-// Copyright John Maddock 2006.
+// Copyright John Maddock 2006, 2010.
 // 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)
@@ -31,6 +31,13 @@
 inline T factorial(unsigned i, const Policy& pol)
 {
    BOOST_STATIC_ASSERT(!boost::is_integral<T>::value);
+ // factorial<unsigned int>(n) is not implemented
+ // because it would overflow integral type T for too small n
+ // to be useful. Use instead a floating-point type,
+ // and convert to an unsigned type if essential, for example:
+ // unsigned int nfac = static_cast<unsigned int>(factorial<double>(n));
+ // See factorial documentation for more detail.
+
    BOOST_MATH_STD_USING // Aid ADL for floor.
 
    if(i <= max_factorial<T>::value)
@@ -78,7 +85,7 @@
          return ceil(unchecked_factorial<T>(i) / (ldexp(T(1), (int)n) * unchecked_factorial<T>(n)) - 0.5f);
       }
       //
- // Fallthrough: i is too large to use table lookup, try the
+ // Fallthrough: i is too large to use table lookup, try the
       // gamma function instead.
       //
       T result = boost::math::tgamma(static_cast<T>(i) / 2 + 1, pol) / sqrt(constants::pi<T>());
@@ -181,7 +188,7 @@
    //
    // Simple case: just the ratio of two
    // (positive argument) gamma functions.
- // Note that we don't optimise this for small n,
+ // Note that we don't optimise this for small n,
    // because tgamma_delta_ratio is alreay optimised
    // for that use case:
    //
@@ -191,7 +198,7 @@
 } // namespace detail
 
 template <class RT>
-inline typename tools::promote_args<RT>::type
+inline typename tools::promote_args<RT>::type
    falling_factorial(RT x, unsigned n)
 {
    typedef typename tools::promote_args<RT>::type result_type;
@@ -200,7 +207,7 @@
 }
 
 template <class RT, class Policy>
-inline typename tools::promote_args<RT>::type
+inline typename tools::promote_args<RT>::type
    falling_factorial(RT x, unsigned n, const Policy& pol)
 {
    typedef typename tools::promote_args<RT>::type result_type;
@@ -209,7 +216,7 @@
 }
 
 template <class RT>
-inline typename tools::promote_args<RT>::type
+inline typename tools::promote_args<RT>::type
    rising_factorial(RT x, int n)
 {
    typedef typename tools::promote_args<RT>::type result_type;
@@ -218,7 +225,7 @@
 }
 
 template <class RT, class Policy>
-inline typename tools::promote_args<RT>::type
+inline typename tools::promote_args<RT>::type
    rising_factorial(RT x, int n, const Policy& pol)
 {
    typedef typename tools::promote_args<RT>::type result_type;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk