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_exp
20 //! @{
21 
22 
23 
24 template<typename eT>
25 arma_warn_unused
26 inline
27 static
28 typename arma_real_only<eT>::result
trunc_exp(const eT x)29 trunc_exp(const eT x)
30   {
31   if(std::numeric_limits<eT>::is_iec559 && (x >= Datum<eT>::log_max ))
32     {
33     return std::numeric_limits<eT>::max();
34     }
35   else
36     {
37     return std::exp(x);
38     }
39   }
40 
41 
42 
43 template<typename eT>
44 arma_warn_unused
45 inline
46 static
47 typename arma_integral_only<eT>::result
trunc_exp(const eT x)48 trunc_exp(const eT x)
49   {
50   return eT( trunc_exp( double(x) ) );
51   }
52 
53 
54 
55 template<typename T>
56 arma_warn_unused
57 inline
58 static
59 std::complex<T>
trunc_exp(const std::complex<T> & x)60 trunc_exp(const std::complex<T>& x)
61   {
62   return std::polar( trunc_exp( x.real() ), x.imag() );
63   }
64 
65 
66 
67 template<typename T1>
68 arma_warn_unused
69 arma_inline
70 typename enable_if2< is_arma_type<T1>::value, const eOp<T1, eop_trunc_exp> >::result
trunc_exp(const T1 & A)71 trunc_exp(const T1& A)
72   {
73   arma_extra_debug_sigprint();
74 
75   return eOp<T1, eop_trunc_exp>(A);
76   }
77 
78 
79 
80 template<typename T1>
81 arma_warn_unused
82 arma_inline
83 const eOpCube<T1, eop_trunc_exp>
trunc_exp(const BaseCube<typename T1::elem_type,T1> & A)84 trunc_exp(const BaseCube<typename T1::elem_type,T1>& A)
85   {
86   arma_extra_debug_sigprint();
87 
88   return eOpCube<T1, eop_trunc_exp>(A.get_ref());
89   }
90 
91 
92 
93 //! @}
94