DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
// Copyright John Maddock 2006. // 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) #ifndef BOOST_MATH_SP_FACTORIALS_HPP #define BOOST_MATH_SP_FACTORIALS_HPP #include
#include
#include
#include
#ifdef BOOST_MSVC #pragma warning(push) // Temporary until lexical cast fixed. #pragma warning(disable: 4127 4701) #endif #include
#ifdef BOOST_MSVC #pragma warning(pop) #endif #include
namespace boost { namespace math { template
inline T factorial(unsigned i, const Policy& pol) { BOOST_MATH_STD_USING // Aid ADL for floor. if(i <= max_factorial
::value) return unchecked_factorial
(i); T result = boost::math::tgamma(static_cast
(i+1), pol); if(result > tools::max_value
()) return result; // Overflowed value! (But tgamma will have signalled the error already). return floor(result + 0.5f); } template
inline T factorial(unsigned i) { return factorial
(i, policies::policy<>()); } /* // Can't have these in a policy enabled world? template<> inline float factorial
(unsigned i) { if(i <= max_factorial
::value) return unchecked_factorial
(i); return tools::overflow_error
(BOOST_CURRENT_FUNCTION); } template<> inline double factorial
(unsigned i) { if(i <= max_factorial
::value) return unchecked_factorial
(i); return tools::overflow_error
(BOOST_CURRENT_FUNCTION); } */ template
T double_factorial(unsigned i, const Policy& pol) { BOOST_MATH_STD_USING // ADL lookup of std names if(i & 1) { // odd i: if(i < max_factorial
::value) { unsigned n = (i - 1) / 2; return ceil(unchecked_factorial
(i) / (ldexp(T(1), (int)n) * unchecked_factorial
(n)) - 0.5f); } // // Fallthrough: i is too large to use table lookup, try the // gamma function instead. // T result = boost::math::tgamma(static_cast
(i) / 2 + 1, pol) / sqrt(constants::pi
()); if(ldexp(tools::max_value
(), -static_cast
(i+1) / 2) > result) return ceil(result * ldexp(T(1), (i+1) / 2) - 0.5f); } else { // even i: unsigned n = i / 2; T result = factorial
(n, pol); if(ldexp(tools::max_value
(), -(int)n) > result) return result * ldexp(T(1), (int)n); } // // If we fall through to here then the result is infinite: // return policies::raise_overflow_error
("boost::math::double_factorial<%1%>(unsigned)", 0, pol); } template
inline T double_factorial(unsigned i) { return double_factorial
(i, policies::policy<>()); } namespace detail{ template
T rising_factorial_imp(T x, int n, const Policy& pol) { if(x < 0) { // // For x less than zero, we really have a falling // factorial, modulo a possible change of sign. // // Note that the falling factorial isn't defined // for negative n, so we'll get rid of that case // first: // bool inv = false; if(n < 0) { x += n; n = -n; inv = true; } T result = ((n&1) ? -1 : 1) * falling_factorial(-x, n, pol); if(inv) result = 1 / result; return result; } if(n == 0) return 1; // // We don't optimise this for small n, because // tgamma_delta_ratio is alreay optimised for that // use case: // return 1 / boost::math::tgamma_delta_ratio(x, static_cast
(n), pol); } template
inline T falling_factorial_imp(T x, unsigned n, const Policy& pol) { BOOST_MATH_STD_USING // ADL of std names if(x == 0) return 0; if(x < 0) { // // For x < 0 we really have a rising factorial // modulo a possible change of sign: // return (n&1 ? -1 : 1) * rising_factorial(-x, n, pol); } if(n == 0) return 1; if(x < n-1) { // // x+1-n will be negative and tgamma_delta_ratio won't // handle it, split the product up into three parts: // T xp1 = x + 1; unsigned n2 = tools::real_cast
(floor(xp1)); if(n2 == xp1) return 0; T result = boost::math::tgamma_delta_ratio(xp1, -static_cast
(n2), pol); x -= n2; result *= x; ++n2; if(n2 < n) result *= falling_factorial(x - 1, n - n2, pol); return result; } // // Simple case: just the ratio of two // (positive argument) gamma functions. // Note that we don't optimise this for small n, // because tgamma_delta_ratio is alreay optimised // for that use case: // return boost::math::tgamma_delta_ratio(x + 1, -static_cast
(n), pol); } } // namespace detail template
inline typename tools::promote_args
::type falling_factorial(RT x, unsigned n) { typedef typename tools::promote_args
::type result_type; return detail::falling_factorial_imp( static_cast
(x), n, policies::policy<>()); } template
inline typename tools::promote_args
::type falling_factorial(RT x, unsigned n, const Policy& pol) { typedef typename tools::promote_args
::type result_type; return detail::falling_factorial_imp( static_cast
(x), n, pol); } template
inline typename tools::promote_args
::type rising_factorial(RT x, int n) { typedef typename tools::promote_args
::type result_type; return detail::rising_factorial_imp( static_cast
(x), n, policies::policy<>()); } template
inline typename tools::promote_args
::type rising_factorial(RT x, int n, const Policy& pol) { typedef typename tools::promote_args
::type result_type; return detail::rising_factorial_imp( static_cast
(x), n, pol); } } // namespace math } // namespace boost #endif // BOOST_MATH_SP_FACTORIALS_HPP
factorials.hpp
Page URL
File URL
Prev
19/35
Next
Download
( 6 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.