2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2013 - Scilab Enterprises - Cedric Delamarre
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
13 #include "types_ldivide.hxx"
14 #include "types_divide.hxx"
15 #include "types_finite.hxx"
19 #include "matrix_left_division.h"
21 #include "localization.h"
22 #include "charEncoding.h"
25 using namespace types;
27 InternalType *GenericLDivide(InternalType *_pLeftOperand, InternalType *_pRightOperand)
29 InternalType *pResult = NULL;
30 GenericType::ScilabType TypeL = _pLeftOperand->getType();
31 GenericType::ScilabType TypeR = _pRightOperand->getType();
35 if (_pLeftOperand->isDouble() && _pLeftOperand->getAs<Double>()->isEmpty())
37 return Double::Empty();
40 if (_pRightOperand->isDouble() && _pRightOperand->getAs<Double>()->isEmpty())
42 return Double::Empty();
48 if (TypeL == GenericType::ScilabDouble && TypeR == GenericType::ScilabDouble)
50 Double *pL = _pLeftOperand->getAs<Double>();
51 Double *pR = _pRightOperand->getAs<Double>();
53 iResult = LDivideDoubleByDouble(pL, pR, (Double**)&pResult);
59 if (TypeL == GenericType::ScilabDouble && TypeR == GenericType::ScilabSparse)
61 Double *pL = _pLeftOperand->getAs<Double>();
62 Sparse *pR = _pRightOperand->getAs<Sparse>();
64 iResult = RDivideSparseByDouble(pR, pL, &pResult);
73 throw ast::InternalError(_W("Inconsistent row/column dimensions.\n"));
75 throw ast::InternalError(_W("With NaN or Inf a left division by scalar expected.\n"));
77 throw ast::InternalError(_W("Left division by zero...\n"));
79 sciprint(_("Warning : Left division by zero...\n"));
82 sciprint(_("Operator \\ : Error %d not yet managed.\n"), iResult);
87 ** Default case : Return NULL will Call Overloading.
92 int LDivideDoubleByDouble(Double *_pDouble1, Double *_pDouble2, Double **_pDoubleOut)
96 //check finite values of _pDouble1 and _pDouble2
97 if (isDoubleFinite(_pDouble1) == false || isDoubleFinite(_pDouble2) == false)
99 if (_pDouble1->isScalar() == false)
105 if (_pDouble1->isScalar())
108 return RDivideDoubleByDouble(_pDouble2, _pDouble1, _pDoubleOut);
111 if (_pDouble2->isScalar())
113 // managed in %s_l_s, call overload
117 if (_pDouble1->getDims() > 2 || _pDouble2->getDims() > 2 || _pDouble1->getRows() != _pDouble2->getRows())
123 *_pDoubleOut = new Double(_pDouble1->getCols(), _pDouble2->getCols(), _pDouble1->isComplex() || _pDouble2->isComplex());
124 if ((*_pDoubleOut)->isComplex())
127 iErr = iLeftDivisionOfComplexMatrix(
128 _pDouble1->getReal(), _pDouble1->getImg(), _pDouble1->getRows(), _pDouble1->getCols(),
129 _pDouble2->getReal(), _pDouble2->getImg(), _pDouble2->getRows(), _pDouble2->getCols(),
130 (*_pDoubleOut)->getReal(), (*_pDoubleOut)->getImg(), (*_pDoubleOut)->getRows(), (*_pDoubleOut)->getCols(), &dblRcond);
135 iErr = iLeftDivisionOfRealMatrix(
136 _pDouble1->getReal(), _pDouble1->getRows(), _pDouble1->getCols(),
137 _pDouble2->getReal(), _pDouble2->getRows(), _pDouble2->getCols(),
138 (*_pDoubleOut)->getReal(), (*_pDoubleOut)->getRows(), (*_pDoubleOut)->getCols(), &dblRcond);