2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - DIGITEO - Cedric DELAMARRE
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
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.
15 /*--------------------------------------------------------------------------*/
19 #include "elem_func_gw.hxx"
20 #include "function.hxx"
22 #include "overload.hxx"
23 #include "configvariable.hxx"
28 #include "localization.h"
29 #include "elem_common.h"
34 clear a;nb = 2500;a = rand(nb, nb);tic();atanh(a);toc
35 clear a;nb = 2500;a = rand(nb, nb); a = a + a *%i;tic();atanh(a);toc
37 /*--------------------------------------------------------------------------*/
38 types::Function::ReturnValue sci_atanh(types::typed_list &in, int _iRetCount, types::typed_list &out)
40 types::Double* pDblIn = NULL;
41 types::Double* pDblOut = NULL;
45 Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "atanh", 1);
46 return types::Function::Error;
51 Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "atanh", 1);
52 return types::Function::Error;
55 if (in[0]->isDouble())
57 pDblIn = in[0]->getAs<types::Double>();
58 double* pInR = pDblIn->get();
59 double* pInI = pDblIn->getImg();
61 int iSize = pDblIn->getSize();
62 bool bComplex = pDblIn->isComplex();
63 bool bAlreadyDisp = false;
65 if (bComplex == false)
68 for (int i = 0; i < iSize; i++)
70 double dAbsIn = abs(pInR[i]);
73 if (pInI && pDblIn->isComplex() == false)
78 if (ConfigVariable::getIeee() == 0)
80 Scierror(78, _("%s: Warning: Wrong value for input argument #%d : Singularity of the function.\n"), "atanh", 1);
81 return types::Function::Error;
84 if (ConfigVariable::getIeee() == 1 && ConfigVariable::getWarningMode() && bAlreadyDisp == false)
87 sciprint(_("%s: Warning: Wrong value for input argument #%d : Singularity of the function.\n"), "atanh", 1);
90 else if (dAbsIn > 1 && bComplex == false)
93 pInI = new double[iSize];
94 memset(pInI, 0x00, iSize * sizeof(double));
99 pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray(), bComplex);
100 double* pOutR = pDblOut->get();
101 double* pOutI = pDblOut->getImg();
105 // using scilab 5 macro atanh is faster than std::atanh (08/2015)
106 // see comment a the begins of this gateway
107 for (int i = 0; i < iSize; i++)
109 //zcoss(-pInI[i], pInR[i], &pOutR[i], &pOutI[i]);
110 std::complex<double> c(pInR[i], pInI[i]);
111 std::complex<double> d = std::atanh(c);
119 for (int i = 0; i < iSize; i++)
121 pOutR[i] = std::atanh(pInR[i]);
124 out.push_back(pDblOut);
128 std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_atanh";
129 return Overload::call(wstFuncName, in, _iRetCount, out);
132 return types::Function::OK;
134 /*--------------------------------------------------------------------------*/