update dev300-m57
[ooovba.git] / sc / source / core / tool / scmatrix.cxx
blob35541bc1e87ff55b97b7542bf9bdf55b18f03534
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scmatrix.cxx,v $
10 * $Revision: 1.17.136.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <tools/debug.hxx>
36 #include "scmatrix.hxx"
37 #include "global.hxx"
38 #include "address.hxx"
39 #include "formula/errorcodes.hxx"
40 #include "interpre.hxx"
41 #include <svtools/zforlist.hxx>
42 #include <tools/stream.hxx>
43 #include <rtl/math.hxx>
45 #include <math.h>
47 //------------------------------------------------------------------------
49 void ScMatrix::CreateMatrix(SCSIZE nC, SCSIZE nR) // nur fuer ctor
51 pErrorInterpreter = NULL;
52 nColCount = nC;
53 nRowCount = nR;
54 SCSIZE nCount = nColCount * nRowCount;
55 if ( !nCount || nCount > GetElementsMax() )
57 DBG_ERRORFILE("ScMatrix::CreateMatrix: dimension error");
58 nColCount = nRowCount = 1;
59 pMat = new ScMatrixValue[1];
60 pMat[0].fVal = CreateDoubleError( errStackOverflow);
62 else
63 pMat = new ScMatrixValue[nCount];
64 mnValType = NULL;
65 mnNonValue = 0;
68 ScMatrix::~ScMatrix()
70 DeleteIsString();
71 delete [] pMat;
74 ScMatrix* ScMatrix::Clone() const
76 ScMatrix* pScMat = new ScMatrix( nColCount, nRowCount);
77 MatCopy(*pScMat);
78 pScMat->SetErrorInterpreter( pErrorInterpreter); // TODO: really?
79 return pScMat;
82 ScMatrix* ScMatrix::CloneAndExtend( SCSIZE nNewCols, SCSIZE nNewRows ) const
84 ScMatrix* pScMat = new ScMatrix( nNewCols, nNewRows);
85 MatCopy(*pScMat);
86 pScMat->SetErrorInterpreter( pErrorInterpreter);
87 return pScMat;
90 void ScMatrix::SetErrorAtInterpreter( USHORT nError ) const
92 if ( pErrorInterpreter )
93 pErrorInterpreter->SetError( nError);
97 // File format: USHORT columns, USHORT rows, (columns*rows) entries:
98 // BYTE type ( CELLTYPE_NONE, CELLTYPE_VALUE, CELLTYPE_STRING ); nothing, double or String
101 ScMatrix::ScMatrix(SvStream& /* rStream */)
102 : pErrorInterpreter( NULL)
103 , nRefCnt(0)
105 #if SC_ROWLIMIT_STREAM_ACCESS
106 #error address types changed!
107 USHORT nC;
108 USHORT nR;
110 rStream >> nC;
111 rStream >> nR;
113 CreateMatrix(nC, nR);
114 DBG_ASSERT( pMat, "pMat == NULL" );
116 String aMatStr;
117 double fVal;
118 rtl_TextEncoding eCharSet = rStream.GetStreamCharSet();
119 SCSIZE nCount = nColCount * nRowCount;
120 SCSIZE nReadCount = (SCSIZE) nC * nR;
121 for (SCSIZE i=0; i<nReadCount; i++)
123 BYTE nType;
124 rStream >> nType;
125 if ( nType == CELLTYPE_VALUE )
127 if ( i < nCount )
128 rStream >> pMat[i].fVal;
129 else
130 rStream >> fVal;
132 else
134 // For unknown types read and forget string (upwards compatibility)
136 if ( nType != CELLTYPE_NONE )
137 rStream.ReadByteString( aMatStr, eCharSet );
139 if ( i < nCount )
141 if (!mnValType)
142 ResetIsString(); // init string flags
143 mnValType[i] = ( nType == CELLTYPE_NONE ? SC_MATVAL_EMPTY : SC_MATVAL_STRING );
144 mnNonValue++;
146 if ( nType == CELLTYPE_STRING )
147 pMat[i].pS = new String(aMatStr);
148 else
149 pMat[i].pS = NULL;
153 #else
154 CreateMatrix(0,0);
155 #endif // SC_ROWLIMIT_STREAM_ACCESS
158 void ScMatrix::Store(SvStream& /* rStream */) const
160 #if SC_ROWLIMIT_STREAM_ACCESS
161 #error address types changed!
162 SCSIZE nCount = nColCount * nRowCount;
163 // Don't store matrix with more than USHORT max elements, old versions
164 // might get confused in loops for(USHORT i=0; i<nC*nR; i++)
165 if ( !pMat || nCount > ((USHORT)(~0)) )
167 DBG_ASSERT( pMat, "ScMatrix::Store: pMat == NULL" );
168 // We can't store a 0 dimension because old versions rely on some
169 // matrix being present, e.g. DDE link results, and old versions didn't
170 // create a matrix if dimension was 0. Store an error result.
171 rStream << (USHORT) 1;
172 rStream << (USHORT) 1;
173 rStream << (BYTE) CELLTYPE_VALUE;
174 double fVal;
175 ::rtl::math::setNan( &fVal );
176 rStream << fVal;
177 return;
180 rStream << (USHORT) nColCount;
181 #if SC_ROWLIMIT_MORE_THAN_32K
182 #error row32k
183 #endif
184 rStream << (USHORT) nRowCount;
186 String aMatStr;
187 rtl_TextEncoding eCharSet = rStream.GetStreamCharSet();
188 for (SCSIZE i=0; i<nCount; i++)
190 BYTE nType = CELLTYPE_VALUE;
191 if ( mnValType && IsNonValueType( mnValType[i]))
193 if ( pMat[i].pS )
194 aMatStr = *pMat[i].pS;
195 else
196 aMatStr.Erase();
198 if ( mnValType[i] == SC_MATVAL_STRING )
199 nType = CELLTYPE_STRING;
200 else
201 nType = CELLTYPE_NONE;
203 rStream << nType;
204 if ( nType == CELLTYPE_VALUE )
205 rStream << pMat[i].fVal;
206 else if ( nType == CELLTYPE_STRING )
207 rStream.WriteByteString( aMatStr, eCharSet );
209 #endif // SC_ROWLIMIT_STREAM_ACCESS
212 void ScMatrix::ResetIsString()
214 SCSIZE nCount = nColCount * nRowCount;
215 if (mnValType)
217 for (SCSIZE i = 0; i < nCount; i++)
219 if ( IsNonValueType( mnValType[i]))
220 delete pMat[i].pS;
223 else
224 mnValType = new BYTE[nCount];
225 memset( mnValType, 0, nCount * sizeof( BYTE ) );
226 mnNonValue = 0;
229 void ScMatrix::DeleteIsString()
231 if ( mnValType )
233 SCSIZE nCount = nColCount * nRowCount;
234 for ( SCSIZE i = 0; i < nCount; i++ )
236 if (IsNonValueType( mnValType[i]))
237 delete pMat[i].pS;
239 delete [] mnValType;
240 mnValType = NULL;
241 mnNonValue = 0;
245 void ScMatrix::PutDouble(double fVal, SCSIZE nC, SCSIZE nR)
247 if (ValidColRow( nC, nR))
248 PutDouble( fVal, CalcOffset( nC, nR) );
249 else
251 DBG_ERRORFILE("ScMatrix::PutDouble: dimension error");
255 void ScMatrix::PutString(const String& rStr, SCSIZE nC, SCSIZE nR)
257 if (ValidColRow( nC, nR))
258 PutString( rStr, CalcOffset( nC, nR) );
259 else
261 DBG_ERRORFILE("ScMatrix::PutString: dimension error");
265 void ScMatrix::PutString(const String& rStr, SCSIZE nIndex)
267 if (mnValType == NULL)
268 ResetIsString();
269 if ( IsNonValueType( mnValType[nIndex]) && pMat[nIndex].pS )
270 *(pMat[nIndex].pS) = rStr;
271 else
273 pMat[nIndex].pS = new String(rStr);
274 mnNonValue++;
276 mnValType[nIndex] = SC_MATVAL_STRING;
279 void ScMatrix::PutStringEntry( const String* pStr, BYTE bFlag, SCSIZE nIndex )
281 DBG_ASSERT( bFlag, "ScMatrix::PutStringEntry: bFlag == 0" );
282 if (mnValType == NULL)
283 ResetIsString();
284 // Make sure all bytes of the union are initialized to be able to access
285 // the value with if (IsValueOrEmpty()) GetDouble(). Backup pS first.
286 String* pS = pMat[nIndex].pS;
287 pMat[nIndex].fVal = 0.0;
288 // An EMPTY or EMPTYPATH entry must not have a string pointer therefor.
289 DBG_ASSERT( (((bFlag & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY) && !pStr) || TRUE,
290 "ScMatrix::PutStringEntry: pStr passed through EMPTY entry");
291 if ( IsNonValueType( mnValType[nIndex]) && pS )
293 if ((bFlag & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY)
294 delete pS, pS = NULL;
295 if ( pStr )
296 *pS = *pStr;
297 else if (pS)
298 pS->Erase();
299 pMat[nIndex].pS = pS;
301 else
303 pMat[nIndex].pS = (pStr ? new String(*pStr) : NULL);
304 mnNonValue++;
306 mnValType[nIndex] = bFlag;
309 void ScMatrix::PutEmpty(SCSIZE nC, SCSIZE nR)
311 if (ValidColRow( nC, nR))
312 PutEmpty( CalcOffset( nC, nR) );
313 else
315 DBG_ERRORFILE("ScMatrix::PutEmpty: dimension error");
319 void ScMatrix::PutEmpty(SCSIZE nIndex)
321 if (mnValType == NULL)
322 ResetIsString();
323 if ( IsNonValueType( mnValType[nIndex]) && pMat[nIndex].pS )
325 delete pMat[nIndex].pS;
327 else
329 mnNonValue++;
331 mnValType[nIndex] = SC_MATVAL_EMPTY;
332 pMat[nIndex].pS = NULL;
333 pMat[nIndex].fVal = 0.0;
336 void ScMatrix::PutEmptyPath(SCSIZE nC, SCSIZE nR)
338 if (ValidColRow( nC, nR))
339 PutEmptyPath( CalcOffset( nC, nR) );
340 else
342 DBG_ERRORFILE("ScMatrix::PutEmptyPath: dimension error");
346 void ScMatrix::PutEmptyPath(SCSIZE nIndex)
348 if (mnValType == NULL)
349 ResetIsString();
350 if ( IsNonValueType( mnValType[nIndex]) && pMat[nIndex].pS )
352 delete pMat[nIndex].pS;
354 else
356 mnNonValue++;
358 mnValType[nIndex] = SC_MATVAL_EMPTYPATH;
359 pMat[nIndex].pS = NULL;
360 pMat[nIndex].fVal = 0.0;
363 void ScMatrix::PutBoolean(bool bVal, SCSIZE nC, SCSIZE nR)
365 if (ValidColRow( nC, nR))
366 PutBoolean( bVal, CalcOffset( nC, nR) );
367 else
369 DBG_ERRORFILE("ScMatrix::PutBoolean: dimension error");
373 void ScMatrix::PutBoolean( bool bVal, SCSIZE nIndex)
375 if (mnValType == NULL)
376 ResetIsString();
377 if ( IsNonValueType( mnValType[nIndex]) && pMat[nIndex].pS )
379 delete pMat[nIndex].pS;
380 mnNonValue--;
383 mnValType[nIndex] = SC_MATVAL_BOOLEAN;
384 pMat[nIndex].pS = NULL;
385 pMat[nIndex].fVal = bVal ? 1. : 0.;
388 USHORT ScMatrix::GetError( SCSIZE nC, SCSIZE nR) const
390 if (ValidColRowOrReplicated( nC, nR ))
391 return GetError( CalcOffset( nC, nR) );
392 else
394 DBG_ERRORFILE("ScMatrix::GetError: dimension error");
395 return errNoValue;
399 double ScMatrix::GetDouble(SCSIZE nC, SCSIZE nR) const
401 if (ValidColRowOrReplicated( nC, nR ))
402 return GetDouble( CalcOffset( nC, nR) );
403 else
405 DBG_ERRORFILE("ScMatrix::GetDouble: dimension error");
406 return CreateDoubleError( errNoValue);
410 const String& ScMatrix::GetString(SCSIZE nC, SCSIZE nR) const
412 if (ValidColRowOrReplicated( nC, nR ))
414 SCSIZE nIndex = CalcOffset( nC, nR);
415 if ( IsString( nIndex ) )
416 return GetString( nIndex );
417 else
419 SetErrorAtInterpreter( GetError( nIndex));
420 DBG_ERRORFILE("ScMatrix::GetString: access error, no string");
423 else
425 DBG_ERRORFILE("ScMatrix::GetString: dimension error");
427 return ScGlobal::GetEmptyString();
431 String ScMatrix::GetString( SvNumberFormatter& rFormatter, SCSIZE nIndex) const
433 if (IsString( nIndex))
435 if (IsEmptyPath( nIndex))
436 { // result of empty FALSE jump path
437 ULONG nKey = rFormatter.GetStandardFormat( NUMBERFORMAT_LOGICAL,
438 ScGlobal::eLnge);
439 String aStr;
440 Color* pColor = NULL;
441 rFormatter.GetOutputString( 0.0, nKey, aStr, &pColor);
442 return aStr;
444 return GetString( nIndex );
447 USHORT nError = GetError( nIndex);
448 if (nError)
450 SetErrorAtInterpreter( nError);
451 return ScGlobal::GetErrorString( nError);
454 double fVal= GetDouble( nIndex);
455 ULONG nKey = rFormatter.GetStandardFormat( NUMBERFORMAT_NUMBER,
456 ScGlobal::eLnge);
457 String aStr;
458 rFormatter.GetInputLineString( fVal, nKey, aStr);
459 return aStr;
463 String ScMatrix::GetString( SvNumberFormatter& rFormatter, SCSIZE nC, SCSIZE nR) const
465 if (ValidColRowOrReplicated( nC, nR ))
467 SCSIZE nIndex = CalcOffset( nC, nR);
468 return GetString( rFormatter, nIndex);
470 else
472 DBG_ERRORFILE("ScMatrix::GetString: dimension error");
474 return String();
478 const ScMatrixValue* ScMatrix::Get(SCSIZE nC, SCSIZE nR, ScMatValType& nType) const
480 if (ValidColRowOrReplicated( nC, nR ))
482 SCSIZE nIndex = CalcOffset( nC, nR);
483 if (mnValType)
484 nType = mnValType[nIndex];
485 else
486 nType = SC_MATVAL_VALUE;
487 return &pMat[nIndex];
489 else
491 DBG_ERRORFILE("ScMatrix::Get: dimension error");
493 nType = SC_MATVAL_EMPTY;
494 return NULL;
497 void ScMatrix::MatCopy(ScMatrix& mRes) const
499 if (nColCount > mRes.nColCount || nRowCount > mRes.nRowCount)
501 DBG_ERRORFILE("ScMatrix::MatCopy: dimension error");
503 else if ( nColCount == mRes.nColCount && nRowCount == mRes.nRowCount )
505 if (mnValType)
507 ScMatValType nType;
508 mRes.ResetIsString();
509 for (SCSIZE i = 0; i < nColCount; i++)
511 SCSIZE nStart = i * nRowCount;
512 for (SCSIZE j = 0; j < nRowCount; j++)
514 if (IsNonValueType( (nType = mnValType[nStart+j])))
515 mRes.PutStringEntry( pMat[nStart+j].pS, nType, nStart+j );
516 else
518 mRes.pMat[nStart+j].fVal = pMat[nStart+j].fVal;
519 mRes.mnValType[nStart+j] = nType;
524 else
526 mRes.DeleteIsString();
527 SCSIZE nCount = nColCount * nRowCount;
528 for (SCSIZE i = 0; i < nCount; i++)
529 mRes.pMat[i].fVal = pMat[i].fVal;
532 else
534 // Copy this matrix to upper left rectangle of result matrix.
535 if (mnValType)
537 ScMatValType nType;
538 mRes.ResetIsString();
539 for (SCSIZE i = 0; i < nColCount; i++)
541 SCSIZE nStart = i * nRowCount;
542 SCSIZE nResStart = i * mRes.nRowCount;
543 for (SCSIZE j = 0; j < nRowCount; j++)
545 if (IsNonValueType( (nType = mnValType[nStart+j])))
546 mRes.PutStringEntry( pMat[nStart+j].pS, nType, nResStart+j );
547 else
549 mRes.pMat[nResStart+j].fVal = pMat[nStart+j].fVal;
550 mRes.mnValType[nResStart+j] = nType;
555 else
557 mRes.DeleteIsString();
558 for (SCSIZE i = 0; i < nColCount; i++)
560 SCSIZE nStart = i * nRowCount;
561 SCSIZE nResStart = i * mRes.nRowCount;
562 for (SCSIZE j = 0; j < nRowCount; j++)
563 mRes.pMat[nResStart+j].fVal = pMat[nStart+j].fVal;
569 void ScMatrix::MatTrans(ScMatrix& mRes) const
571 if (nColCount != mRes.nRowCount || nRowCount != mRes.nColCount)
573 DBG_ERRORFILE("ScMatrix::MatTrans: dimension error");
575 else
577 if (mnValType)
579 ScMatValType nType;
580 mRes.ResetIsString();
581 for ( SCSIZE i = 0; i < nColCount; i++ )
583 SCSIZE nStart = i * nRowCount;
584 for ( SCSIZE j = 0; j < nRowCount; j++ )
586 if (IsNonValueType( (nType = mnValType[nStart+j])))
587 mRes.PutStringEntry( pMat[nStart+j].pS, nType, j*mRes.nRowCount+i );
588 else
590 mRes.pMat[j*mRes.nRowCount+i].fVal = pMat[nStart+j].fVal;
591 mRes.mnValType[j*mRes.nRowCount+i] = nType;
596 else
598 mRes.DeleteIsString();
599 for ( SCSIZE i = 0; i < nColCount; i++ )
601 SCSIZE nStart = i * nRowCount;
602 for ( SCSIZE j = 0; j < nRowCount; j++ )
604 mRes.pMat[j*mRes.nRowCount+i].fVal = pMat[nStart+j].fVal;
611 //UNUSED2009-05 void ScMatrix::MatCopyUpperLeft(ScMatrix& mRes) const
612 //UNUSED2009-05 {
613 //UNUSED2009-05 if (nColCount < mRes.nColCount || nRowCount < mRes.nRowCount)
614 //UNUSED2009-05 {
615 //UNUSED2009-05 DBG_ERRORFILE("ScMatrix::MatCopyUpperLeft: dimension error");
616 //UNUSED2009-05 }
617 //UNUSED2009-05 else
618 //UNUSED2009-05 {
619 //UNUSED2009-05 if (mnValType)
620 //UNUSED2009-05 {
621 //UNUSED2009-05 ScMatValType nType;
622 //UNUSED2009-05 mRes.ResetIsString();
623 //UNUSED2009-05 for ( SCSIZE i = 0; i < mRes.nColCount; i++ )
624 //UNUSED2009-05 {
625 //UNUSED2009-05 SCSIZE nStart = i * nRowCount;
626 //UNUSED2009-05 for ( SCSIZE j = 0; j < mRes.nRowCount; j++ )
627 //UNUSED2009-05 {
628 //UNUSED2009-05 if ( IsNonValueType( (nType = mnValType[nStart+j]) ))
629 //UNUSED2009-05 mRes.PutStringEntry( pMat[nStart+j].pS, nType,
630 //UNUSED2009-05 i*mRes.nRowCount+j );
631 //UNUSED2009-05 else
632 //UNUSED2009-05 {
633 //UNUSED2009-05 mRes.pMat[i*mRes.nRowCount+j].fVal = pMat[nStart+j].fVal;
634 //UNUSED2009-05 mRes.mnValType[i*mRes.nRowCount+j] = nType;
635 //UNUSED2009-05 }
636 //UNUSED2009-05 }
637 //UNUSED2009-05 }
638 //UNUSED2009-05 }
639 //UNUSED2009-05 else
640 //UNUSED2009-05 {
641 //UNUSED2009-05 mRes.DeleteIsString();
642 //UNUSED2009-05 for ( SCSIZE i = 0; i < mRes.nColCount; i++ )
643 //UNUSED2009-05 {
644 //UNUSED2009-05 SCSIZE nStart = i * nRowCount;
645 //UNUSED2009-05 for ( SCSIZE j = 0; j < mRes.nRowCount; j++ )
646 //UNUSED2009-05 {
647 //UNUSED2009-05 mRes.pMat[i*mRes.nRowCount+j].fVal = pMat[nStart+j].fVal;
648 //UNUSED2009-05 }
649 //UNUSED2009-05 }
650 //UNUSED2009-05 }
651 //UNUSED2009-05 }
652 //UNUSED2009-05 }
654 void ScMatrix::FillDouble( double fVal, SCSIZE nC1, SCSIZE nR1, SCSIZE nC2, SCSIZE nR2 )
656 if (ValidColRow( nC1, nR1) && ValidColRow( nC2, nR2))
658 if ( nC1 == 0 && nR1 == 0 && nC2 == nColCount-1 && nR2 == nRowCount-1 )
660 SCSIZE nEnd = nColCount * nRowCount;
661 for ( SCSIZE j=0; j<nEnd; j++ )
662 pMat[j].fVal = fVal;
664 else
666 for ( SCSIZE i=nC1; i<=nC2; i++ )
668 SCSIZE nOff1 = i * nRowCount + nR1;
669 SCSIZE nOff2 = nOff1 + nR2 - nR1;
670 for ( SCSIZE j=nOff1; j<=nOff2; j++ )
671 pMat[j].fVal = fVal;
675 else
677 DBG_ERRORFILE("ScMatrix::FillDouble: dimension error");
681 void ScMatrix::CompareEqual()
683 SCSIZE n = nColCount * nRowCount;
684 if ( mnValType )
686 for ( SCSIZE j=0; j<n; j++ )
687 if ( IsValueType( mnValType[j]) ) // else: #WERT!
688 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
689 pMat[j].fVal = (pMat[j].fVal == 0.0);
691 else
693 for ( SCSIZE j=0; j<n; j++ )
694 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
695 pMat[j].fVal = (pMat[j].fVal == 0.0);
699 void ScMatrix::CompareNotEqual()
701 SCSIZE n = nColCount * nRowCount;
702 if ( mnValType )
704 for ( SCSIZE j=0; j<n; j++ )
705 if ( IsValueType( mnValType[j]) ) // else: #WERT!
706 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
707 pMat[j].fVal = (pMat[j].fVal != 0.0);
709 else
711 for ( SCSIZE j=0; j<n; j++ )
712 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
713 pMat[j].fVal = (pMat[j].fVal != 0.0);
717 void ScMatrix::CompareLess()
719 SCSIZE n = nColCount * nRowCount;
720 if ( mnValType )
722 for ( SCSIZE j=0; j<n; j++ )
723 if ( IsValueType( mnValType[j]) ) // else: #WERT!
724 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
725 pMat[j].fVal = (pMat[j].fVal < 0.0);
727 else
729 for ( SCSIZE j=0; j<n; j++ )
730 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
731 pMat[j].fVal = (pMat[j].fVal < 0.0);
735 void ScMatrix::CompareGreater()
737 SCSIZE n = nColCount * nRowCount;
738 if ( mnValType )
740 for ( SCSIZE j=0; j<n; j++ )
741 if ( IsValueType( mnValType[j]) ) // else: #WERT!
742 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
743 pMat[j].fVal = (pMat[j].fVal > 0.0);
745 else
747 for ( SCSIZE j=0; j<n; j++ )
748 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
749 pMat[j].fVal = (pMat[j].fVal > 0.0);
753 void ScMatrix::CompareLessEqual()
755 SCSIZE n = nColCount * nRowCount;
756 if ( mnValType )
758 for ( SCSIZE j=0; j<n; j++ )
759 if ( IsValueType( mnValType[j]) ) // else: #WERT!
760 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
761 pMat[j].fVal = (pMat[j].fVal <= 0.0);
763 else
765 for ( SCSIZE j=0; j<n; j++ )
766 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
767 pMat[j].fVal = (pMat[j].fVal <= 0.0);
771 void ScMatrix::CompareGreaterEqual()
773 SCSIZE n = nColCount * nRowCount;
774 if ( mnValType )
776 for ( SCSIZE j=0; j<n; j++ )
777 if ( IsValueType( mnValType[j]) ) // else: #WERT!
778 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
779 pMat[j].fVal = (pMat[j].fVal >= 0.0);
781 else
783 for ( SCSIZE j=0; j<n; j++ )
784 if ( ::rtl::math::isFinite( pMat[j].fVal)) // else: DoubleError
785 pMat[j].fVal = (pMat[j].fVal >= 0.0);
789 double ScMatrix::And()
791 SCSIZE n = nColCount * nRowCount;
792 bool bAnd = true;
793 if ( mnValType )
795 for ( SCSIZE j=0; bAnd && j<n; j++ )
797 if ( !IsValueType( mnValType[j]) )
798 { // assuming a CompareMat this is an error
799 return CreateDoubleError( errIllegalArgument );
801 else if ( ::rtl::math::isFinite( pMat[j].fVal))
802 bAnd = (pMat[j].fVal != 0.0);
803 else
804 return pMat[j].fVal; // DoubleError
807 else
809 for ( SCSIZE j=0; bAnd && j<n; j++ )
811 if ( ::rtl::math::isFinite( pMat[j].fVal))
812 bAnd = (pMat[j].fVal != 0.0);
813 else
814 return pMat[j].fVal; // DoubleError
817 return bAnd;
820 double ScMatrix::Or()
822 SCSIZE n = nColCount * nRowCount;
823 bool bOr = false;
824 if ( mnValType )
826 for ( SCSIZE j=0; !bOr && j<n; j++ )
827 if ( !IsValueType( mnValType[j]) )
828 { // assuming a CompareMat this is an error
829 return CreateDoubleError( errIllegalArgument );
831 else if ( ::rtl::math::isFinite( pMat[j].fVal))
832 bOr = (pMat[j].fVal != 0.0);
833 else
834 return pMat[j].fVal; // DoubleError
836 else
838 for ( SCSIZE j=0; !bOr && j<n; j++ )
839 if ( ::rtl::math::isFinite( pMat[j].fVal))
840 bOr = (pMat[j].fVal != 0.0);
841 else
842 return pMat[j].fVal; // DoubleError
844 return bOr;