1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - DIGITEO - Cedric DELAMARRE
4 *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13 *
14 */
15 /*--------------------------------------------------------------------------*/
16 
17 #include <complex>
18 
19 #include "elem_func_gw.hxx"
20 #include "function.hxx"
21 #include "double.hxx"
22 #include "overload.hxx"
23 
24 extern "C"
25 {
26 #include "Scierror.h"
27 #include "localization.h"
28 #include "elem_common.h"
29 }
30 
31 /*
32 clear a;nb = 2500;a = rand(nb, nb);tic();cosh(a);toc
33 clear a;nb = 2500;a = rand(nb, nb); a = a + a *%i;tic();cosh(a);toc
34 */
35 /*--------------------------------------------------------------------------*/
sci_cosh(types::typed_list & in,int _iRetCount,types::typed_list & out)36 types::Function::ReturnValue sci_cosh(types::typed_list &in, int _iRetCount, types::typed_list &out)
37 {
38     types::Double* pDblIn = NULL;
39     types::Double* pDblOut = NULL;
40 
41     if (in.size() != 1)
42     {
43         Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "cosh", 1);
44         return types::Function::Error;
45     }
46 
47     if (_iRetCount > 1)
48     {
49         Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "cosh", 1);
50         return types::Function::Error;
51     }
52 
53     if (in[0]->isDouble())
54     {
55         pDblIn = in[0]->getAs<types::Double>();
56         pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray(), pDblIn->isComplex());
57 
58         double* pInR = pDblIn->get();
59         double* pOutR = pDblOut->get();
60         int size = pDblIn->getSize();
61         if (pDblIn->isComplex())
62         {
63             double* pInI = pDblIn->getImg();
64             double* pOutI = pDblOut->getImg();
65 
66             for (int i = 0; i < size; i++)
67             {
68                 //zcoss(-pInI[i], pInR[i], &pOutR[i], &pOutI[i]);
69                 std::complex<double> c(pInR[i], pInI[i]);
70                 std::complex<double> d = std::cosh(c);
71                 pOutR[i] = d.real();
72                 pOutI[i] = d.imag();
73             }
74         }
75         else
76         {
77             for (int i = 0; i < size; i++)
78             {
79                 pOutR[i] = std::cosh(pInR[i]);
80             }
81         }
82 
83         out.push_back(pDblOut);
84     }
85     else
86     {
87         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_cosh";
88         return Overload::call(wstFuncName, in, _iRetCount, out);
89     }
90 
91     return types::Function::OK;
92 }
93 /*--------------------------------------------------------------------------*/
94