2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Anais AUBERT
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 /*--------------------------------------------------------------------------*/
17 #include "elem_func_gw.hxx"
18 #include "function.hxx"
21 #include "overload.hxx"
25 #include "basic_functions.h"
29 /*--------------------------------------------------------------------------*/
30 types::Function::ReturnValue sci_sign(types::typed_list &in, int _iRetCount, types::typed_list &out)
37 double *pdblReal = NULL;
38 double *pdblImg = NULL;
39 double *pdblRealRet = NULL;
40 double *pdblImgRet = NULL;
44 Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "sign", 1);
45 return types::Function::Error;
50 Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "sign", 1);
51 return types::Function::Error;
54 if (in[0]->isDouble())
56 types::Double* pDblIn = in[0]->getAs<types::Double>();
57 int dims = pDblIn->getDims();
58 int *dimsArray = pDblIn->getDimsArray();
59 int size = pDblIn->getSize();
61 if (pDblIn->isComplex())
63 types::Double* pOut = new types::Double(dims, dimsArray, true);
64 double *dOutR = pOut->getReal();
65 double *dOutImg = pOut->getImg() ;
66 double *dInR = pDblIn->getReal();
67 double *dInImg = pDblIn->getImg() ;
69 for (int i = 0; i < size; i++)
71 double dblTemp = dpythags(dInR[i], dInImg[i]);
79 dOutR[i] = dInR[i] / dblTemp;
80 dOutImg[i] = dInImg[i] / dblTemp;
88 types::Double* pOut = new types::Double(dims, dimsArray);
89 double * dOutR = pOut->getReal();
90 double * dInR = pDblIn->getReal();
92 for (int i = 0; i < size; i++)
94 dOutR[i] = dsignsEx(dInR[i]);
100 else if(in[0]->isInt())
102 switch (in[0]->getType())
104 case types::InternalType::ScilabInt8 :
105 out.push_back(in[0]->getAs<types::Int8>()->sign());
107 case types::InternalType::ScilabUInt8 :
108 out.push_back(in[0]->getAs<types::UInt8>()->sign());
110 case types::InternalType::ScilabInt16 :
111 out.push_back(in[0]->getAs<types::Int16>()->sign());
113 case types::InternalType::ScilabUInt16 :
114 out.push_back(in[0]->getAs<types::UInt16>()->sign());
116 case types::InternalType::ScilabInt32 :
117 out.push_back(in[0]->getAs<types::Int32>()->sign());
119 case types::InternalType::ScilabUInt32 :
120 out.push_back(in[0]->getAs<types::UInt32>()->sign());
122 case types::InternalType::ScilabInt64 :
123 out.push_back(in[0]->getAs<types::Int64>()->sign());
125 case types::InternalType::ScilabUInt64 :
126 out.push_back(in[0]->getAs<types::UInt64>()->sign());
132 std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_sign";
133 return Overload::call(wstFuncName, in, _iRetCount, out);
136 return types::Function::OK;
138 /*--------------------------------------------------------------------------*/