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 #include "elem_func_gw.hxx"
17 #include "function.hxx"
18 #include "double.hxx"
19 #include "overload.hxx"
20 #include "configvariable.hxx"
21 
22 extern "C"
23 {
24 #include "Scierror.h"
25 #include "sciprint.h"
26 #include "localization.h"
27 #include "elem_common.h"
28 #include "log.h"
29 }
30 
31 /*
32 clear a;nb = 2500;a = rand(nb, nb);tic();log1p(a);toc
33 */
34 /*--------------------------------------------------------------------------*/
sci_log1p(types::typed_list & in,int _iRetCount,types::typed_list & out)35 types::Function::ReturnValue sci_log1p(types::typed_list &in, int _iRetCount, types::typed_list &out)
36 {
37     int iAlert = 1;
38 
39     if (in.size() != 1)
40     {
41         Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "log1p", 1);
42         return types::Function::Error;
43     }
44 
45     if (_iRetCount > 1)
46     {
47         Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "log1p", 1);
48         return types::Function::Error;
49     }
50 
51     if (in[0]->isDouble() == false)
52     {
53         std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_log1p";
54         return Overload::call(wstFuncName, in, _iRetCount, out);
55     }
56 
57     types::Double* pDblIn = in[0]->getAs<types::Double>();
58 
59     if (pDblIn->isComplex())
60     {
61         Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), "log1p", 1);
62         return types::Function::Error;
63     }
64 
65     double* pInR = pDblIn->get();
66     int size = pDblIn->getSize();
67     for (int i = 0; i < size; i++)
68     {
69         if (pInR[i] <= -1)
70         {
71             if (ConfigVariable::getIeee() == 0)
72             {
73                 Scierror(999, _("%s: Wrong value for input argument #%d : Singularity of the function.\n"), "log1p", 1);
74                 return types::Function::Error;
75             }
76             else if (ConfigVariable::getIeee() == 1)
77             {
78                 if (ConfigVariable::getWarningMode())
79                 {
80                     sciprint(_("%s: Warning: Wrong value for input argument #%d : Singularity of the function.\n"), "log1p", 1);
81                     break;
82                 }
83             }
84         }
85     }
86 
87     types::Double* pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray());
88     double* pOutR = pDblOut->get();
89 
90     for (int i = 0; i < size; i++)
91     {
92         pOutR[i] = dlog1ps(pInR[i]);
93     }
94 
95     out.push_back(pDblOut);
96     return types::Function::OK;
97 }
98 /*--------------------------------------------------------------------------*/
99