X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=boost%2Fmath%2Fspecial_functions%2Fdetail%2Funchecked_factorial.hpp;h=4fa1ebff9cc3a2da8d63e927a656925da7ec070e;hb=HEAD;hp=7783e161c4fea3268257bf136adb4a1ea9af9e76;hpb=a95154919f950f86de9104b2b9dcf1f0c7e83387;p=rsem.git diff --git a/boost/math/special_functions/detail/unchecked_factorial.hpp b/boost/math/special_functions/detail/unchecked_factorial.hpp index 7783e16..4fa1ebf 100644 --- a/boost/math/special_functions/detail/unchecked_factorial.hpp +++ b/boost/math/special_functions/detail/unchecked_factorial.hpp @@ -15,7 +15,9 @@ #pragma warning(push) // Temporary until lexical cast fixed. #pragma warning(disable: 4127 4701) #endif +#ifndef BOOST_MATH_NO_LEXICAL_CAST #include +#endif #ifdef BOOST_MSVC #pragma warning(pop) #endif @@ -28,7 +30,7 @@ namespace boost { namespace math template struct max_factorial; -// efinitions: +// Definitions: template <> inline float unchecked_factorial(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(float)) { @@ -279,9 +281,19 @@ struct max_factorial value = ::boost::math::max_factorial::value); }; +#ifndef BOOST_MATH_NO_LEXICAL_CAST + template inline T unchecked_factorial(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) { + BOOST_STATIC_ASSERT(!boost::is_integral::value); + // factorial(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(factorial(n)); + // See factorial documentation for more detail. + static const boost::array factorials = {{ boost::lexical_cast("1"), boost::lexical_cast("1"), @@ -395,6 +407,27 @@ struct max_factorial BOOST_STATIC_CONSTANT(unsigned, value = 100); }; +#else // BOOST_MATH_NO_LEXICAL_CAST + +template +inline T unchecked_factorial(unsigned i BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) +{ + return 1; +} + +template +struct max_factorial +{ + BOOST_STATIC_CONSTANT(unsigned, value = 0); +}; + +#endif + +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +template +const unsigned max_factorial::value; +#endif + } // namespace math } // namespace boost