Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67361 - trunk/boost/math/special_functions/detail
From: pbristow_at_[hidden]
Date: 2010-12-20 10:14:33


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

Log:
Add assert (and comment) for integer template type
Text files modified:
   trunk/boost/math/special_functions/detail/unchecked_factorial.hpp | 10 +++++++++-
   1 files changed, 9 insertions(+), 1 deletions(-)

Modified: trunk/boost/math/special_functions/detail/unchecked_factorial.hpp
==============================================================================
--- trunk/boost/math/special_functions/detail/unchecked_factorial.hpp (original)
+++ trunk/boost/math/special_functions/detail/unchecked_factorial.hpp 2010-12-20 10:14:31 EST (Mon, 20 Dec 2010)
@@ -28,7 +28,7 @@
 template <class T>
 struct max_factorial;
 
-// efinitions:
+// Definitions:
 template <>
 inline float unchecked_factorial<float>(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(float))
 {
@@ -282,6 +282,14 @@
 template <class T>
 inline T unchecked_factorial(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
 {
+ 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.
+
    static const boost::array<T, 101> factorials = {{
       boost::lexical_cast<T>("1"),
       boost::lexical_cast<T>("1"),


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