fix and test
[scilab.git] / scilab / modules / ast / src / cpp / operations / types_power.cpp
1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
4 *
5 *  This file must be used under the terms of the CeCILL.
6 *  This source file is licensed as described in the file COPYING, which
7 *  you should have received as part of this distribution.  The terms
8 *  are also available at
9 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
13 #include "types_power.hxx"
14 #include "types_multiplication.hxx"
15 #include "scilabexception.hxx"
16
17 extern "C"
18 {
19 #include "operation_f.h"
20 #include "matrix_power.h"
21 #include "localization.h"
22 #include "charEncoding.h"
23 }
24
25 InternalType *GenericPower(InternalType *_pLeftOperand, InternalType *_pRightOperand)
26 {
27     InternalType *pResult = NULL;
28
29     /*
30     ** DOUBLE ^ DOUBLE
31     ** DOUBLE ** DOUBLE
32     */
33     if (_pLeftOperand->isDouble() && _pRightOperand->isDouble())
34     {
35         Double *pL   = _pLeftOperand->getAs<Double>();
36         Double *pR   = _pRightOperand->getAs<Double>();
37
38         int iResult = PowerDoubleByDouble(pL, pR, (Double**)&pResult);
39         if (iResult)
40         {
41             throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
42         }
43
44         return pResult;
45     }
46
47     /*
48     ** POLY ^ DOUBLE
49     ** POLY ** DOUBLE
50     */
51     if (_pLeftOperand->isPoly() && _pRightOperand->isDouble())
52     {
53         Polynom *pL   = _pLeftOperand->getAs<Polynom>();
54         Double *pR    = _pRightOperand->getAs<Double>();
55
56         int iResult = PowerPolyByDouble(pL, pR, &pResult);
57         switch (iResult)
58         {
59             case 1 :
60                 throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
61             case 2 :
62                 throw ast::ScilabError(_W("Invalid exponent.\n"));
63             default:
64                 //OK
65                 break;
66         }
67
68         return pResult;
69     }
70
71     /*
72     ** Default case : Return NULL will Call Overloading.
73     */
74     return NULL;
75
76 }
77
78 InternalType *GenericDotPower(InternalType *_pLeftOperand, InternalType *_pRightOperand)
79 {
80     InternalType *pResult = NULL;
81     GenericType::ScilabType TypeL = _pLeftOperand->getType();
82     GenericType::ScilabType TypeR = _pRightOperand->getType();
83
84     /*
85     ** DOUBLE .^ DOUBLE
86     ** DOUBLE .** DOUBLE
87     */
88     if (TypeL == GenericType::ScilabDouble && TypeR == GenericType::ScilabDouble)
89     {
90         Double *pL  = _pLeftOperand->getAs<Double>();
91         Double *pR  = _pRightOperand->getAs<Double>();
92
93         int iResult = DotPowerDoubleByDouble(pL, pR, (Double**)&pResult);
94         if (iResult)
95         {
96             throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
97         }
98
99         return pResult;
100     }
101
102     /*
103     ** POLY .^ DOUBLE
104     ** POLY .** DOUBLE
105     */
106     if (TypeL == GenericType::ScilabPolynom && TypeR == GenericType::ScilabDouble)
107     {
108         Polynom *pL   = _pLeftOperand->getAs<Polynom>();
109         Double *pR   = _pRightOperand->getAs<Double>();
110
111         int iResult = DotPowerPolyByDouble(pL, pR, &pResult);
112         switch (iResult)
113         {
114             case 1 :
115                 throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
116             case 2 :
117                 throw ast::ScilabError(_W("Invalid exponent.\n"));
118             default:
119                 //OK
120                 break;
121         }
122         return pResult;
123     }
124
125     /*
126     ** Default case : Return NULL will Call Overloading.
127     */
128     return NULL;
129
130 }
131
132 int PowerDoubleByDouble(Double* _pDouble1, Double* _pDouble2, Double** _pDoubleOut)
133 {
134     bool bComplex1  = _pDouble1->isComplex();
135     bool bComplex2  = _pDouble2->isComplex();
136     bool bScalar1   = _pDouble1->isScalar();
137     bool bScalar2   = _pDouble2->isScalar();
138
139     int iComplex = 1;
140
141     if (bScalar1 && bScalar2)
142     {
143         //s ^ s
144         *_pDoubleOut = new Double(1, 1, true);
145
146         if (bComplex1 == false && bComplex2 == false)
147         {
148             iPowerRealScalarByRealScalar(_pDouble1->get(0), _pDouble2->get(0), (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg(), &iComplex);
149         }
150         else if (bComplex1 == false && bComplex2 == true)
151         {
152             iPowerRealScalarByComplexScalar(_pDouble1->get(0), _pDouble2->get(0), _pDouble2->getImg(0), (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg());
153         }
154         else if (bComplex1 == true && bComplex2 == false)
155         {
156             iPowerComplexScalarByRealScalar(_pDouble1->get(0), _pDouble1->getImg(0), _pDouble2->get(0), (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg());
157         }
158         else if (bComplex1 == true && bComplex2 == true)
159         {
160             iPowerComplexScalarByComplexScalar(_pDouble1->get(0), _pDouble1->getImg(0), _pDouble2->get(0), _pDouble2->getImg(0), (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg());
161         }
162
163         if (iComplex == 0)
164         {
165             (*_pDoubleOut)->setComplex(false);
166         }
167
168         return 0;
169     }
170     else if (bScalar1 && _pDouble2->getDims() == 2)
171     {
172         //s ^ []
173         *_pDoubleOut = new Double(_pDouble2->getRows(), _pDouble2->getCols(), true);
174
175         if (bComplex1 == false && bComplex2 == false)
176         {
177             iPowerRealScalarByRealMatrix(
178                 _pDouble1->get(0),
179                 _pDouble2->get(), _pDouble2->getRows(), _pDouble2->getCols(),
180                 (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg(), &iComplex);
181         }
182         else if (bComplex1 == false && bComplex2 == true)
183         {
184             iPowerRealScalarByComplexMatrix(
185                 _pDouble1->get(0),
186                 _pDouble2->get(), _pDouble2->getImg(), _pDouble2->getRows(), _pDouble2->getCols(),
187                 (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg());
188         }
189         else if (bComplex1 == true && bComplex2 == false)
190         {
191             iPowerComplexScalarByRealMatrix(
192                 _pDouble1->get(0), _pDouble1->getImg(0),
193                 _pDouble2->get(), _pDouble2->getRows(), _pDouble2->getCols(),
194                 (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg());
195         }
196         else if (bComplex1 == true && bComplex2 == true)
197         {
198             iPowerComplexScalarByComplexMatrix(
199                 _pDouble1->get(0), _pDouble1->getImg(0),
200                 _pDouble2->get(), _pDouble2->getImg(), _pDouble2->getRows(), _pDouble2->getCols(),
201                 (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg());
202         }
203
204         if (iComplex == 0)
205         {
206             (*_pDoubleOut)->setComplex(false);
207         }
208
209         return 0;
210     }
211
212     if (bScalar2 && _pDouble1->getDims() == 2 && _pDouble1->isVector() )
213     {
214         //_pDouble1 is a vector and _pDouble is a scalar
215         *_pDoubleOut = new Double(_pDouble1->getRows(), _pDouble1->getCols() , true);
216
217         if (bComplex1 == false && bComplex2 == false)
218         {
219             for (int i = 0 ; i < (*_pDoubleOut)->getSize() ; i++)
220             {
221                 iPowerRealScalarByRealScalar(
222                     _pDouble1->get(i),
223                     _pDouble2->get(0),
224                     &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i], &iComplex);
225             }
226         }
227         else if (bComplex1 == false && bComplex2 == true)
228         {
229             for (int i = 0 ; i < (*_pDoubleOut)->getSize() ; i++)
230             {
231                 iPowerRealScalarByComplexScalar(
232                     _pDouble1->get(i),
233                     _pDouble2->get(0), _pDouble2->getImg(0),
234                     &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
235             }
236         }
237         else if (bComplex1 == true && bComplex2 == false)
238         {
239             for (int i = 0 ; i < (*_pDoubleOut)->getSize() ; i++)
240             {
241                 iPowerComplexScalarByRealScalar(
242                     _pDouble1->get(i), _pDouble1->getImg(i),
243                     _pDouble2->get(0),
244                     &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
245             }
246         }
247         else if (bComplex1 == true && bComplex2 == true)
248         {
249             for (int i = 0 ; i < (*_pDoubleOut)->getSize() ; i++)
250             {
251                 iPowerComplexScalarByComplexScalar(
252                     _pDouble1->get(i), _pDouble1->getImg(i),
253                     _pDouble2->get(0), _pDouble2->getImg(0),
254                     &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
255             }
256         }
257
258         if (iComplex == 0)
259         {
260             (*_pDoubleOut)->setComplex(false);
261         }
262
263         return 0;
264     }
265
266     if (bScalar2 && ( _pDouble1->getRows() == _pDouble1->getCols()))
267     {
268         //power of a square matrix by a scalar exponent.
269         int iRet = 0;
270         if (bComplex2)
271         {
272             //mange by overloading
273             return 0;
274         }
275
276         *_pDoubleOut = new Double(_pDouble1->getRows(), _pDouble1->getCols() , true);
277         if (bComplex1 == false)
278         {
279             iRet = iPowerRealSquareMatrixByRealScalar(
280                        _pDouble1->get(), _pDouble1->getRows(), _pDouble1->getCols(),
281                        _pDouble2->get(0),
282                        (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg(), &iComplex);
283         }
284         else if (bComplex1 == true)
285         {
286             iRet = iPowerComplexSquareMatrixByRealScalar(
287                        _pDouble1->get(), _pDouble1->getImg(), _pDouble1->getRows(), _pDouble1->getCols(),
288                        _pDouble2->get(0),
289                        (*_pDoubleOut)->get(), (*_pDoubleOut)->getImg());
290         }
291
292         // call overload
293         if (iRet == -1)
294         {
295             delete *_pDoubleOut;
296             *_pDoubleOut = NULL;
297             return 0;
298         }
299
300         if (iComplex == 0)
301         {
302             (*_pDoubleOut)->setComplex(false);
303         }
304     }
305     return 0;
306 }
307
308 int PowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut)
309 {
310     bool bComplex1  = _pPoly->isComplex();
311     bool bComplex2  = _pDouble->isComplex();
312     bool bScalar1   = _pPoly->isScalar();
313
314     if (bComplex2)
315     {
316         //invalid exponent.
317         return 2;
318     }
319
320     if (_pDouble->isEmpty())
321     {
322         //p ** []
323         *_pOut = Double::Empty();
324         return 0;
325     }
326
327     if (bScalar1)
328     {
329         //p ^ x or p ^ X
330         int iRank   = 0;
331         int* piRank = new int[_pDouble->getSize()];
332
333         _pPoly->getRank(&iRank);
334         for (int i = 0 ; i < _pDouble->getSize() ; i++)
335         {
336             int iInputRank = (int)_pDouble->get(i);
337             if (iInputRank < 0)
338             {
339                 //call overload
340                 _pOut = NULL;
341                 delete[] piRank;
342                 return 0;
343             }
344
345             piRank[i] = iRank * iInputRank;
346         }
347
348         Polynom* pOut = new Polynom(_pPoly->getVariableName(), _pDouble->getRows(), _pDouble->getCols(), piRank);
349         pOut->setComplex(bComplex1);
350
351         for (int i = 0 ; i < _pDouble->getSize() ; i++)
352         {
353             SinglePoly* pCoeffOut = pOut->get(i);
354
355             int iCurrentRank    = 0;
356             int iLoop           = (int)_pDouble->get(i);
357
358             //initialize Out to 1
359             pCoeffOut->set(0, 1);
360             //get a copy of p
361             Polynom* pP = _pPoly->clone()->getAs<Polynom>();
362             pP->setComplex(_pPoly->isComplex());
363
364             while (iLoop)
365             {
366                 if (iLoop % 2)
367                 {
368                     int iRank = pP->getMaxRank();
369                     if (bComplex1)
370                     {
371                         C2F(wpmul1)(pCoeffOut->get(), pCoeffOut->getImg(), &iCurrentRank, pP->getCoef()->get(), pP->getCoef()->getImg(), &iRank, pCoeffOut->get(), pCoeffOut->getImg());
372                     }
373                     else
374                     {
375                         C2F(dpmul1)(pCoeffOut->get(), &iCurrentRank, pP->getCoef()->get(), &iRank, pCoeffOut->get());
376                     }
377                     iCurrentRank += iRank;
378                 }
379
380                 iLoop /= 2;
381                 if (iLoop)
382                 {
383                     //p = p * p
384                     Polynom* pTemp = NULL;
385                     MultiplyPolyByPoly(pP, pP, &pTemp);
386                     delete pP;
387                     pP = pTemp;
388                 }
389             }
390         }
391         *_pOut = pOut;
392     }
393     return 0;
394 }
395
396 int DotPowerPolyByDouble(Polynom* _pPoly, Double* _pDouble, InternalType** _pOut)
397 {
398     if (_pDouble->isEmpty())
399     {
400         //p .^ []
401         *_pOut = Double::Empty();
402         return 0;
403     }
404
405     int iSize = _pPoly->getSize();
406     Double** pDblPower  = new Double*[iSize];
407     double* pdblPower   = _pDouble->get();
408     if (_pPoly->isScalar())
409     {
410         return PowerPolyByDouble(_pPoly, _pDouble, _pOut);
411     }
412     else if (_pDouble->isScalar())
413     {
414         if (pdblPower[0] < 0)
415         {
416             //call overload
417             _pOut = NULL;
418             delete[] pDblPower;
419             return 0;
420         }
421
422         for (int i = 0; i < iSize; i++)
423         {
424             pDblPower[i] = new Double(pdblPower[0]);
425         }
426     }
427     else if (_pDouble->getSize() == iSize)
428     {
429         for (int i = 0; i < iSize; i++)
430         {
431             if (pdblPower[i] < 0)
432             {
433                 //call overload
434                 _pOut = NULL;
435                 delete[] pDblPower;
436                 return 0;
437             }
438
439             pDblPower[i] = new Double(pdblPower[i]);
440         }
441     }
442     else
443     {
444         delete[] pDblPower;
445         throw ast::ScilabError(_W("Invalid exponent.\n"));
446     }
447
448     InternalType* pITTempOut    = NULL;
449     Polynom* pPolyTemp          = new Polynom(_pPoly->getVariableName(), 1, 1);
450     Polynom* pPolyOut           = new Polynom(_pPoly->getVariableName(), _pPoly->getDims(), _pPoly->getDimsArray());
451     SinglePoly** pSPOut         = pPolyOut->get();
452     SinglePoly** pSPTemp        = pPolyTemp->get();
453     SinglePoly** pSP            = _pPoly->get();
454
455     int iResult = 0;
456     for (int i = 0; i < iSize; i++)
457     {
458         // set singlePoly of _pPoly in pPolyTemp without copy
459         pSPTemp[0] = pSP[i];
460         iResult = PowerPolyByDouble(pPolyTemp, pDblPower[i], &pITTempOut);
461         if (iResult)
462         {
463             break;
464         }
465
466         // get singlePoly of pITTempOut and set it in pPolyOut without copy
467         SinglePoly** pSPTempOut = pITTempOut->getAs<Polynom>()->get();
468         pSPOut[i] = pSPTempOut[0];
469         pSPTempOut[0] = NULL;
470         delete pITTempOut;
471     }
472
473     // delete exp
474     for (int i = 0; i < iSize; i++)
475     {
476         delete pDblPower[i];
477     }
478
479     delete pDblPower;
480
481     // delete temporary polynom
482     // do not delete the last SinglePoly of _pPoly setted without copy in pPolyTemp
483     pSPTemp[0] = NULL;
484     delete pPolyTemp;
485
486     switch (iResult)
487     {
488         case 1 :
489         {
490             delete pPolyOut;
491             throw ast::ScilabError(_W("Inconsistent row/column dimensions.\n"));
492         }
493         case 2 :
494         {
495             delete pPolyOut;
496             throw ast::ScilabError(_W("Invalid exponent.\n"));
497         }
498         default:
499             //OK
500             break;
501     }
502
503     *_pOut = pPolyOut;
504     return 0;
505 }
506
507 int DotPowerDoubleByDouble(Double* _pDouble1, Double* _pDouble2, Double** _pDoubleOut)
508 {
509     int iResultComplex = 0;
510
511     if (_pDouble1->isEmpty() || _pDouble2->isEmpty())
512     {
513         *_pDoubleOut = Double::Empty();
514     }
515     else if (_pDouble1->isIdentity())
516     {
517         return 1;
518     }
519     else if (_pDouble2->isIdentity())
520     {
521         *_pDoubleOut = dynamic_cast<Double*>(_pDouble1->clone());
522     }
523     else if (_pDouble1->isScalar())
524     {
525         //a .^ (b or B)
526         *_pDoubleOut = new Double(_pDouble2->getDims() , _pDouble2->getDimsArray(), true);
527
528         if (_pDouble1->isComplex())
529         {
530             double dblR1 = _pDouble1->get(0);
531             double dblI1 = _pDouble1->getImg(0);
532
533             if (_pDouble2->isComplex())
534             {
535                 iResultComplex = 1;
536                 for (int i = 0 ; i < _pDouble2->getSize() ; i++)
537                 {
538                     iPowerComplexScalarByComplexScalar(
539                         dblR1, dblI1,
540                         _pDouble2->get(i), _pDouble2->getImg(i),
541                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
542                 }
543             }
544             else
545             {
546                 iResultComplex = 1;
547                 for (int i = 0 ; i < _pDouble2->getSize() ; i++)
548                 {
549                     iPowerComplexScalarByRealScalar(
550                         dblR1, dblI1,
551                         _pDouble2->get(i),
552                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
553                 }
554             }
555         }
556         else
557         {
558             double dblR1 = _pDouble1->get(0);
559             if (_pDouble2->isComplex())
560             {
561                 iResultComplex = 1;
562                 for (int i = 0 ; i < _pDouble2->getSize() ; i++)
563                 {
564                     iPowerRealScalarByComplexScalar(
565                         dblR1,
566                         _pDouble2->get(i), _pDouble2->getImg(i),
567                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
568                 }
569             }
570             else
571             {
572                 for (int i = 0 ; i < _pDouble2->getSize() ; i++)
573                 {
574                     int iComplex = 1;
575                     iPowerRealScalarByRealScalar(
576                         dblR1,
577                         _pDouble2->get(i),
578                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i], &iComplex);
579                     iResultComplex |= iComplex;
580                 }
581             }
582         }
583     }
584     else if (_pDouble2->isScalar())
585     {
586         //A .^ b
587         *_pDoubleOut = new Double(_pDouble1->getDims() , _pDouble1->getDimsArray(), true);
588         if (_pDouble1->isComplex())
589         {
590             double dblR2 = _pDouble2->get(0);
591             if (_pDouble2->isComplex())
592             {
593                 double dblI2 = _pDouble2->getImg(0);
594                 iResultComplex = 1;
595                 for (int i = 0 ; i < _pDouble1->getSize() ; i++)
596                 {
597                     iPowerComplexScalarByComplexScalar(
598                         _pDouble1->get(i), _pDouble1->getImg(i),
599                         dblR2, dblI2,
600                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
601                 }
602             }
603             else
604             {
605                 double dblR2 = _pDouble2->get(0);
606                 iResultComplex = 1;
607                 for (int i = 0 ; i < _pDouble1->getSize() ; i++)
608                 {
609                     iPowerComplexScalarByRealScalar(
610                         _pDouble1->get(i), _pDouble1->getImg(i),
611                         dblR2,
612                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
613                 }
614             }
615         }
616         else
617         {
618             double dblR2 = _pDouble2->get(0);
619             if (_pDouble2->isComplex())
620             {
621                 double dblI2 = _pDouble2->getImg(0);
622                 iResultComplex = 1;
623                 for (int i = 0 ; i < _pDouble1->getSize() ; i++)
624                 {
625                     iPowerRealScalarByComplexScalar(
626                         _pDouble1->get(i),
627                         dblR2, dblI2,
628                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
629                 }
630             }
631             else
632             {
633                 for (int i = 0 ; i < _pDouble1->getSize() ; i++)
634                 {
635                     int iComplex = 1;
636                     iPowerRealScalarByRealScalar(
637                         _pDouble1->get(i),
638                         dblR2,
639                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i], &iComplex);
640                     iResultComplex |= iComplex;
641                 }
642             }
643         }
644     }
645     else
646     {
647         //A .^ B
648         //check dimension compatibilities ( same number of dimension and same size for each dimension
649         int iDims1      = _pDouble1->getDims();
650         int* piDims1    = _pDouble1->getDimsArray();
651         int iDims2      = _pDouble2->getDims();
652         int* piDims2    = _pDouble2->getDimsArray();
653
654         if (iDims1 != iDims2)
655         {
656             return 1;
657         }
658
659         for (int i = 0 ; i < iDims1 ; i++)
660         {
661             if (piDims1[i] != piDims2[i])
662             {
663                 return 1;
664             }
665         }
666
667         (*_pDoubleOut) = new Double(iDims2, piDims2, true);
668
669         if (_pDouble1->isComplex())
670         {
671             if (_pDouble2->isComplex())
672             {
673                 iResultComplex = 1;
674                 for (int i = 0 ; i < _pDouble1->getSize() ; i++)
675                 {
676                     iPowerComplexScalarByComplexScalar(
677                         _pDouble1->get(i), _pDouble1->getImg(i),
678                         _pDouble2->get(i), _pDouble2->getImg(i),
679                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
680                 }
681             }
682             else
683             {
684                 iResultComplex = 1;
685                 for (int i = 0 ; i < _pDouble1->getSize() ; i++)
686                 {
687                     iPowerComplexScalarByRealScalar(
688                         _pDouble1->get(i), _pDouble1->getImg(i),
689                         _pDouble2->get(i),
690                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
691                 }
692             }
693         }
694         else
695         {
696             if (_pDouble2->isComplex())
697             {
698                 iResultComplex = 1;
699                 for (int i = 0 ; i < _pDouble1->getSize() ; i++)
700                 {
701                     iPowerRealScalarByComplexScalar(
702                         _pDouble1->get(i),
703                         _pDouble2->get(i), _pDouble2->getImg(i),
704                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i]);
705                 }
706             }
707             else
708             {
709                 for (int i = 0 ; i < _pDouble1->getSize() ; i++)
710                 {
711                     int iComplex = 1;
712                     iPowerRealScalarByRealScalar(
713                         _pDouble1->get(i),
714                         _pDouble2->get(i),
715                         &(*_pDoubleOut)->get()[i], &(*_pDoubleOut)->getImg()[i], &iComplex);
716                     iResultComplex |= iComplex;
717                 }
718             }
719         }
720     }
721
722     if (iResultComplex == 0)
723     {
724         (*_pDoubleOut)->setComplex(false);
725     }
726     return 0;
727 }
728