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
21 extern "C"
22 {
23 #include "Scierror.h"
24 #include "localization.h"
25 #include "sin.h"
26 int C2F(wasin)(double*, double*, double*, double*);
27 }
28
29 /*
30 clear a;nb = 2500;a = rand(nb, nb);tic();asin(a);toc
31 clear a;nb = 2500;a = rand(nb, nb) + 0.5;tic();asin(a);toc
32 clear a;nb = 2500;a = rand(nb, nb); a = a + a *%i;tic();asin(a);toc
33 */
34 /*--------------------------------------------------------------------------*/
sci_asin(types::typed_list & in,int _iRetCount,types::typed_list & out)35 types::Function::ReturnValue sci_asin(types::typed_list &in, int _iRetCount, types::typed_list &out)
36 {
37 types::Double* pDblIn = NULL;
38 types::Double* pDblOut = NULL;
39
40 if (in.size() != 1)
41 {
42 Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "asin", 1);
43 return types::Function::Error;
44 }
45
46 if (_iRetCount > 1)
47 {
48 Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "asin", 1);
49 return types::Function::Error;
50 }
51
52 if (in[0]->isDouble() == false)
53 {
54 std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_asin";
55 return Overload::call(wstFuncName, in, _iRetCount, out);
56 }
57
58 pDblIn = in[0]->getAs<types::Double>();
59
60 if (pDblIn->isComplex())
61 {
62 pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray(), true);
63 int size = pDblIn->getSize();
64
65 double* pInR = pDblIn->get();
66 double* pInI = pDblIn->getImg();
67 double* pOutR = pDblOut->get();
68 double* pOutI = pDblOut->getImg();
69
70 for (int i = 0; i < size; i++)
71 {
72 C2F(wasin)(pInR + i, pInI + i, pOutR + i, pOutI + i);
73 }
74 }
75 else
76 {
77 bool bOutSide = 0;
78 //check if all variables are between [-1,1]
79 double* pInR = pDblIn->get();
80 int size = pDblIn->getSize();
81 for (int i = 0; i < size; i++)
82 {
83 if (std::fabs(pInR[i]) > 1)
84 {
85 bOutSide = 1;
86 break;
87 }
88 }
89
90 if (bOutSide) // Values outside [-1,1]
91 {
92 pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray(), true);
93 double* pOutR = pDblOut->get();
94 double* pOutI = pDblOut->getImg();
95 double zero = 0;
96 for (int i = 0; i < size; i++)
97 {
98 C2F(wasin)(pInR + i, &zero, pOutR + i, pOutI + i);
99 }
100 }
101 else //all values are in [-1,1]
102 {
103 pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray(), false);
104 double* pOutR = pDblOut->get();
105 for (int i = 0; i < size; i++)
106 {
107 pOutR[i] = std::asin(pInR[i]);
108 }
109 }
110 }
111
112 out.push_back(pDblOut);
113 return types::Function::OK;
114 }
115 /*--------------------------------------------------------------------------*/
116