x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
bessel.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\math\special_functions\bessel.hpp
旋转
特效
属性
历史版本
// Copyright (c) 2007 John Maddock // 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) // // This header just defines the function entry points, and adds dispatch // to the right implementation method. Most of the implementation details // are in separate headers and copyright Xiaogang Zhang. // #ifndef BOOST_MATH_BESSEL_HPP #define BOOST_MATH_BESSEL_HPP #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace boost{ namespace math{ namespace detail{ template
struct bessel_j_small_z_series_term { typedef T result_type; bessel_j_small_z_series_term(T v_, T x) : N(0), v(v_) { BOOST_MATH_STD_USING mult = x / 2; term = pow(mult, v) / boost::math::tgamma(v+1, Policy()); mult *= -mult; } T operator()() { T r = term; ++N; term *= mult / (N * (N + v)); return r; } private: unsigned N; T v; T mult; T term; }; template
struct sph_bessel_j_small_z_series_term { typedef T result_type; sph_bessel_j_small_z_series_term(unsigned v_, T x) : N(0), v(v_) { BOOST_MATH_STD_USING mult = x / 2; term = pow(mult, T(v)) / boost::math::tgamma(v+1+T(0.5f), Policy()); mult *= -mult; } T operator()() { T r = term; ++N; term *= mult / (N * T(N + v + 0.5f)); return r; } private: unsigned N; unsigned v; T mult; T term; }; template
inline T bessel_j_small_z_series(T v, T x, const Policy& pol) { bessel_j_small_z_series_term
s(v, x); boost::uintmax_t max_iter = policies::get_max_series_iterations
(); #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) T zero = 0; T result = boost::math::tools::sum_series(s, boost::math::policies::digits
(), max_iter, zero); #else T result = boost::math::tools::sum_series(s, boost::math::policies::digits
(), max_iter); #endif policies::check_series_iterations("boost::math::bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol); return result; } template
inline T sph_bessel_j_small_z_series(unsigned v, T x, const Policy& pol) { BOOST_MATH_STD_USING // ADL of std names sph_bessel_j_small_z_series_term
s(v, x); boost::uintmax_t max_iter = policies::get_max_series_iterations
(); #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) T zero = 0; T result = boost::math::tools::sum_series(s, boost::math::policies::digits
(), max_iter, zero); #else T result = boost::math::tools::sum_series(s, boost::math::policies::digits
(), max_iter); #endif policies::check_series_iterations("boost::math::sph_bessel_j_small_z_series<%1%>(%1%,%1%)", max_iter, pol); return result * sqrt(constants::pi
() / 4); } template
T cyl_bessel_j_imp(T v, T x, const bessel_no_int_tag& t, const Policy& pol) { BOOST_MATH_STD_USING static const char* function = "boost::math::bessel_j<%1%>(%1%,%1%)"; if(x < 0) { // better have integer v: if(floor(v) == v) { T r = cyl_bessel_j_imp(v, -x, t, pol); if(tools::real_cast
(v) & 1) r = -r; return r; } else return policies::raise_domain_error
( function, "Got x = %1%, but we need x >= 0", x, pol); } if(x == 0) return (v == 0) ? 1 : (v > 0) ? 0 : policies::raise_domain_error
( function, "Got v = %1%, but require v >= 0 or a negative integer: the result would be complex.", v, pol); if((v >= 0) && ((x < 1) || (v > x * x / 4))) { return bessel_j_small_z_series(v, x, pol); } T j, y; bessel_jy(v, x, &j, &y, need_j, pol); return j; } template
inline T cyl_bessel_j_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol) { BOOST_MATH_STD_USING // ADL of std names. typedef typename bessel_asymptotic_tag
::type tag_type; if((fabs(v) < 200) && (floor(v) == v)) { if(fabs(x) > asymptotic_bessel_j_limit
(v, tag_type())) return asymptotic_bessel_j_large_x_2(v, x); else return bessel_jn(tools::real_cast
(v), x, pol); } return cyl_bessel_j_imp(v, x, bessel_no_int_tag(), pol); } template
inline T cyl_bessel_j_imp(int v, T x, const bessel_int_tag&, const Policy& pol) { BOOST_MATH_STD_USING typedef typename bessel_asymptotic_tag
::type tag_type; if(fabs(x) > asymptotic_bessel_j_limit
(abs(v), tag_type())) { T r = asymptotic_bessel_j_large_x_2(static_cast
(abs(v)), x); if((v < 0) && (v & 1)) r = -r; return r; } else return bessel_jn(v, x, pol); } template
inline T sph_bessel_j_imp(unsigned n, T x, const Policy& pol) { BOOST_MATH_STD_USING // ADL of std names if(x < 0) return policies::raise_domain_error
( "boost::math::sph_bessel_j<%1%>(%1%,%1%)", "Got x = %1%, but function requires x > 0.", x, pol); // // Special case, n == 0 resolves down to the sinus cardinal of x: // if(n == 0) return boost::math::sinc_pi(x, pol); // // When x is small we may end up with 0/0, use series evaluation // instead, especially as it converges rapidly: // if(x < 1) return sph_bessel_j_small_z_series(n, x, pol); // // Default case is just a naive evaluation of the definition: // return sqrt(constants::pi
() / (2 * x)) * cyl_bessel_j_imp(T(n)+T(0.5f), x, bessel_no_int_tag(), pol); } template
T cyl_bessel_i_imp(T v, T x, const Policy& pol) { // // This handles all the bessel I functions, note that we don't optimise // for integer v, other than the v = 0 or 1 special cases, as Millers // algorithm is at least as inefficient as the general case (the general // case has better error handling too). // BOOST_MATH_STD_USING if(x < 0) { // better have integer v: if(floor(v) == v) { T r = cyl_bessel_i_imp(v, -x, pol); if(tools::real_cast
(v) & 1) r = -r; return r; } else return policies::raise_domain_error
( "boost::math::cyl_bessel_i<%1%>(%1%,%1%)", "Got x = %1%, but we need x >= 0", x, pol); } if(x == 0) { return (v == 0) ? 1 : 0; } if(v == 0.5f) { // common special case, note try and avoid overflow in exp(x): T e = exp(x / 2); return e * (e / sqrt(2 * x * constants::pi
())); } if(policies::digits
() <= 64) { if(v == 0) { return bessel_i0(x); } if(v == 1) { return bessel_i1(x); } } T I, K; bessel_ik(v, x, &I, &K, need_i, pol); return I; } template
inline T cyl_bessel_k_imp(T v, T x, const bessel_no_int_tag& /* t */, const Policy& pol) { static const char* function = "boost::math::cyl_bessel_k<%1%>(%1%,%1%)"; BOOST_MATH_STD_USING if(x < 0) { return policies::raise_domain_error
( function, "Got x = %1%, but we need x > 0", x, pol); } if(x == 0) { return (v == 0) ? policies::raise_overflow_error
(function, 0, pol) : policies::raise_domain_error
( function, "Got x = %1%, but we need x > 0", x, pol); } T I, K; bessel_ik(v, x, &I, &K, need_k, pol); return K; } template
inline T cyl_bessel_k_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol) { BOOST_MATH_STD_USING if((floor(v) == v)) { return bessel_kn(tools::real_cast
(v), x, pol); } return cyl_bessel_k_imp(v, x, bessel_no_int_tag(), pol); } template
inline T cyl_bessel_k_imp(int v, T x, const bessel_int_tag&, const Policy& pol) { return bessel_kn(v, x, pol); } template
inline T cyl_neumann_imp(T v, T x, const bessel_no_int_tag&, const Policy& pol) { static const char* function = "boost::math::cyl_neumann<%1%>(%1%,%1%)"; if(x <= 0) { return (v == 0) && (x == 0) ? policies::raise_overflow_error
(function, 0, pol) : policies::raise_domain_error
( function, "Got x = %1%, but result is complex for x <= 0", x, pol); } T j, y; bessel_jy(v, x, &j, &y, need_y, pol); // // Post evaluation check for internal overflow during evaluation, // can occur when x is small and v is large, in which case the result // is -INF: // if(!(boost::math::isfinite)(y)) return -policies::raise_overflow_error
(function, 0, pol); return y; } template
inline T cyl_neumann_imp(T v, T x, const bessel_maybe_int_tag&, const Policy& pol) { BOOST_MATH_STD_USING typedef typename bessel_asymptotic_tag
::type tag_type; if(floor(v) == v) { if((fabs(x) > asymptotic_bessel_y_limit
(tag_type())) && (fabs(x) > 5 * abs(v))) { T r = asymptotic_bessel_y_large_x_2(static_cast
(abs(v)), x); if((v < 0) && (tools::real_cast
(v) & 1)) r = -r; return r; } else return bessel_yn(tools::real_cast
(v), x, pol); } return cyl_neumann_imp
(v, x, bessel_no_int_tag(), pol); } template
inline T cyl_neumann_imp(int v, T x, const bessel_int_tag&, const Policy& pol) { BOOST_MATH_STD_USING typedef typename bessel_asymptotic_tag
::type tag_type; if((fabs(x) > asymptotic_bessel_y_limit
(tag_type())) && (fabs(x) > 5 * abs(v))) { T r = asymptotic_bessel_y_large_x_2(static_cast
(abs(v)), x); if((v < 0) && (v & 1)) r = -r; return r; } else return bessel_yn(tools::real_cast
(v), x, pol); } template
inline T sph_neumann_imp(unsigned v, T x, const Policy& pol) { BOOST_MATH_STD_USING // ADL of std names static const char* function = "boost::math::sph_neumann<%1%>(%1%,%1%)"; // // Nothing much to do here but check for errors, and // evaluate the function's definition directly: // if(x < 0) return policies::raise_domain_error
( function, "Got x = %1%, but function requires x > 0.", x, pol); if(x < 2 * tools::min_value
()) return -policies::raise_overflow_error
(function, 0, pol); T result = cyl_neumann_imp(T(v)+0.5f, x, bessel_no_int_tag(), pol); T tx = sqrt(constants::pi
() / (2 * x)); if((tx > 1) && (tools::max_value
() / tx < result)) return -policies::raise_overflow_error
(function, 0, pol); return result * tx; } } // namespace detail template
inline typename detail::bessel_traits
::result_type cyl_bessel_j(T1 v, T2 x, const Policy& pol) { BOOST_FPU_EXCEPTION_GUARD typedef typename detail::bessel_traits
::result_type result_type; typedef typename detail::bessel_traits
::optimisation_tag tag_type; typedef typename policies::evaluation
::type value_type; return policies::checked_narrowing_cast
(detail::cyl_bessel_j_imp
(v, static_cast
(x), tag_type(), pol), "boost::math::cyl_bessel_j<%1%>(%1%,%1%)"); } template
inline typename detail::bessel_traits
>::result_type cyl_bessel_j(T1 v, T2 x) { return cyl_bessel_j(v, x, policies::policy<>()); } template
inline typename detail::bessel_traits
::result_type sph_bessel(unsigned v, T x, const Policy& pol) { BOOST_FPU_EXCEPTION_GUARD typedef typename detail::bessel_traits
::result_type result_type; typedef typename policies::evaluation
::type value_type; return policies::checked_narrowing_cast
(detail::sph_bessel_j_imp
(v, static_cast
(x), pol), "boost::math::sph_bessel<%1%>(%1%,%1%)"); } template
inline typename detail::bessel_traits
>::result_type sph_bessel(unsigned v, T x) { return sph_bessel(v, x, policies::policy<>()); } template
inline typename detail::bessel_traits
::result_type cyl_bessel_i(T1 v, T2 x, const Policy& pol) { BOOST_FPU_EXCEPTION_GUARD typedef typename detail::bessel_traits
::result_type result_type; typedef typename policies::evaluation
::type value_type; return policies::checked_narrowing_cast
(detail::cyl_bessel_i_imp
(v, static_cast
(x), pol), "boost::math::cyl_bessel_i<%1%>(%1%,%1%)"); } template
inline typename detail::bessel_traits
>::result_type cyl_bessel_i(T1 v, T2 x) { return cyl_bessel_i(v, x, policies::policy<>()); } template
inline typename detail::bessel_traits
::result_type cyl_bessel_k(T1 v, T2 x, const Policy& pol) { BOOST_FPU_EXCEPTION_GUARD typedef typename detail::bessel_traits
::result_type result_type; typedef typename detail::bessel_traits
::optimisation_tag tag_type; typedef typename policies::evaluation
::type value_type; return policies::checked_narrowing_cast
(detail::cyl_bessel_k_imp
(v, static_cast
(x), tag_type(), pol), "boost::math::cyl_bessel_k<%1%>(%1%,%1%)"); } template
inline typename detail::bessel_traits
>::result_type cyl_bessel_k(T1 v, T2 x) { return cyl_bessel_k(v, x, policies::policy<>()); } template
inline typename detail::bessel_traits
::result_type cyl_neumann(T1 v, T2 x, const Policy& pol) { BOOST_FPU_EXCEPTION_GUARD typedef typename detail::bessel_traits
::result_type result_type; typedef typename detail::bessel_traits
::optimisation_tag tag_type; typedef typename policies::evaluation
::type value_type; return policies::checked_narrowing_cast
(detail::cyl_neumann_imp
(v, static_cast
(x), tag_type(), pol), "boost::math::cyl_neumann<%1%>(%1%,%1%)"); } template
inline typename detail::bessel_traits
>::result_type cyl_neumann(T1 v, T2 x) { return cyl_neumann(v, x, policies::policy<>()); } template
inline typename detail::bessel_traits
::result_type sph_neumann(unsigned v, T x, const Policy& pol) { BOOST_FPU_EXCEPTION_GUARD typedef typename detail::bessel_traits
::result_type result_type; typedef typename policies::evaluation
::type value_type; return policies::checked_narrowing_cast
(detail::sph_neumann_imp
(v, static_cast
(x), pol), "boost::math::sph_neumann<%1%>(%1%,%1%)"); } template
inline typename detail::bessel_traits
>::result_type sph_neumann(unsigned v, T x) { return sph_neumann(v, x, policies::policy<>()); } } // namespace math } // namespace boost #endif // BOOST_MATH_BESSEL_HPP
bessel.hpp
网页地址
文件地址
上一页
4/35
下一页
下载
( 16 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.