1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17 
18 
19 //! \addtogroup fn_trunc_log
20 //! @{
21 
22 
23 
24 template<typename eT>
25 arma_warn_unused
26 inline
27 static
28 typename arma_real_only<eT>::result
trunc_log(const eT x)29 trunc_log(const eT x)
30   {
31   if(std::numeric_limits<eT>::is_iec559)
32     {
33     if(x == std::numeric_limits<eT>::infinity())
34       {
35       return Datum<eT>::log_max;
36       }
37     else
38       {
39       return (x <= eT(0)) ? Datum<eT>::log_min : std::log(x);
40       }
41     }
42   else
43     {
44     return std::log(x);
45     }
46   }
47 
48 
49 
50 template<typename eT>
51 arma_warn_unused
52 inline
53 static
54 typename arma_integral_only<eT>::result
trunc_log(const eT x)55 trunc_log(const eT x)
56   {
57   return eT( trunc_log( double(x) ) );
58   }
59 
60 
61 
62 template<typename T>
63 arma_warn_unused
64 inline
65 static
66 std::complex<T>
trunc_log(const std::complex<T> & x)67 trunc_log(const std::complex<T>& x)
68   {
69   return std::complex<T>( trunc_log( std::abs(x) ), std::arg(x) );
70   }
71 
72 
73 
74 template<typename T1>
75 arma_warn_unused
76 arma_inline
77 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_trunc_log> >::result
trunc_log(const T1 & A)78 trunc_log(const T1& A)
79   {
80   arma_extra_debug_sigprint();
81 
82   return eOp<T1, eop_trunc_log>(A);
83   }
84 
85 
86 
87 template<typename T1>
88 arma_warn_unused
89 arma_inline
90 const eOpCube<T1, eop_trunc_log>
trunc_log(const BaseCube<typename T1::elem_type,T1> & A)91 trunc_log(const BaseCube<typename T1::elem_type,T1>& A)
92   {
93   arma_extra_debug_sigprint();
94 
95   return eOpCube<T1, eop_trunc_log>(A.get_ref());
96   }
97 
98 
99 
100 //! @}
101