fn_trunc_exp.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup fn_trunc_exp
  16. //! @{
  17. template<typename eT>
  18. arma_warn_unused
  19. inline
  20. static
  21. typename arma_real_only<eT>::result
  22. trunc_exp(const eT x)
  23. {
  24. if(std::numeric_limits<eT>::is_iec559 && (x >= Datum<eT>::log_max ))
  25. {
  26. return std::numeric_limits<eT>::max();
  27. }
  28. else
  29. {
  30. return std::exp(x);
  31. }
  32. }
  33. template<typename eT>
  34. arma_warn_unused
  35. inline
  36. static
  37. typename arma_integral_only<eT>::result
  38. trunc_exp(const eT x)
  39. {
  40. return eT( trunc_exp( double(x) ) );
  41. }
  42. template<typename T>
  43. arma_warn_unused
  44. inline
  45. static
  46. std::complex<T>
  47. trunc_exp(const std::complex<T>& x)
  48. {
  49. return std::polar( trunc_exp( x.real() ), x.imag() );
  50. }
  51. template<typename T1>
  52. arma_warn_unused
  53. arma_inline
  54. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_trunc_exp> >::result
  55. trunc_exp(const T1& A)
  56. {
  57. arma_extra_debug_sigprint();
  58. return eOp<T1, eop_trunc_exp>(A);
  59. }
  60. template<typename T1>
  61. arma_warn_unused
  62. arma_inline
  63. const eOpCube<T1, eop_trunc_exp>
  64. trunc_exp(const BaseCube<typename T1::elem_type,T1>& A)
  65. {
  66. arma_extra_debug_sigprint();
  67. return eOpCube<T1, eop_trunc_exp>(A.get_ref());
  68. }
  69. //! @}