xref: /AOO41X/main/sc/source/core/tool/scmatrix.cxx (revision 245212b4a6344def03df5c29631ba99a8d6dbb8e)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "scmatrix.hxx"
30cdf0e10cSrcweir #include "global.hxx"
31cdf0e10cSrcweir #include "address.hxx"
32cdf0e10cSrcweir #include "formula/errorcodes.hxx"
33cdf0e10cSrcweir #include "interpre.hxx"
34cdf0e10cSrcweir #include <svl/zforlist.hxx>
35cdf0e10cSrcweir #include <tools/stream.hxx>
36cdf0e10cSrcweir #include <rtl/math.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <math.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //------------------------------------------------------------------------
41cdf0e10cSrcweir 
CreateMatrix(SCSIZE nC,SCSIZE nR)42cdf0e10cSrcweir void ScMatrix::CreateMatrix(SCSIZE nC, SCSIZE nR)		// nur fuer ctor
43cdf0e10cSrcweir {
44cdf0e10cSrcweir     pErrorInterpreter = NULL;
45cdf0e10cSrcweir 	nColCount = nC;
46cdf0e10cSrcweir 	nRowCount = nR;
47cdf0e10cSrcweir 	SCSIZE nCount = nColCount * nRowCount;
48cdf0e10cSrcweir 	if ( !nCount || nCount > GetElementsMax() )
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::CreateMatrix: dimension error");
51cdf0e10cSrcweir 		nColCount = nRowCount = 1;
52cdf0e10cSrcweir 		pMat = new ScMatrixValue[1];
53cdf0e10cSrcweir         pMat[0].fVal = CreateDoubleError( errStackOverflow);
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir 	else
56cdf0e10cSrcweir 		pMat = new ScMatrixValue[nCount];
57cdf0e10cSrcweir 	mnValType = NULL;
58cdf0e10cSrcweir     mnNonValue = 0;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
Clear()61cdf0e10cSrcweir void ScMatrix::Clear()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     DeleteIsString();
64cdf0e10cSrcweir     delete [] pMat;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
~ScMatrix()67cdf0e10cSrcweir ScMatrix::~ScMatrix()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     Clear();
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
Clone() const72cdf0e10cSrcweir ScMatrix* ScMatrix::Clone() const
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     ScMatrix* pScMat = new ScMatrix( nColCount, nRowCount);
75cdf0e10cSrcweir 	MatCopy(*pScMat);
76cdf0e10cSrcweir     pScMat->SetErrorInterpreter( pErrorInterpreter);    // TODO: really?
77cdf0e10cSrcweir 	return pScMat;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
CloneIfConst()80cdf0e10cSrcweir ScMatrix* ScMatrix::CloneIfConst()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     return (mbCloneIfConst || IsEternalRef()) ? Clone() : this;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
Resize(SCSIZE nC,SCSIZE nR)85cdf0e10cSrcweir void ScMatrix::Resize( SCSIZE nC, SCSIZE nR)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     Clear();
88cdf0e10cSrcweir     CreateMatrix(nC, nR);
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
CloneAndExtend(SCSIZE nNewCols,SCSIZE nNewRows) const91cdf0e10cSrcweir ScMatrix* ScMatrix::CloneAndExtend( SCSIZE nNewCols, SCSIZE nNewRows ) const
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     ScMatrix* pScMat = new ScMatrix( nNewCols, nNewRows);
94cdf0e10cSrcweir     MatCopy(*pScMat);
95cdf0e10cSrcweir     pScMat->SetErrorInterpreter( pErrorInterpreter);
96cdf0e10cSrcweir     return pScMat;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
SetErrorAtInterpreter(sal_uInt16 nError) const99cdf0e10cSrcweir void ScMatrix::SetErrorAtInterpreter( sal_uInt16 nError ) const
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     if ( pErrorInterpreter )
102cdf0e10cSrcweir         pErrorInterpreter->SetError( nError);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir //
106cdf0e10cSrcweir //	File format: sal_uInt16 columns, sal_uInt16 rows, (columns*rows) entries:
107cdf0e10cSrcweir //	sal_uInt8 type ( CELLTYPE_NONE, CELLTYPE_VALUE, CELLTYPE_STRING ); nothing, double or String
108cdf0e10cSrcweir //
109cdf0e10cSrcweir 
ScMatrix(SvStream &)110cdf0e10cSrcweir ScMatrix::ScMatrix(SvStream& /* rStream */)
111cdf0e10cSrcweir         : pErrorInterpreter( NULL)
112cdf0e10cSrcweir         , nRefCnt(0)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir #if SC_ROWLIMIT_STREAM_ACCESS
115cdf0e10cSrcweir #error address types changed!
116cdf0e10cSrcweir 	sal_uInt16 nC;
117cdf0e10cSrcweir 	sal_uInt16 nR;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	rStream >> nC;
120cdf0e10cSrcweir 	rStream >> nR;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	CreateMatrix(nC, nR);
123cdf0e10cSrcweir 	DBG_ASSERT( pMat, "pMat == NULL" );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	String aMatStr;
126cdf0e10cSrcweir 	double fVal;
127cdf0e10cSrcweir 	rtl_TextEncoding eCharSet = rStream.GetStreamCharSet();
128cdf0e10cSrcweir 	SCSIZE nCount = nColCount * nRowCount;
129cdf0e10cSrcweir 	SCSIZE nReadCount = (SCSIZE) nC * nR;
130cdf0e10cSrcweir 	for (SCSIZE i=0; i<nReadCount; i++)
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir 		sal_uInt8 nType;
133cdf0e10cSrcweir 		rStream >> nType;
134cdf0e10cSrcweir 		if ( nType == CELLTYPE_VALUE )
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir 			if ( i < nCount )
137cdf0e10cSrcweir 				rStream >> pMat[i].fVal;
138cdf0e10cSrcweir 			else
139cdf0e10cSrcweir 				rStream >> fVal;
140cdf0e10cSrcweir 		}
141cdf0e10cSrcweir 		else
142cdf0e10cSrcweir 		{
143cdf0e10cSrcweir 			// For unknown types read and forget string (upwards compatibility)
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 			if ( nType != CELLTYPE_NONE )
146cdf0e10cSrcweir 				rStream.ReadByteString( aMatStr, eCharSet );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 			if ( i < nCount )
149cdf0e10cSrcweir 			{
150cdf0e10cSrcweir 				if (!mnValType)
151cdf0e10cSrcweir 					ResetIsString();		// init string flags
152cdf0e10cSrcweir 				mnValType[i] = ( nType == CELLTYPE_NONE ? SC_MATVAL_EMPTY : SC_MATVAL_STRING );
153cdf0e10cSrcweir                 mnNonValue++;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 				if ( nType == CELLTYPE_STRING )
156cdf0e10cSrcweir 					pMat[i].pS = new String(aMatStr);
157cdf0e10cSrcweir 				else
158cdf0e10cSrcweir 					pMat[i].pS = NULL;
159cdf0e10cSrcweir 			}
160cdf0e10cSrcweir 		}
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir #else
163cdf0e10cSrcweir 	CreateMatrix(0,0);
164cdf0e10cSrcweir #endif // SC_ROWLIMIT_STREAM_ACCESS
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
Store(SvStream &) const167cdf0e10cSrcweir void ScMatrix::Store(SvStream& /* rStream */) const
168cdf0e10cSrcweir {
169cdf0e10cSrcweir #if SC_ROWLIMIT_STREAM_ACCESS
170cdf0e10cSrcweir #error address types changed!
171cdf0e10cSrcweir 	SCSIZE nCount = nColCount * nRowCount;
172cdf0e10cSrcweir 	// Don't store matrix with more than sal_uInt16 max elements, old versions
173cdf0e10cSrcweir 	// might get confused in loops for(sal_uInt16 i=0; i<nC*nR; i++)
174cdf0e10cSrcweir 	if ( !pMat || nCount > ((sal_uInt16)(~0)) )
175cdf0e10cSrcweir 	{
176cdf0e10cSrcweir 		DBG_ASSERT( pMat, "ScMatrix::Store: pMat == NULL" );
177cdf0e10cSrcweir 		// We can't store a 0 dimension because old versions rely on some
178cdf0e10cSrcweir 		// matrix being present, e.g. DDE link results, and old versions didn't
179cdf0e10cSrcweir 		// create a matrix if dimension was 0. Store an error result.
180cdf0e10cSrcweir 		rStream << (sal_uInt16) 1;
181cdf0e10cSrcweir 		rStream << (sal_uInt16) 1;
182cdf0e10cSrcweir 		rStream << (sal_uInt8) CELLTYPE_VALUE;
183cdf0e10cSrcweir 		double fVal;
184cdf0e10cSrcweir 		::rtl::math::setNan( &fVal );
185cdf0e10cSrcweir 		rStream << fVal;
186cdf0e10cSrcweir 		return;
187cdf0e10cSrcweir 	}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	rStream << (sal_uInt16) nColCount;
190cdf0e10cSrcweir #if SC_ROWLIMIT_MORE_THAN_32K
191cdf0e10cSrcweir     #error row32k
192cdf0e10cSrcweir #endif
193cdf0e10cSrcweir 	rStream << (sal_uInt16) nRowCount;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	String aMatStr;
196cdf0e10cSrcweir 	rtl_TextEncoding eCharSet = rStream.GetStreamCharSet();
197cdf0e10cSrcweir 	for (SCSIZE i=0; i<nCount; i++)
198cdf0e10cSrcweir 	{
199cdf0e10cSrcweir 		sal_uInt8 nType = CELLTYPE_VALUE;
200cdf0e10cSrcweir 		if ( mnValType && IsNonValueType( mnValType[i]))
201cdf0e10cSrcweir 		{
202cdf0e10cSrcweir 			if ( pMat[i].pS )
203cdf0e10cSrcweir 				aMatStr = *pMat[i].pS;
204cdf0e10cSrcweir 			else
205cdf0e10cSrcweir 				aMatStr.Erase();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 			if ( mnValType[i] == SC_MATVAL_STRING )
208cdf0e10cSrcweir 				nType = CELLTYPE_STRING;
209cdf0e10cSrcweir 			else
210cdf0e10cSrcweir 				nType = CELLTYPE_NONE;
211cdf0e10cSrcweir 		}
212cdf0e10cSrcweir 		rStream << nType;
213cdf0e10cSrcweir 		if ( nType == CELLTYPE_VALUE )
214cdf0e10cSrcweir 			rStream << pMat[i].fVal;
215cdf0e10cSrcweir 		else if ( nType == CELLTYPE_STRING )
216cdf0e10cSrcweir 			rStream.WriteByteString( aMatStr, eCharSet );
217cdf0e10cSrcweir 	}
218cdf0e10cSrcweir #endif // SC_ROWLIMIT_STREAM_ACCESS
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
ResetIsString()221cdf0e10cSrcweir void ScMatrix::ResetIsString()
222cdf0e10cSrcweir {
223cdf0e10cSrcweir 	SCSIZE nCount = nColCount * nRowCount;
224cdf0e10cSrcweir 	if (mnValType)
225cdf0e10cSrcweir 	{
226cdf0e10cSrcweir 		for (SCSIZE i = 0; i < nCount; i++)
227cdf0e10cSrcweir 		{
228cdf0e10cSrcweir 			if ( IsNonValueType( mnValType[i]))
229cdf0e10cSrcweir 				delete pMat[i].pS;
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 	}
232cdf0e10cSrcweir 	else
233cdf0e10cSrcweir 		mnValType = new sal_uInt8[nCount];
234cdf0e10cSrcweir 	memset( mnValType, 0, nCount * sizeof( sal_uInt8 ) );
235cdf0e10cSrcweir     mnNonValue = 0;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
DeleteIsString()238cdf0e10cSrcweir void ScMatrix::DeleteIsString()
239cdf0e10cSrcweir {
240cdf0e10cSrcweir 	if ( mnValType )
241cdf0e10cSrcweir 	{
242cdf0e10cSrcweir 		SCSIZE nCount = nColCount * nRowCount;
243cdf0e10cSrcweir 		for ( SCSIZE i = 0; i < nCount; i++ )
244cdf0e10cSrcweir 		{
245cdf0e10cSrcweir 			if (IsNonValueType( mnValType[i]))
246cdf0e10cSrcweir 				delete pMat[i].pS;
247cdf0e10cSrcweir 		}
248cdf0e10cSrcweir 		delete [] mnValType;
249cdf0e10cSrcweir 		mnValType = NULL;
250cdf0e10cSrcweir         mnNonValue = 0;
251cdf0e10cSrcweir 	}
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
PutDouble(double fVal,SCSIZE nC,SCSIZE nR)254cdf0e10cSrcweir void ScMatrix::PutDouble(double fVal, SCSIZE nC, SCSIZE nR)
255cdf0e10cSrcweir {
256cdf0e10cSrcweir 	if (ValidColRow( nC, nR))
257cdf0e10cSrcweir 		PutDouble( fVal, CalcOffset( nC, nR) );
258cdf0e10cSrcweir 	else
259cdf0e10cSrcweir 	{
260cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::PutDouble: dimension error");
261cdf0e10cSrcweir 	}
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
PutString(const String & rStr,SCSIZE nC,SCSIZE nR)264cdf0e10cSrcweir void ScMatrix::PutString(const String& rStr, SCSIZE nC, SCSIZE nR)
265cdf0e10cSrcweir {
266cdf0e10cSrcweir 	if (ValidColRow( nC, nR))
267cdf0e10cSrcweir 		PutString( rStr, CalcOffset( nC, nR) );
268cdf0e10cSrcweir 	else
269cdf0e10cSrcweir 	{
270cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::PutString: dimension error");
271cdf0e10cSrcweir 	}
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
PutString(const String & rStr,SCSIZE nIndex)274cdf0e10cSrcweir void ScMatrix::PutString(const String& rStr, SCSIZE nIndex)
275cdf0e10cSrcweir {
276cdf0e10cSrcweir 	if (mnValType == NULL)
277cdf0e10cSrcweir 		ResetIsString();
278cdf0e10cSrcweir 	if ( IsNonValueType( mnValType[nIndex]) && pMat[nIndex].pS )
279cdf0e10cSrcweir 		*(pMat[nIndex].pS) = rStr;
280cdf0e10cSrcweir 	else
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir 		pMat[nIndex].pS = new String(rStr);
283cdf0e10cSrcweir         mnNonValue++;
284cdf0e10cSrcweir     }
285cdf0e10cSrcweir 	mnValType[nIndex] = SC_MATVAL_STRING;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
PutStringEntry(const String * pStr,sal_uInt8 bFlag,SCSIZE nIndex)288cdf0e10cSrcweir void ScMatrix::PutStringEntry( const String* pStr, sal_uInt8 bFlag, SCSIZE nIndex )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir 	DBG_ASSERT( bFlag, "ScMatrix::PutStringEntry: bFlag == 0" );
291cdf0e10cSrcweir 	if (mnValType == NULL)
292cdf0e10cSrcweir 		ResetIsString();
293cdf0e10cSrcweir     // Make sure all bytes of the union are initialized to be able to access
294cdf0e10cSrcweir     // the value with if (IsValueOrEmpty()) GetDouble(). Backup pS first.
295cdf0e10cSrcweir     String* pS = pMat[nIndex].pS;
296cdf0e10cSrcweir     pMat[nIndex].fVal = 0.0;
297cdf0e10cSrcweir     // An EMPTY or EMPTYPATH entry must not have a string pointer therefor.
298cdf0e10cSrcweir     DBG_ASSERT( (((bFlag & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY) && !pStr) || sal_True,
299cdf0e10cSrcweir             "ScMatrix::PutStringEntry: pStr passed through EMPTY entry");
300cdf0e10cSrcweir 	if ( IsNonValueType( mnValType[nIndex]) && pS )
301cdf0e10cSrcweir 	{
302cdf0e10cSrcweir         if ((bFlag & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY)
303cdf0e10cSrcweir             delete pS, pS = NULL;
304cdf0e10cSrcweir 		if ( pStr )
305cdf0e10cSrcweir             *pS = *pStr;
306cdf0e10cSrcweir 		else if (pS)
307cdf0e10cSrcweir             pS->Erase();
308cdf0e10cSrcweir         pMat[nIndex].pS = pS;
309cdf0e10cSrcweir 	}
310cdf0e10cSrcweir 	else
311cdf0e10cSrcweir     {
312cdf0e10cSrcweir 		pMat[nIndex].pS = (pStr ? new String(*pStr) : NULL);
313cdf0e10cSrcweir         mnNonValue++;
314cdf0e10cSrcweir     }
315cdf0e10cSrcweir 	mnValType[nIndex] = bFlag;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
PutEmpty(SCSIZE nC,SCSIZE nR)318cdf0e10cSrcweir void ScMatrix::PutEmpty(SCSIZE nC, SCSIZE nR)
319cdf0e10cSrcweir {
320cdf0e10cSrcweir 	if (ValidColRow( nC, nR))
321cdf0e10cSrcweir 		PutEmpty( CalcOffset( nC, nR) );
322cdf0e10cSrcweir 	else
323cdf0e10cSrcweir 	{
324cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::PutEmpty: dimension error");
325cdf0e10cSrcweir 	}
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
PutEmpty(SCSIZE nIndex)328cdf0e10cSrcweir void ScMatrix::PutEmpty(SCSIZE nIndex)
329cdf0e10cSrcweir {
330cdf0e10cSrcweir 	if (mnValType == NULL)
331cdf0e10cSrcweir 		ResetIsString();
332cdf0e10cSrcweir 	if ( IsNonValueType( mnValType[nIndex]) && pMat[nIndex].pS )
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir 		delete pMat[nIndex].pS;
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir     else
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         mnNonValue++;
339cdf0e10cSrcweir     }
340cdf0e10cSrcweir 	mnValType[nIndex] = SC_MATVAL_EMPTY;
341cdf0e10cSrcweir 	pMat[nIndex].pS = NULL;
342cdf0e10cSrcweir 	pMat[nIndex].fVal = 0.0;
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
PutEmptyPath(SCSIZE nC,SCSIZE nR)345cdf0e10cSrcweir void ScMatrix::PutEmptyPath(SCSIZE nC, SCSIZE nR)
346cdf0e10cSrcweir {
347cdf0e10cSrcweir     if (ValidColRow( nC, nR))
348cdf0e10cSrcweir         PutEmptyPath( CalcOffset( nC, nR) );
349cdf0e10cSrcweir     else
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         DBG_ERRORFILE("ScMatrix::PutEmptyPath: dimension error");
352cdf0e10cSrcweir     }
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
PutEmptyPath(SCSIZE nIndex)355cdf0e10cSrcweir void ScMatrix::PutEmptyPath(SCSIZE nIndex)
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     if (mnValType == NULL)
358cdf0e10cSrcweir         ResetIsString();
359cdf0e10cSrcweir     if ( IsNonValueType( mnValType[nIndex]) && pMat[nIndex].pS )
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir         delete pMat[nIndex].pS;
362cdf0e10cSrcweir     }
363cdf0e10cSrcweir     else
364cdf0e10cSrcweir     {
365cdf0e10cSrcweir         mnNonValue++;
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir     mnValType[nIndex] = SC_MATVAL_EMPTYPATH;
368cdf0e10cSrcweir     pMat[nIndex].pS = NULL;
369cdf0e10cSrcweir     pMat[nIndex].fVal = 0.0;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
PutBoolean(bool bVal,SCSIZE nC,SCSIZE nR)372cdf0e10cSrcweir void ScMatrix::PutBoolean(bool bVal, SCSIZE nC, SCSIZE nR)
373cdf0e10cSrcweir {
374cdf0e10cSrcweir 	if (ValidColRow( nC, nR))
375cdf0e10cSrcweir 		PutBoolean( bVal, CalcOffset( nC, nR) );
376cdf0e10cSrcweir 	else
377cdf0e10cSrcweir 	{
378cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::PutBoolean: dimension error");
379cdf0e10cSrcweir 	}
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
PutBoolean(bool bVal,SCSIZE nIndex)382cdf0e10cSrcweir void ScMatrix::PutBoolean( bool bVal, SCSIZE nIndex)
383cdf0e10cSrcweir {
384cdf0e10cSrcweir     if (mnValType == NULL)
385cdf0e10cSrcweir         ResetIsString();
386cdf0e10cSrcweir     if ( IsNonValueType( mnValType[nIndex]) && pMat[nIndex].pS )
387cdf0e10cSrcweir     {
388cdf0e10cSrcweir         delete pMat[nIndex].pS;
389cdf0e10cSrcweir         mnNonValue--;
390cdf0e10cSrcweir     }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     mnValType[nIndex] = SC_MATVAL_BOOLEAN;
393cdf0e10cSrcweir     pMat[nIndex].pS = NULL;
394cdf0e10cSrcweir     pMat[nIndex].fVal = bVal ? 1. : 0.;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
GetError(SCSIZE nC,SCSIZE nR) const397cdf0e10cSrcweir sal_uInt16 ScMatrix::GetError( SCSIZE nC, SCSIZE nR) const
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     if (ValidColRowOrReplicated( nC, nR ))
400cdf0e10cSrcweir         return GetError( CalcOffset( nC, nR) );
401cdf0e10cSrcweir     else
402cdf0e10cSrcweir     {
403cdf0e10cSrcweir         DBG_ERRORFILE("ScMatrix::GetError: dimension error");
404cdf0e10cSrcweir 		return errNoValue;
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
GetDouble(SCSIZE nC,SCSIZE nR) const408cdf0e10cSrcweir double ScMatrix::GetDouble(SCSIZE nC, SCSIZE nR) const
409cdf0e10cSrcweir {
410cdf0e10cSrcweir     if (ValidColRowOrReplicated( nC, nR ))
411cdf0e10cSrcweir 		return GetDouble( CalcOffset( nC, nR) );
412cdf0e10cSrcweir 	else
413cdf0e10cSrcweir 	{
414cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::GetDouble: dimension error");
415cdf0e10cSrcweir 		return CreateDoubleError( errNoValue);
416cdf0e10cSrcweir 	}
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
GetString(SCSIZE nC,SCSIZE nR) const419cdf0e10cSrcweir const String& ScMatrix::GetString(SCSIZE nC, SCSIZE nR) const
420cdf0e10cSrcweir {
421cdf0e10cSrcweir     if (ValidColRowOrReplicated( nC, nR ))
422cdf0e10cSrcweir 	{
423cdf0e10cSrcweir 		SCSIZE nIndex = CalcOffset( nC, nR);
424cdf0e10cSrcweir 		if ( IsString( nIndex ) )
425cdf0e10cSrcweir 			return GetString( nIndex );
426cdf0e10cSrcweir 		else
427cdf0e10cSrcweir         {
428cdf0e10cSrcweir             SetErrorAtInterpreter( GetError( nIndex));
429cdf0e10cSrcweir 			DBG_ERRORFILE("ScMatrix::GetString: access error, no string");
430cdf0e10cSrcweir         }
431cdf0e10cSrcweir 	}
432cdf0e10cSrcweir 	else
433cdf0e10cSrcweir 	{
434cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::GetString: dimension error");
435cdf0e10cSrcweir 	}
436cdf0e10cSrcweir 	return ScGlobal::GetEmptyString();
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 
GetString(SvNumberFormatter & rFormatter,SCSIZE nIndex) const440cdf0e10cSrcweir String ScMatrix::GetString( SvNumberFormatter& rFormatter, SCSIZE nIndex) const
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     if (IsString( nIndex))
443cdf0e10cSrcweir     {
444cdf0e10cSrcweir         if (IsEmptyPath( nIndex))
445cdf0e10cSrcweir         {   // result of empty sal_False jump path
446cdf0e10cSrcweir             sal_uLong nKey = rFormatter.GetStandardFormat( NUMBERFORMAT_LOGICAL,
447cdf0e10cSrcweir                     ScGlobal::eLnge);
448cdf0e10cSrcweir             String aStr;
449cdf0e10cSrcweir             Color* pColor = NULL;
450cdf0e10cSrcweir             rFormatter.GetOutputString( 0.0, nKey, aStr, &pColor);
451cdf0e10cSrcweir             return aStr;
452cdf0e10cSrcweir         }
453cdf0e10cSrcweir         return GetString( nIndex );
454cdf0e10cSrcweir     }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir     sal_uInt16 nError = GetError( nIndex);
457cdf0e10cSrcweir     if (nError)
458cdf0e10cSrcweir     {
459cdf0e10cSrcweir         SetErrorAtInterpreter( nError);
460cdf0e10cSrcweir         return ScGlobal::GetErrorString( nError);
461cdf0e10cSrcweir     }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir     double fVal= GetDouble( nIndex);
464cdf0e10cSrcweir     sal_uLong nKey = rFormatter.GetStandardFormat( NUMBERFORMAT_NUMBER,
465cdf0e10cSrcweir             ScGlobal::eLnge);
466cdf0e10cSrcweir     String aStr;
467cdf0e10cSrcweir     rFormatter.GetInputLineString( fVal, nKey, aStr);
468cdf0e10cSrcweir     return aStr;
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 
GetString(SvNumberFormatter & rFormatter,SCSIZE nC,SCSIZE nR) const472cdf0e10cSrcweir String ScMatrix::GetString( SvNumberFormatter& rFormatter, SCSIZE nC, SCSIZE nR) const
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     if (ValidColRowOrReplicated( nC, nR ))
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir         SCSIZE nIndex = CalcOffset( nC, nR);
477cdf0e10cSrcweir         return GetString( rFormatter, nIndex);
478cdf0e10cSrcweir     }
479cdf0e10cSrcweir     else
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         DBG_ERRORFILE("ScMatrix::GetString: dimension error");
482cdf0e10cSrcweir     }
483cdf0e10cSrcweir     return String();
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 
Get(SCSIZE nC,SCSIZE nR,ScMatValType & nType) const487cdf0e10cSrcweir const ScMatrixValue* ScMatrix::Get(SCSIZE nC, SCSIZE nR, ScMatValType& nType) const
488cdf0e10cSrcweir {
489cdf0e10cSrcweir     if (ValidColRowOrReplicated( nC, nR ))
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 		SCSIZE nIndex = CalcOffset( nC, nR);
492cdf0e10cSrcweir 		if (mnValType)
493cdf0e10cSrcweir 			nType = mnValType[nIndex];
494cdf0e10cSrcweir 		else
495cdf0e10cSrcweir 			nType = SC_MATVAL_VALUE;
496cdf0e10cSrcweir 		return &pMat[nIndex];
497cdf0e10cSrcweir 	}
498cdf0e10cSrcweir 	else
499cdf0e10cSrcweir 	{
500cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::Get: dimension error");
501cdf0e10cSrcweir 	}
502cdf0e10cSrcweir     nType = SC_MATVAL_EMPTY;
503cdf0e10cSrcweir 	return NULL;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
MatCopy(ScMatrix & mRes) const506cdf0e10cSrcweir void ScMatrix::MatCopy(ScMatrix& mRes) const
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     if (nColCount > mRes.nColCount || nRowCount > mRes.nRowCount)
509cdf0e10cSrcweir 	{
510cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::MatCopy: dimension error");
511cdf0e10cSrcweir 	}
512cdf0e10cSrcweir     else if ( nColCount == mRes.nColCount && nRowCount == mRes.nRowCount )
513cdf0e10cSrcweir 	{
514cdf0e10cSrcweir 		if (mnValType)
515cdf0e10cSrcweir 		{
516cdf0e10cSrcweir             ScMatValType nType;
517cdf0e10cSrcweir 			mRes.ResetIsString();
518cdf0e10cSrcweir 			for (SCSIZE i = 0; i < nColCount; i++)
519cdf0e10cSrcweir 			{
520cdf0e10cSrcweir 				SCSIZE nStart = i * nRowCount;
521cdf0e10cSrcweir 				for (SCSIZE j = 0; j < nRowCount; j++)
522cdf0e10cSrcweir 				{
523cdf0e10cSrcweir 					if (IsNonValueType( (nType = mnValType[nStart+j])))
524cdf0e10cSrcweir 						mRes.PutStringEntry( pMat[nStart+j].pS, nType, nStart+j );
525cdf0e10cSrcweir 					else
526cdf0e10cSrcweir                     {
527cdf0e10cSrcweir                         mRes.pMat[nStart+j].fVal = pMat[nStart+j].fVal;
528cdf0e10cSrcweir                         mRes.mnValType[nStart+j] = nType;
529cdf0e10cSrcweir                     }
530cdf0e10cSrcweir 				}
531cdf0e10cSrcweir 			}
532cdf0e10cSrcweir 		}
533cdf0e10cSrcweir 		else
534cdf0e10cSrcweir 		{
535cdf0e10cSrcweir 			mRes.DeleteIsString();
536cdf0e10cSrcweir 			SCSIZE nCount = nColCount * nRowCount;
537cdf0e10cSrcweir 			for (SCSIZE i = 0; i < nCount; i++)
538cdf0e10cSrcweir 				mRes.pMat[i].fVal = pMat[i].fVal;
539cdf0e10cSrcweir 		}
540cdf0e10cSrcweir 	}
541cdf0e10cSrcweir     else
542cdf0e10cSrcweir     {
543cdf0e10cSrcweir         // Copy this matrix to upper left rectangle of result matrix.
544cdf0e10cSrcweir         if (mnValType)
545cdf0e10cSrcweir         {
546cdf0e10cSrcweir             ScMatValType nType;
547cdf0e10cSrcweir             mRes.ResetIsString();
548cdf0e10cSrcweir             for (SCSIZE i = 0; i < nColCount; i++)
549cdf0e10cSrcweir             {
550cdf0e10cSrcweir                 SCSIZE nStart = i * nRowCount;
551cdf0e10cSrcweir                 SCSIZE nResStart = i * mRes.nRowCount;
552cdf0e10cSrcweir                 for (SCSIZE j = 0; j < nRowCount; j++)
553cdf0e10cSrcweir                 {
554cdf0e10cSrcweir                     if (IsNonValueType( (nType = mnValType[nStart+j])))
555cdf0e10cSrcweir                         mRes.PutStringEntry( pMat[nStart+j].pS, nType, nResStart+j );
556cdf0e10cSrcweir                     else
557cdf0e10cSrcweir                     {
558cdf0e10cSrcweir                         mRes.pMat[nResStart+j].fVal = pMat[nStart+j].fVal;
559cdf0e10cSrcweir                         mRes.mnValType[nResStart+j] = nType;
560cdf0e10cSrcweir                     }
561cdf0e10cSrcweir                 }
562cdf0e10cSrcweir             }
563cdf0e10cSrcweir         }
564cdf0e10cSrcweir         else
565cdf0e10cSrcweir         {
566cdf0e10cSrcweir             mRes.DeleteIsString();
567cdf0e10cSrcweir             for (SCSIZE i = 0; i < nColCount; i++)
568cdf0e10cSrcweir             {
569cdf0e10cSrcweir                 SCSIZE nStart = i * nRowCount;
570cdf0e10cSrcweir                 SCSIZE nResStart = i * mRes.nRowCount;
571cdf0e10cSrcweir                 for (SCSIZE j = 0; j < nRowCount; j++)
572cdf0e10cSrcweir                     mRes.pMat[nResStart+j].fVal = pMat[nStart+j].fVal;
573cdf0e10cSrcweir             }
574cdf0e10cSrcweir         }
575cdf0e10cSrcweir     }
576cdf0e10cSrcweir }
577cdf0e10cSrcweir 
MatTrans(ScMatrix & mRes) const578cdf0e10cSrcweir void ScMatrix::MatTrans(ScMatrix& mRes) const
579cdf0e10cSrcweir {
580cdf0e10cSrcweir 	if (nColCount != mRes.nRowCount || nRowCount != mRes.nColCount)
581cdf0e10cSrcweir 	{
582cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::MatTrans: dimension error");
583cdf0e10cSrcweir 	}
584cdf0e10cSrcweir 	else
585cdf0e10cSrcweir 	{
586cdf0e10cSrcweir 		if (mnValType)
587cdf0e10cSrcweir 		{
588cdf0e10cSrcweir             ScMatValType nType;
589cdf0e10cSrcweir 			mRes.ResetIsString();
590cdf0e10cSrcweir 			for ( SCSIZE i = 0; i < nColCount; i++ )
591cdf0e10cSrcweir 			{
592cdf0e10cSrcweir 				SCSIZE nStart = i * nRowCount;
593cdf0e10cSrcweir 				for ( SCSIZE j = 0; j < nRowCount; j++ )
594cdf0e10cSrcweir 				{
595cdf0e10cSrcweir 					if (IsNonValueType( (nType = mnValType[nStart+j])))
596cdf0e10cSrcweir 						mRes.PutStringEntry( pMat[nStart+j].pS, nType, j*mRes.nRowCount+i );
597cdf0e10cSrcweir 					else
598cdf0e10cSrcweir                     {
599cdf0e10cSrcweir 						mRes.pMat[j*mRes.nRowCount+i].fVal = pMat[nStart+j].fVal;
600cdf0e10cSrcweir 						mRes.mnValType[j*mRes.nRowCount+i] = nType;
601cdf0e10cSrcweir                     }
602cdf0e10cSrcweir 				}
603cdf0e10cSrcweir 			}
604cdf0e10cSrcweir 		}
605cdf0e10cSrcweir 		else
606cdf0e10cSrcweir 		{
607cdf0e10cSrcweir 			mRes.DeleteIsString();
608cdf0e10cSrcweir 			for ( SCSIZE i = 0; i < nColCount; i++ )
609cdf0e10cSrcweir 			{
610cdf0e10cSrcweir 				SCSIZE nStart = i * nRowCount;
611cdf0e10cSrcweir 				for ( SCSIZE j = 0; j < nRowCount; j++ )
612cdf0e10cSrcweir 				{
613cdf0e10cSrcweir 					mRes.pMat[j*mRes.nRowCount+i].fVal = pMat[nStart+j].fVal;
614cdf0e10cSrcweir 				}
615cdf0e10cSrcweir 			}
616cdf0e10cSrcweir 		}
617cdf0e10cSrcweir 	}
618cdf0e10cSrcweir }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir //UNUSED2009-05 void ScMatrix::MatCopyUpperLeft(ScMatrix& mRes) const
621cdf0e10cSrcweir //UNUSED2009-05 {
622cdf0e10cSrcweir //UNUSED2009-05     if (nColCount < mRes.nColCount || nRowCount < mRes.nRowCount)
623cdf0e10cSrcweir //UNUSED2009-05     {
624cdf0e10cSrcweir //UNUSED2009-05         DBG_ERRORFILE("ScMatrix::MatCopyUpperLeft: dimension error");
625cdf0e10cSrcweir //UNUSED2009-05     }
626cdf0e10cSrcweir //UNUSED2009-05     else
627cdf0e10cSrcweir //UNUSED2009-05     {
628cdf0e10cSrcweir //UNUSED2009-05         if (mnValType)
629cdf0e10cSrcweir //UNUSED2009-05         {
630cdf0e10cSrcweir //UNUSED2009-05             ScMatValType nType;
631cdf0e10cSrcweir //UNUSED2009-05             mRes.ResetIsString();
632cdf0e10cSrcweir //UNUSED2009-05             for ( SCSIZE i = 0; i < mRes.nColCount; i++ )
633cdf0e10cSrcweir //UNUSED2009-05             {
634cdf0e10cSrcweir //UNUSED2009-05                 SCSIZE nStart = i * nRowCount;
635cdf0e10cSrcweir //UNUSED2009-05                 for ( SCSIZE j = 0; j < mRes.nRowCount; j++ )
636cdf0e10cSrcweir //UNUSED2009-05                 {
637cdf0e10cSrcweir //UNUSED2009-05                     if ( IsNonValueType( (nType = mnValType[nStart+j]) ))
638cdf0e10cSrcweir //UNUSED2009-05                         mRes.PutStringEntry( pMat[nStart+j].pS, nType,
639cdf0e10cSrcweir //UNUSED2009-05                             i*mRes.nRowCount+j );
640cdf0e10cSrcweir //UNUSED2009-05                     else
641cdf0e10cSrcweir //UNUSED2009-05                     {
642cdf0e10cSrcweir //UNUSED2009-05                         mRes.pMat[i*mRes.nRowCount+j].fVal = pMat[nStart+j].fVal;
643cdf0e10cSrcweir //UNUSED2009-05                         mRes.mnValType[i*mRes.nRowCount+j] = nType;
644cdf0e10cSrcweir //UNUSED2009-05                     }
645cdf0e10cSrcweir //UNUSED2009-05                 }
646cdf0e10cSrcweir //UNUSED2009-05             }
647cdf0e10cSrcweir //UNUSED2009-05         }
648cdf0e10cSrcweir //UNUSED2009-05         else
649cdf0e10cSrcweir //UNUSED2009-05         {
650cdf0e10cSrcweir //UNUSED2009-05             mRes.DeleteIsString();
651cdf0e10cSrcweir //UNUSED2009-05             for ( SCSIZE i = 0; i < mRes.nColCount; i++ )
652cdf0e10cSrcweir //UNUSED2009-05             {
653cdf0e10cSrcweir //UNUSED2009-05                 SCSIZE nStart = i * nRowCount;
654cdf0e10cSrcweir //UNUSED2009-05                 for ( SCSIZE j = 0; j < mRes.nRowCount; j++ )
655cdf0e10cSrcweir //UNUSED2009-05                 {
656cdf0e10cSrcweir //UNUSED2009-05                     mRes.pMat[i*mRes.nRowCount+j].fVal = pMat[nStart+j].fVal;
657cdf0e10cSrcweir //UNUSED2009-05                 }
658cdf0e10cSrcweir //UNUSED2009-05             }
659cdf0e10cSrcweir //UNUSED2009-05         }
660cdf0e10cSrcweir //UNUSED2009-05     }
661cdf0e10cSrcweir //UNUSED2009-05 }
662cdf0e10cSrcweir 
FillDouble(double fVal,SCSIZE nC1,SCSIZE nR1,SCSIZE nC2,SCSIZE nR2)663cdf0e10cSrcweir void ScMatrix::FillDouble( double fVal, SCSIZE nC1, SCSIZE nR1, SCSIZE nC2, SCSIZE nR2 )
664cdf0e10cSrcweir {
665cdf0e10cSrcweir 	if (ValidColRow( nC1, nR1) && ValidColRow( nC2, nR2))
666cdf0e10cSrcweir 	{
667cdf0e10cSrcweir         if ( nC1 == 0 && nR1 == 0 && nC2 == nColCount-1 && nR2 == nRowCount-1 )
668cdf0e10cSrcweir 		{
669cdf0e10cSrcweir 			SCSIZE nEnd = nColCount * nRowCount;
670cdf0e10cSrcweir 			for ( SCSIZE j=0; j<nEnd; j++ )
671cdf0e10cSrcweir 				pMat[j].fVal = fVal;
672cdf0e10cSrcweir 		}
673cdf0e10cSrcweir 		else
674cdf0e10cSrcweir 		{
675cdf0e10cSrcweir 			for ( SCSIZE i=nC1; i<=nC2; i++ )
676cdf0e10cSrcweir 			{
677cdf0e10cSrcweir                 SCSIZE nOff1 = i * nRowCount + nR1;
678cdf0e10cSrcweir                 SCSIZE nOff2 = nOff1 + nR2 - nR1;
679cdf0e10cSrcweir 				for ( SCSIZE j=nOff1; j<=nOff2; j++ )
680cdf0e10cSrcweir 					pMat[j].fVal = fVal;
681cdf0e10cSrcweir 			}
682cdf0e10cSrcweir 		}
683cdf0e10cSrcweir 	}
684cdf0e10cSrcweir 	else
685cdf0e10cSrcweir 	{
686cdf0e10cSrcweir 		DBG_ERRORFILE("ScMatrix::FillDouble: dimension error");
687cdf0e10cSrcweir 	}
688cdf0e10cSrcweir }
689cdf0e10cSrcweir 
CompareEqual()690cdf0e10cSrcweir void ScMatrix::CompareEqual()
691cdf0e10cSrcweir {
692cdf0e10cSrcweir 	SCSIZE n = nColCount * nRowCount;
693cdf0e10cSrcweir 	if ( mnValType )
694cdf0e10cSrcweir 	{
695cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
696cdf0e10cSrcweir 			if ( IsValueType( mnValType[j]) )		        // else: #WERT!
697cdf0e10cSrcweir                 if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
698cdf0e10cSrcweir                     pMat[j].fVal = (pMat[j].fVal == 0.0);
699cdf0e10cSrcweir 	}
700cdf0e10cSrcweir 	else
701cdf0e10cSrcweir 	{
702cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
703cdf0e10cSrcweir             if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
704cdf0e10cSrcweir                 pMat[j].fVal = (pMat[j].fVal == 0.0);
705cdf0e10cSrcweir 	}
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
CompareNotEqual()708cdf0e10cSrcweir void ScMatrix::CompareNotEqual()
709cdf0e10cSrcweir {
710cdf0e10cSrcweir 	SCSIZE n = nColCount * nRowCount;
711cdf0e10cSrcweir 	if ( mnValType )
712cdf0e10cSrcweir 	{
713cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
714cdf0e10cSrcweir 			if ( IsValueType( mnValType[j]) )		        // else: #WERT!
715cdf0e10cSrcweir                 if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
716cdf0e10cSrcweir                     pMat[j].fVal = (pMat[j].fVal != 0.0);
717cdf0e10cSrcweir 	}
718cdf0e10cSrcweir 	else
719cdf0e10cSrcweir 	{
720cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
721cdf0e10cSrcweir             if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
722cdf0e10cSrcweir                 pMat[j].fVal = (pMat[j].fVal != 0.0);
723cdf0e10cSrcweir 	}
724cdf0e10cSrcweir }
725cdf0e10cSrcweir 
CompareLess()726cdf0e10cSrcweir void ScMatrix::CompareLess()
727cdf0e10cSrcweir {
728cdf0e10cSrcweir 	SCSIZE n = nColCount * nRowCount;
729cdf0e10cSrcweir 	if ( mnValType )
730cdf0e10cSrcweir 	{
731cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
732cdf0e10cSrcweir 			if ( IsValueType( mnValType[j]) )		        // else: #WERT!
733cdf0e10cSrcweir                 if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
734cdf0e10cSrcweir                     pMat[j].fVal = (pMat[j].fVal < 0.0);
735cdf0e10cSrcweir 	}
736cdf0e10cSrcweir 	else
737cdf0e10cSrcweir 	{
738cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
739cdf0e10cSrcweir             if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
740cdf0e10cSrcweir                 pMat[j].fVal = (pMat[j].fVal < 0.0);
741cdf0e10cSrcweir 	}
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
CompareGreater()744cdf0e10cSrcweir void ScMatrix::CompareGreater()
745cdf0e10cSrcweir {
746cdf0e10cSrcweir 	SCSIZE n = nColCount * nRowCount;
747cdf0e10cSrcweir 	if ( mnValType )
748cdf0e10cSrcweir 	{
749cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
750cdf0e10cSrcweir 			if ( IsValueType( mnValType[j]) )		        // else: #WERT!
751cdf0e10cSrcweir                 if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
752cdf0e10cSrcweir                     pMat[j].fVal = (pMat[j].fVal > 0.0);
753cdf0e10cSrcweir 	}
754cdf0e10cSrcweir 	else
755cdf0e10cSrcweir 	{
756cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
757cdf0e10cSrcweir             if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
758cdf0e10cSrcweir                 pMat[j].fVal = (pMat[j].fVal > 0.0);
759cdf0e10cSrcweir 	}
760cdf0e10cSrcweir }
761cdf0e10cSrcweir 
CompareLessEqual()762cdf0e10cSrcweir void ScMatrix::CompareLessEqual()
763cdf0e10cSrcweir {
764cdf0e10cSrcweir 	SCSIZE n = nColCount * nRowCount;
765cdf0e10cSrcweir 	if ( mnValType )
766cdf0e10cSrcweir 	{
767cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
768cdf0e10cSrcweir 			if ( IsValueType( mnValType[j]) )		        // else: #WERT!
769cdf0e10cSrcweir                 if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
770cdf0e10cSrcweir                     pMat[j].fVal = (pMat[j].fVal <= 0.0);
771cdf0e10cSrcweir 	}
772cdf0e10cSrcweir 	else
773cdf0e10cSrcweir 	{
774cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
775cdf0e10cSrcweir             if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
776cdf0e10cSrcweir                 pMat[j].fVal = (pMat[j].fVal <= 0.0);
777cdf0e10cSrcweir 	}
778cdf0e10cSrcweir }
779cdf0e10cSrcweir 
CompareGreaterEqual()780cdf0e10cSrcweir void ScMatrix::CompareGreaterEqual()
781cdf0e10cSrcweir {
782cdf0e10cSrcweir 	SCSIZE n = nColCount * nRowCount;
783cdf0e10cSrcweir 	if ( mnValType )
784cdf0e10cSrcweir 	{
785cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
786cdf0e10cSrcweir 			if ( IsValueType( mnValType[j]) )		        // else: #WERT!
787cdf0e10cSrcweir                 if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
788cdf0e10cSrcweir                     pMat[j].fVal = (pMat[j].fVal >= 0.0);
789cdf0e10cSrcweir 	}
790cdf0e10cSrcweir 	else
791cdf0e10cSrcweir 	{
792cdf0e10cSrcweir 		for ( SCSIZE j=0; j<n; j++ )
793cdf0e10cSrcweir             if ( ::rtl::math::isFinite( pMat[j].fVal))  // else: DoubleError
794cdf0e10cSrcweir                 pMat[j].fVal = (pMat[j].fVal >= 0.0);
795cdf0e10cSrcweir 	}
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
And()798cdf0e10cSrcweir double ScMatrix::And()
799cdf0e10cSrcweir {
800cdf0e10cSrcweir 	SCSIZE n = nColCount * nRowCount;
801cdf0e10cSrcweir 	bool bAnd = true;
802cdf0e10cSrcweir 	if ( mnValType )
803cdf0e10cSrcweir 	{
804cdf0e10cSrcweir 		for ( SCSIZE j=0; bAnd && j<n; j++ )
805cdf0e10cSrcweir         {
806cdf0e10cSrcweir 			if ( !IsValueType( mnValType[j]) )
807cdf0e10cSrcweir             {   // assuming a CompareMat this is an error
808cdf0e10cSrcweir                 return CreateDoubleError( errIllegalArgument );
809cdf0e10cSrcweir             }
810cdf0e10cSrcweir             else if ( ::rtl::math::isFinite( pMat[j].fVal))
811cdf0e10cSrcweir 				bAnd = (pMat[j].fVal != 0.0);
812cdf0e10cSrcweir 			else
813cdf0e10cSrcweir                 return pMat[j].fVal;    // DoubleError
814cdf0e10cSrcweir         }
815cdf0e10cSrcweir 	}
816cdf0e10cSrcweir 	else
817cdf0e10cSrcweir 	{
818cdf0e10cSrcweir 		for ( SCSIZE j=0; bAnd && j<n; j++ )
819cdf0e10cSrcweir         {
820cdf0e10cSrcweir             if ( ::rtl::math::isFinite( pMat[j].fVal))
821cdf0e10cSrcweir                 bAnd = (pMat[j].fVal != 0.0);
822cdf0e10cSrcweir 			else
823cdf0e10cSrcweir                 return pMat[j].fVal;    // DoubleError
824cdf0e10cSrcweir         }
825cdf0e10cSrcweir 	}
826cdf0e10cSrcweir 	return bAnd;
827cdf0e10cSrcweir }
828cdf0e10cSrcweir 
Or()829cdf0e10cSrcweir double ScMatrix::Or()
830cdf0e10cSrcweir {
831cdf0e10cSrcweir 	SCSIZE n = nColCount * nRowCount;
832cdf0e10cSrcweir 	bool bOr = false;
833cdf0e10cSrcweir 	if ( mnValType )
834cdf0e10cSrcweir 	{
835cdf0e10cSrcweir 		for ( SCSIZE j=0; !bOr && j<n; j++ )
836cdf0e10cSrcweir 			if ( !IsValueType( mnValType[j]) )
837cdf0e10cSrcweir             {   // assuming a CompareMat this is an error
838cdf0e10cSrcweir                 return CreateDoubleError( errIllegalArgument );
839cdf0e10cSrcweir             }
840cdf0e10cSrcweir             else if ( ::rtl::math::isFinite( pMat[j].fVal))
841cdf0e10cSrcweir                 bOr = (pMat[j].fVal != 0.0);
842cdf0e10cSrcweir 			else
843cdf0e10cSrcweir                 return pMat[j].fVal;    // DoubleError
844cdf0e10cSrcweir 	}
845cdf0e10cSrcweir 	else
846cdf0e10cSrcweir 	{
847cdf0e10cSrcweir 		for ( SCSIZE j=0; !bOr && j<n; j++ )
848cdf0e10cSrcweir             if ( ::rtl::math::isFinite( pMat[j].fVal))
849cdf0e10cSrcweir                 bOr = (pMat[j].fVal != 0.0);
850cdf0e10cSrcweir 			else
851cdf0e10cSrcweir                 return pMat[j].fVal;    // DoubleError
852cdf0e10cSrcweir 	}
853cdf0e10cSrcweir 	return bOr;
854cdf0e10cSrcweir }
855*245212b4SAndrew Rist 
856*245212b4SAndrew Rist // @Author Marina Plakalovic
857*245212b4SAndrew Rist // Computes the logical XOR of elements
Xor()858*245212b4SAndrew Rist double ScMatrix::Xor()
859*245212b4SAndrew Rist {
860*245212b4SAndrew Rist     SCSIZE n = nColCount * nRowCount;
861*245212b4SAndrew Rist     bool bXor = false;
862*245212b4SAndrew Rist     if ( mnValType )
863*245212b4SAndrew Rist     {
864*245212b4SAndrew Rist         for ( SCSIZE j=0; j<n; j++ )
865*245212b4SAndrew Rist             if ( !IsValueType( mnValType[j]) )
866*245212b4SAndrew Rist             {   // assuming a CompareMat this is an error
867*245212b4SAndrew Rist                 return CreateDoubleError( errIllegalArgument );
868*245212b4SAndrew Rist             }
869*245212b4SAndrew Rist             else if ( ::rtl::math::isFinite( pMat[j].fVal))
870*245212b4SAndrew Rist                 bXor ^= (pMat[j].fVal != 0.0);
871*245212b4SAndrew Rist             else
872*245212b4SAndrew Rist                 return pMat[j].fVal;    // DoubleError
873*245212b4SAndrew Rist     }
874*245212b4SAndrew Rist     else
875*245212b4SAndrew Rist     {
876*245212b4SAndrew Rist         for ( SCSIZE j=0; j<n; j++ )
877*245212b4SAndrew Rist             if ( ::rtl::math::isFinite( pMat[j].fVal))
878*245212b4SAndrew Rist                 bXor ^= (pMat[j].fVal != 0.0);
879*245212b4SAndrew Rist             else
880*245212b4SAndrew Rist                 return pMat[j].fVal;    // DoubleError
881*245212b4SAndrew Rist     }
882*245212b4SAndrew Rist     return bXor;
883*245212b4SAndrew Rist }
884