pow.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. // Copyright Christopher Kormanyos 2002 - 2011.
  2. // Copyright 2011 John Maddock. Distributed under the Boost
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // This work is based on an earlier work:
  7. // "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations",
  8. // in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469
  9. //
  10. // This file has no include guards or namespaces - it's expanded inline inside default_ops.hpp
  11. //
  12. namespace detail{
  13. template<typename T, typename U>
  14. inline void pow_imp(T& result, const T& t, const U& p, const mpl::false_&)
  15. {
  16. // Compute the pure power of typename T t^p.
  17. // Use the S-and-X binary method, as described in
  18. // D. E. Knuth, "The Art of Computer Programming", Vol. 2,
  19. // Section 4.6.3 . The resulting computational complexity
  20. // is order log2[abs(p)].
  21. typedef typename boost::multiprecision::detail::canonical<U, T>::type int_type;
  22. if(&result == &t)
  23. {
  24. T temp;
  25. pow_imp(temp, t, p, mpl::false_());
  26. result = temp;
  27. return;
  28. }
  29. // This will store the result.
  30. if(U(p % U(2)) != U(0))
  31. {
  32. result = t;
  33. }
  34. else
  35. result = int_type(1);
  36. U p2(p);
  37. // The variable x stores the binary powers of t.
  38. T x(t);
  39. while(U(p2 /= 2) != U(0))
  40. {
  41. // Square x for each binary power.
  42. eval_multiply(x, x);
  43. const bool has_binary_power = (U(p2 % U(2)) != U(0));
  44. if(has_binary_power)
  45. {
  46. // Multiply the result with each binary power contained in the exponent.
  47. eval_multiply(result, x);
  48. }
  49. }
  50. }
  51. template<typename T, typename U>
  52. inline void pow_imp(T& result, const T& t, const U& p, const mpl::true_&)
  53. {
  54. // Signed integer power, just take care of the sign then call the unsigned version:
  55. typedef typename boost::multiprecision::detail::canonical<U, T>::type int_type;
  56. typedef typename make_unsigned<U>::type ui_type;
  57. if(p < 0)
  58. {
  59. T temp;
  60. temp = static_cast<int_type>(1);
  61. T denom;
  62. pow_imp(denom, t, static_cast<ui_type>(-p), mpl::false_());
  63. eval_divide(result, temp, denom);
  64. return;
  65. }
  66. pow_imp(result, t, static_cast<ui_type>(p), mpl::false_());
  67. }
  68. } // namespace detail
  69. template<typename T, typename U>
  70. inline typename enable_if<is_integral<U> >::type eval_pow(T& result, const T& t, const U& p)
  71. {
  72. detail::pow_imp(result, t, p, boost::is_signed<U>());
  73. }
  74. template <class T>
  75. void hyp0F0(T& H0F0, const T& x)
  76. {
  77. // Compute the series representation of Hypergeometric0F0 taken from
  78. // http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric0F0/06/01/
  79. // There are no checks on input range or parameter boundaries.
  80. typedef typename mpl::front<typename T::unsigned_types>::type ui_type;
  81. BOOST_ASSERT(&H0F0 != &x);
  82. long tol = boost::multiprecision::detail::digits2<number<T, et_on> >::value;
  83. T t;
  84. T x_pow_n_div_n_fact(x);
  85. eval_add(H0F0, x_pow_n_div_n_fact, ui_type(1));
  86. T lim;
  87. eval_ldexp(lim, H0F0, 1 - tol);
  88. if(eval_get_sign(lim) < 0)
  89. lim.negate();
  90. ui_type n;
  91. static const unsigned series_limit =
  92. boost::multiprecision::detail::digits2<number<T, et_on> >::value < 100
  93. ? 100 : boost::multiprecision::detail::digits2<number<T, et_on> >::value;
  94. // Series expansion of hyperg_0f0(; ; x).
  95. for(n = 2; n < series_limit; ++n)
  96. {
  97. eval_multiply(x_pow_n_div_n_fact, x);
  98. eval_divide(x_pow_n_div_n_fact, n);
  99. eval_add(H0F0, x_pow_n_div_n_fact);
  100. bool neg = eval_get_sign(x_pow_n_div_n_fact) < 0;
  101. if(neg)
  102. x_pow_n_div_n_fact.negate();
  103. if(lim.compare(x_pow_n_div_n_fact) > 0)
  104. break;
  105. if(neg)
  106. x_pow_n_div_n_fact.negate();
  107. }
  108. if(n >= series_limit)
  109. BOOST_THROW_EXCEPTION(std::runtime_error("H0F0 failed to converge"));
  110. }
  111. template <class T>
  112. void hyp1F0(T& H1F0, const T& a, const T& x)
  113. {
  114. // Compute the series representation of Hypergeometric1F0 taken from
  115. // http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric1F0/06/01/01/
  116. // and also see the corresponding section for the power function (i.e. x^a).
  117. // There are no checks on input range or parameter boundaries.
  118. typedef typename boost::multiprecision::detail::canonical<int, T>::type si_type;
  119. BOOST_ASSERT(&H1F0 != &x);
  120. BOOST_ASSERT(&H1F0 != &a);
  121. T x_pow_n_div_n_fact(x);
  122. T pochham_a (a);
  123. T ap (a);
  124. eval_multiply(H1F0, pochham_a, x_pow_n_div_n_fact);
  125. eval_add(H1F0, si_type(1));
  126. T lim;
  127. eval_ldexp(lim, H1F0, 1 - boost::multiprecision::detail::digits2<number<T, et_on> >::value);
  128. if(eval_get_sign(lim) < 0)
  129. lim.negate();
  130. si_type n;
  131. T term, part;
  132. static const unsigned series_limit =
  133. boost::multiprecision::detail::digits2<number<T, et_on> >::value < 100
  134. ? 100 : boost::multiprecision::detail::digits2<number<T, et_on> >::value;
  135. // Series expansion of hyperg_1f0(a; ; x).
  136. for(n = 2; n < series_limit; n++)
  137. {
  138. eval_multiply(x_pow_n_div_n_fact, x);
  139. eval_divide(x_pow_n_div_n_fact, n);
  140. eval_increment(ap);
  141. eval_multiply(pochham_a, ap);
  142. eval_multiply(term, pochham_a, x_pow_n_div_n_fact);
  143. eval_add(H1F0, term);
  144. if(eval_get_sign(term) < 0)
  145. term.negate();
  146. if(lim.compare(term) >= 0)
  147. break;
  148. }
  149. if(n >= series_limit)
  150. BOOST_THROW_EXCEPTION(std::runtime_error("H1F0 failed to converge"));
  151. }
  152. template <class T>
  153. void eval_exp(T& result, const T& x)
  154. {
  155. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The exp function is only valid for floating point types.");
  156. if(&x == &result)
  157. {
  158. T temp;
  159. eval_exp(temp, x);
  160. result = temp;
  161. return;
  162. }
  163. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  164. typedef typename boost::multiprecision::detail::canonical<int, T>::type si_type;
  165. typedef typename T::exponent_type exp_type;
  166. typedef typename boost::multiprecision::detail::canonical<exp_type, T>::type canonical_exp_type;
  167. // Handle special arguments.
  168. int type = eval_fpclassify(x);
  169. bool isneg = eval_get_sign(x) < 0;
  170. if(type == FP_NAN)
  171. {
  172. result = x;
  173. return;
  174. }
  175. else if(type == FP_INFINITE)
  176. {
  177. result = x;
  178. if(isneg)
  179. result = ui_type(0u);
  180. else
  181. result = x;
  182. return;
  183. }
  184. else if(type == FP_ZERO)
  185. {
  186. result = ui_type(1);
  187. return;
  188. }
  189. // Get local copy of argument and force it to be positive.
  190. T xx = x;
  191. T exp_series;
  192. if(isneg)
  193. xx.negate();
  194. // Check the range of the argument.
  195. static const canonical_exp_type maximum_arg_for_exp = std::numeric_limits<number<T, et_on> >::max_exponent == 0 ? (std::numeric_limits<long>::max)() : std::numeric_limits<number<T, et_on> >::max_exponent;
  196. if(xx.compare(maximum_arg_for_exp) >= 0)
  197. {
  198. // Overflow / underflow
  199. if(isneg)
  200. result = ui_type(0);
  201. else
  202. result = std::numeric_limits<number<T, et_on> >::has_infinity ? std::numeric_limits<number<T, et_on> >::infinity().backend() : (std::numeric_limits<number<T, et_on> >::max)().backend();
  203. return;
  204. }
  205. if(xx.compare(si_type(1)) <= 0)
  206. {
  207. //
  208. // Use series for exp(x) - 1:
  209. //
  210. T lim = std::numeric_limits<number<T, et_on> >::epsilon().backend();
  211. unsigned k = 2;
  212. exp_series = xx;
  213. result = si_type(1);
  214. if(isneg)
  215. eval_subtract(result, exp_series);
  216. else
  217. eval_add(result, exp_series);
  218. eval_multiply(exp_series, xx);
  219. eval_divide(exp_series, ui_type(k));
  220. eval_add(result, exp_series);
  221. while(exp_series.compare(lim) > 0)
  222. {
  223. ++k;
  224. eval_multiply(exp_series, xx);
  225. eval_divide(exp_series, ui_type(k));
  226. if(isneg && (k&1))
  227. eval_subtract(result, exp_series);
  228. else
  229. eval_add(result, exp_series);
  230. }
  231. return;
  232. }
  233. // Check for pure-integer arguments which can be either signed or unsigned.
  234. typename boost::multiprecision::detail::canonical<boost::intmax_t, T>::type ll;
  235. eval_trunc(exp_series, x);
  236. eval_convert_to(&ll, exp_series);
  237. if(x.compare(ll) == 0)
  238. {
  239. detail::pow_imp(result, get_constant_e<T>(), ll, mpl::true_());
  240. return;
  241. }
  242. // The algorithm for exp has been taken from MPFUN.
  243. // exp(t) = [ (1 + r + r^2/2! + r^3/3! + r^4/4! ...)^p2 ] * 2^n
  244. // where p2 is a power of 2 such as 2048, r = t_prime / p2, and
  245. // t_prime = t - n*ln2, with n chosen to minimize the absolute
  246. // value of t_prime. In the resulting Taylor series, which is
  247. // implemented as a hypergeometric function, |r| is bounded by
  248. // ln2 / p2. For small arguments, no scaling is done.
  249. // Compute the exponential series of the (possibly) scaled argument.
  250. eval_divide(result, xx, get_constant_ln2<T>());
  251. exp_type n;
  252. eval_convert_to(&n, result);
  253. // The scaling is 2^11 = 2048.
  254. static const si_type p2 = static_cast<si_type>(si_type(1) << 11);
  255. eval_multiply(exp_series, get_constant_ln2<T>(), static_cast<canonical_exp_type>(n));
  256. eval_subtract(exp_series, xx);
  257. eval_divide(exp_series, p2);
  258. exp_series.negate();
  259. hyp0F0(result, exp_series);
  260. detail::pow_imp(exp_series, result, p2, mpl::true_());
  261. result = ui_type(1);
  262. eval_ldexp(result, result, n);
  263. eval_multiply(exp_series, result);
  264. if(isneg)
  265. eval_divide(result, ui_type(1), exp_series);
  266. else
  267. result = exp_series;
  268. }
  269. template <class T>
  270. void eval_log(T& result, const T& arg)
  271. {
  272. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The log function is only valid for floating point types.");
  273. //
  274. // We use a variation of http://dlmf.nist.gov/4.45#i
  275. // using frexp to reduce the argument to x * 2^n,
  276. // then let y = x - 1 and compute:
  277. // log(x) = log(2) * n + log1p(1 + y)
  278. //
  279. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  280. typedef typename T::exponent_type exp_type;
  281. typedef typename boost::multiprecision::detail::canonical<exp_type, T>::type canonical_exp_type;
  282. typedef typename mpl::front<typename T::float_types>::type fp_type;
  283. exp_type e;
  284. T t;
  285. eval_frexp(t, arg, &e);
  286. bool alternate = false;
  287. if(t.compare(fp_type(2) / fp_type(3)) <= 0)
  288. {
  289. alternate = true;
  290. eval_ldexp(t, t, 1);
  291. --e;
  292. }
  293. eval_multiply(result, get_constant_ln2<T>(), canonical_exp_type(e));
  294. INSTRUMENT_BACKEND(result);
  295. eval_subtract(t, ui_type(1)); /* -0.3 <= t <= 0.3 */
  296. if(!alternate)
  297. t.negate(); /* 0 <= t <= 0.33333 */
  298. T pow = t;
  299. T lim;
  300. T t2;
  301. if(alternate)
  302. eval_add(result, t);
  303. else
  304. eval_subtract(result, t);
  305. eval_multiply(lim, result, std::numeric_limits<number<T, et_on> >::epsilon().backend());
  306. if(eval_get_sign(lim) < 0)
  307. lim.negate();
  308. INSTRUMENT_BACKEND(lim);
  309. ui_type k = 1;
  310. do
  311. {
  312. ++k;
  313. eval_multiply(pow, t);
  314. eval_divide(t2, pow, k);
  315. INSTRUMENT_BACKEND(t2);
  316. if(alternate && ((k & 1) != 0))
  317. eval_add(result, t2);
  318. else
  319. eval_subtract(result, t2);
  320. INSTRUMENT_BACKEND(result);
  321. }while(lim.compare(t2) < 0);
  322. }
  323. template <class T>
  324. const T& get_constant_log10()
  325. {
  326. static T result;
  327. static bool b = false;
  328. if(!b)
  329. {
  330. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  331. T ten;
  332. ten = ui_type(10u);
  333. eval_log(result, ten);
  334. }
  335. constant_initializer<T, &get_constant_log10<T> >::do_nothing();
  336. return result;
  337. }
  338. template <class T>
  339. void eval_log10(T& result, const T& arg)
  340. {
  341. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The log10 function is only valid for floating point types.");
  342. eval_log(result, arg);
  343. eval_divide(result, get_constant_log10<T>());
  344. }
  345. template<typename T>
  346. inline void eval_pow(T& result, const T& x, const T& a)
  347. {
  348. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The pow function is only valid for floating point types.");
  349. typedef typename boost::multiprecision::detail::canonical<int, T>::type si_type;
  350. typedef typename mpl::front<typename T::float_types>::type fp_type;
  351. if((&result == &x) || (&result == &a))
  352. {
  353. T t;
  354. eval_pow(t, x, a);
  355. result = t;
  356. return;
  357. }
  358. if(a.compare(si_type(1)) == 0)
  359. {
  360. result = x;
  361. return;
  362. }
  363. int type = eval_fpclassify(x);
  364. switch(type)
  365. {
  366. case FP_INFINITE:
  367. result = x;
  368. return;
  369. case FP_ZERO:
  370. switch(eval_fpclassify(a))
  371. {
  372. case FP_ZERO:
  373. result = si_type(1);
  374. break;
  375. case FP_NAN:
  376. result = a;
  377. break;
  378. default:
  379. result = x;
  380. break;
  381. }
  382. return;
  383. case FP_NAN:
  384. result = x;
  385. return;
  386. default: ;
  387. }
  388. int s = eval_get_sign(a);
  389. if(s == 0)
  390. {
  391. result = si_type(1);
  392. return;
  393. }
  394. if(s < 0)
  395. {
  396. T t, da;
  397. t = a;
  398. t.negate();
  399. eval_pow(da, x, t);
  400. eval_divide(result, si_type(1), da);
  401. return;
  402. }
  403. typename boost::multiprecision::detail::canonical<boost::intmax_t, T>::type an;
  404. T fa;
  405. try
  406. {
  407. eval_convert_to(&an, a);
  408. if(a.compare(an) == 0)
  409. {
  410. detail::pow_imp(result, x, an, mpl::true_());
  411. return;
  412. }
  413. }
  414. catch(const std::exception&)
  415. {
  416. // conversion failed, just fall through, value is not an integer.
  417. an = (std::numeric_limits<boost::intmax_t>::max)();
  418. }
  419. if((eval_get_sign(x) < 0))
  420. {
  421. typename boost::multiprecision::detail::canonical<boost::uintmax_t, T>::type aun;
  422. try
  423. {
  424. eval_convert_to(&aun, a);
  425. if(a.compare(aun) == 0)
  426. {
  427. fa = x;
  428. fa.negate();
  429. eval_pow(result, fa, a);
  430. if(aun & 1u)
  431. result.negate();
  432. return;
  433. }
  434. }
  435. catch(const std::exception&)
  436. {
  437. // conversion failed, just fall through, value is not an integer.
  438. }
  439. if(std::numeric_limits<number<T, et_on> >::has_quiet_NaN)
  440. result = std::numeric_limits<number<T, et_on> >::quiet_NaN().backend();
  441. else
  442. {
  443. BOOST_THROW_EXCEPTION(std::domain_error("Result of pow is undefined or non-real and there is no NaN for this number type."));
  444. }
  445. return;
  446. }
  447. T t, da;
  448. eval_subtract(da, a, an);
  449. if((x.compare(fp_type(0.5)) >= 0) && (x.compare(fp_type(0.9)) < 0))
  450. {
  451. if(a.compare(fp_type(1e-5f)) <= 0)
  452. {
  453. // Series expansion for small a.
  454. eval_log(t, x);
  455. eval_multiply(t, a);
  456. hyp0F0(result, t);
  457. return;
  458. }
  459. else
  460. {
  461. // Series expansion for moderately sized x. Note that for large power of a,
  462. // the power of the integer part of a is calculated using the pown function.
  463. if(an)
  464. {
  465. da.negate();
  466. t = si_type(1);
  467. eval_subtract(t, x);
  468. hyp1F0(result, da, t);
  469. detail::pow_imp(t, x, an, mpl::true_());
  470. eval_multiply(result, t);
  471. }
  472. else
  473. {
  474. da = a;
  475. da.negate();
  476. t = si_type(1);
  477. eval_subtract(t, x);
  478. hyp1F0(result, da, t);
  479. }
  480. }
  481. }
  482. else
  483. {
  484. // Series expansion for pow(x, a). Note that for large power of a, the power
  485. // of the integer part of a is calculated using the pown function.
  486. if(an)
  487. {
  488. eval_log(t, x);
  489. eval_multiply(t, da);
  490. eval_exp(result, t);
  491. detail::pow_imp(t, x, an, mpl::true_());
  492. eval_multiply(result, t);
  493. }
  494. else
  495. {
  496. eval_log(t, x);
  497. eval_multiply(t, a);
  498. eval_exp(result, t);
  499. }
  500. }
  501. }
  502. template<class T, class A>
  503. inline typename enable_if<is_floating_point<A>, void>::type eval_pow(T& result, const T& x, const A& a)
  504. {
  505. // Note this one is restricted to float arguments since pow.hpp already has a version for
  506. // integer powers....
  507. typedef typename boost::multiprecision::detail::canonical<A, T>::type canonical_type;
  508. typedef typename mpl::if_<is_same<A, canonical_type>, T, canonical_type>::type cast_type;
  509. cast_type c;
  510. c = a;
  511. eval_pow(result, x, c);
  512. }
  513. template<class T, class A>
  514. inline typename enable_if<is_arithmetic<A>, void>::type eval_pow(T& result, const A& x, const T& a)
  515. {
  516. typedef typename boost::multiprecision::detail::canonical<A, T>::type canonical_type;
  517. typedef typename mpl::if_<is_same<A, canonical_type>, T, canonical_type>::type cast_type;
  518. cast_type c;
  519. c = x;
  520. eval_pow(result, c, a);
  521. }
  522. namespace detail{
  523. template <class T>
  524. void small_sinh_series(T x, T& result)
  525. {
  526. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  527. bool neg = eval_get_sign(x) < 0;
  528. if(neg)
  529. x.negate();
  530. T p(x);
  531. T mult(x);
  532. eval_multiply(mult, x);
  533. result = x;
  534. ui_type k = 1;
  535. T lim(x);
  536. eval_ldexp(lim, lim, 1 - boost::multiprecision::detail::digits2<number<T, et_on> >::value);
  537. do
  538. {
  539. eval_multiply(p, mult);
  540. eval_divide(p, ++k);
  541. eval_divide(p, ++k);
  542. eval_add(result, p);
  543. }while(p.compare(lim) >= 0);
  544. if(neg)
  545. result.negate();
  546. }
  547. template <class T>
  548. void sinhcosh(const T& x, T* p_sinh, T* p_cosh)
  549. {
  550. typedef typename boost::multiprecision::detail::canonical<unsigned, T>::type ui_type;
  551. typedef typename mpl::front<typename T::float_types>::type fp_type;
  552. switch(eval_fpclassify(x))
  553. {
  554. case FP_NAN:
  555. case FP_INFINITE:
  556. if(p_sinh)
  557. *p_sinh = x;
  558. if(p_cosh)
  559. {
  560. *p_cosh = x;
  561. if(eval_get_sign(x) < 0)
  562. p_cosh->negate();
  563. }
  564. return;
  565. case FP_ZERO:
  566. if(p_sinh)
  567. *p_sinh = x;
  568. if(p_cosh)
  569. *p_cosh = ui_type(1);
  570. return;
  571. default: ;
  572. }
  573. bool small_sinh = eval_get_sign(x) < 0 ? x.compare(fp_type(-0.5)) > 0 : x.compare(fp_type(0.5)) < 0;
  574. if(p_cosh || !small_sinh)
  575. {
  576. T e_px, e_mx;
  577. eval_exp(e_px, x);
  578. eval_divide(e_mx, ui_type(1), e_px);
  579. if(p_sinh)
  580. {
  581. if(small_sinh)
  582. {
  583. small_sinh_series(x, *p_sinh);
  584. }
  585. else
  586. {
  587. eval_subtract(*p_sinh, e_px, e_mx);
  588. eval_ldexp(*p_sinh, *p_sinh, -1);
  589. }
  590. }
  591. if(p_cosh)
  592. {
  593. eval_add(*p_cosh, e_px, e_mx);
  594. eval_ldexp(*p_cosh, *p_cosh, -1);
  595. }
  596. }
  597. else
  598. {
  599. small_sinh_series(x, *p_sinh);
  600. }
  601. }
  602. } // namespace detail
  603. template <class T>
  604. inline void eval_sinh(T& result, const T& x)
  605. {
  606. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The sinh function is only valid for floating point types.");
  607. detail::sinhcosh(x, &result, static_cast<T*>(0));
  608. }
  609. template <class T>
  610. inline void eval_cosh(T& result, const T& x)
  611. {
  612. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The cosh function is only valid for floating point types.");
  613. detail::sinhcosh(x, static_cast<T*>(0), &result);
  614. }
  615. template <class T>
  616. inline void eval_tanh(T& result, const T& x)
  617. {
  618. BOOST_STATIC_ASSERT_MSG(number_category<T>::value == number_kind_floating_point, "The tanh function is only valid for floating point types.");
  619. T c;
  620. detail::sinhcosh(x, &result, &c);
  621. eval_divide(result, c);
  622. }