pow.hpp 19 KB

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