diff options
author | Marina Plakalovic <makkica@openoffice.org> | 2012-12-15 03:41:47 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2012-12-15 21:42:40 +0100 |
commit | 07df025a730be05d087559b939858260df003b97 (patch) | |
tree | 59a1a739ba3e380b64671cc7035cdf1fe99bdeca | |
parent | ba950a50b0d0863e18ef781214eaaff9a8684790 (diff) |
calcishmakkica: #i114428# merge some XOR related code
Merged from Apache OO with adaptions, parts of
http://svn.apache.org/viewvc?rev=1381446&view=rev
Original Apache OO committer: Andrew Rist <arist@apache.org>
Original Author: Marina Plakalovic <makkica@openoffice.org>
Original Committer: Eike Rathke [er] <eike.rathke@oracle.com>
# HG changeset patch
# User Eike Rathke [er] <eike.rathke@oracle.com>
# Date 1284060031 -7200
# Node ID 528da6bfd0daed4355d745590d5ac3a319b08fb4
# Parent 237cb91dd986ff11eb100cc631206cda102e91f7
Change-Id: If456792f23429a80582a48b022d268e6179316a1
-rw-r--r-- | formula/source/core/resource/core_resource.src | 1 | ||||
-rw-r--r-- | sc/inc/scmatrix.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/tool/interpr1.cxx | 7 | ||||
-rw-r--r-- | sc/source/core/tool/scmatrix.cxx | 32 | ||||
-rw-r--r-- | sc/source/ui/src/scfuncs.src | 2 |
5 files changed, 40 insertions, 3 deletions
diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src index c552eb1f7062..b8fc21452458 100644 --- a/formula/source/core/resource/core_resource.src +++ b/formula/source/core/resource/core_resource.src @@ -385,6 +385,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH String SC_OPCODE_GREATER_EQUAL { Text = ">=" ; }; String SC_OPCODE_AND { Text = "AND" ; }; String SC_OPCODE_OR { Text = "OR" ; }; + String SC_OPCODE_XOR { Text = "XOR" ; }; String SC_OPCODE_INTERSECT { Text = "!" ; }; String SC_OPCODE_UNION { Text = "~" ; }; String SC_OPCODE_RANGE { Text = ":" ; }; diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index 84d3e5a6fe34..bf1f15f18b45 100644 --- a/sc/inc/scmatrix.hxx +++ b/sc/inc/scmatrix.hxx @@ -340,6 +340,7 @@ public: double And() const; // logical AND of all matrix values, or NAN double Or() const; // logical OR of all matrix values, or NAN + double Xor() const; // logical XOR of all matrix values, or NAN IterateResult Sum(bool bTextAsZero) const; IterateResult SumSquare(bool bTextAsZero) const; diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 43109e17dda7..d2bc4a44a2d7 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -1435,7 +1435,9 @@ void ScInterpreter::ScXor() bHaveValue = true; nRes ^= ( GetCellValue( aAdr, pCell ) != 0.0 ); } - // else: Xcl raises no error here + /* TODO: set error? Excel doesn't have XOR, but + * doesn't set an error in this case for AND and + * OR. */ } } break; @@ -1471,11 +1473,12 @@ void ScInterpreter::ScXor() if ( pMat ) { bHaveValue = true; - double fVal = pMat->Or(); + double fVal = pMat->Xor(); sal_uInt16 nErr = GetDoubleErrorValue( fVal ); if ( nErr ) { SetError( nErr ); + nRes = 0; } else nRes ^= ( fVal != 0.0 ); diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index cad0ab03c191..259d7477943b 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -376,6 +376,7 @@ public: void CompareGreaterEqual(); double And() const; double Or() const; + double Xor() const; ScMatrix::IterateResult Sum(bool bTextAsZero) const; ScMatrix::IterateResult SumSquare(bool bTextAsZero) const; @@ -950,6 +951,32 @@ double ScMatrixImpl::Or() const return EvalMatrix<OrEvaluator>(maMat); } +double ScMatrixImpl::Xor() const +{ + // All elements must be of value type. + // True if an odd number of elements have a non-zero value. + bool bXor = false; + size_t nRows = maMat.size().row, nCols = maMat.size().column; + for (size_t i = 0; i < nRows; ++i) + { + for (size_t j = 0; j < nCols; ++j) + { + mdds::mtm::element_t eType = maMat.get_type(i, j); + if (eType != mdds::mtm::element_numeric && eType != mdds::mtm::element_boolean) + // assuming a CompareMat this is an error + return CreateDoubleError(errIllegalArgument); + + double fVal = maMat.get_numeric(i, j); + if (!::rtl::math::isFinite(fVal)) + // DoubleError + return fVal; + + bXor ^= (fVal != 0.0); + } + } + return bXor; +} + namespace { struct SumOp @@ -1376,6 +1403,11 @@ double ScMatrix::Or() const return pImpl->Or(); } +double ScMatrix::Xor() const +{ + return pImpl->Xor(); +} + ScMatrix::IterateResult ScMatrix::Sum(bool bTextAsZero) const { return pImpl->Sum(bTextAsZero); diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src index 1080cc9f55d1..1b68b2e51815 100644 --- a/sc/source/ui/src/scfuncs.src +++ b/sc/source/ui/src/scfuncs.src @@ -2696,7 +2696,7 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS1 }; String 3 // Description of Parameter 1 { - Text [ en-US ] = "Logical value 1, logical value 2, ... are 1 to 30 conditions to be tested and which returns either TRUE or FALSE." ; + Text [ en-US ] = "Logical value 1, logical value 2, ... are 1 to 30 conditions to be tested and which return either TRUE or FALSE." ; }; }; // -=*# Resource for function UND #*=- |