fn_trunc_log.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_log
  16. //! @{
  17. template<typename eT>
  18. arma_warn_unused
  19. inline
  20. static
  21. typename arma_real_only<eT>::result
  22. trunc_log(const eT x)
  23. {
  24. if(std::numeric_limits<eT>::is_iec559)
  25. {
  26. if(x == std::numeric_limits<eT>::infinity())
  27. {
  28. return Datum<eT>::log_max;
  29. }
  30. else
  31. {
  32. return (x <= eT(0)) ? Datum<eT>::log_min : std::log(x);
  33. }
  34. }
  35. else
  36. {
  37. return std::log(x);
  38. }
  39. }
  40. template<typename eT>
  41. arma_warn_unused
  42. inline
  43. static
  44. typename arma_integral_only<eT>::result
  45. trunc_log(const eT x)
  46. {
  47. return eT( trunc_log( double(x) ) );
  48. }
  49. template<typename T>
  50. arma_warn_unused
  51. inline
  52. static
  53. std::complex<T>
  54. trunc_log(const std::complex<T>& x)
  55. {
  56. return std::complex<T>( trunc_log( std::abs(x) ), std::arg(x) );
  57. }
  58. template<typename T1>
  59. arma_warn_unused
  60. arma_inline
  61. typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_trunc_log> >::result
  62. trunc_log(const T1& A)
  63. {
  64. arma_extra_debug_sigprint();
  65. return eOp<T1, eop_trunc_log>(A);
  66. }
  67. template<typename T1>
  68. arma_warn_unused
  69. arma_inline
  70. const eOpCube<T1, eop_trunc_log>
  71. trunc_log(const BaseCube<typename T1::elem_type,T1>& A)
  72. {
  73. arma_extra_debug_sigprint();
  74. return eOpCube<T1, eop_trunc_log>(A.get_ref());
  75. }
  76. //! @}