summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--formula/source/core/resource/core_resource.src1
-rw-r--r--sc/inc/scmatrix.hxx1
-rw-r--r--sc/source/core/tool/interpr1.cxx7
-rw-r--r--sc/source/core/tool/scmatrix.cxx32
-rw-r--r--sc/source/ui/src/scfuncs.src2
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 #*=-