Kaydet (Commit) 07df025a authored tarafından Marina Plakalovic's avatar Marina Plakalovic Kaydeden (comit) Eike Rathke

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
üst ba950a50
...@@ -385,6 +385,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH ...@@ -385,6 +385,7 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH
String SC_OPCODE_GREATER_EQUAL { Text = ">=" ; }; String SC_OPCODE_GREATER_EQUAL { Text = ">=" ; };
String SC_OPCODE_AND { Text = "AND" ; }; String SC_OPCODE_AND { Text = "AND" ; };
String SC_OPCODE_OR { Text = "OR" ; }; String SC_OPCODE_OR { Text = "OR" ; };
String SC_OPCODE_XOR { Text = "XOR" ; };
String SC_OPCODE_INTERSECT { Text = "!" ; }; String SC_OPCODE_INTERSECT { Text = "!" ; };
String SC_OPCODE_UNION { Text = "~" ; }; String SC_OPCODE_UNION { Text = "~" ; };
String SC_OPCODE_RANGE { Text = ":" ; }; String SC_OPCODE_RANGE { Text = ":" ; };
......
...@@ -340,6 +340,7 @@ public: ...@@ -340,6 +340,7 @@ public:
double And() const; // logical AND of all matrix values, or NAN double And() const; // logical AND of all matrix values, or NAN
double Or() const; // logical OR 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 Sum(bool bTextAsZero) const;
IterateResult SumSquare(bool bTextAsZero) const; IterateResult SumSquare(bool bTextAsZero) const;
......
...@@ -1435,7 +1435,9 @@ void ScInterpreter::ScXor() ...@@ -1435,7 +1435,9 @@ void ScInterpreter::ScXor()
bHaveValue = true; bHaveValue = true;
nRes ^= ( GetCellValue( aAdr, pCell ) != 0.0 ); 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; break;
...@@ -1471,11 +1473,12 @@ void ScInterpreter::ScXor() ...@@ -1471,11 +1473,12 @@ void ScInterpreter::ScXor()
if ( pMat ) if ( pMat )
{ {
bHaveValue = true; bHaveValue = true;
double fVal = pMat->Or(); double fVal = pMat->Xor();
sal_uInt16 nErr = GetDoubleErrorValue( fVal ); sal_uInt16 nErr = GetDoubleErrorValue( fVal );
if ( nErr ) if ( nErr )
{ {
SetError( nErr ); SetError( nErr );
nRes = 0;
} }
else else
nRes ^= ( fVal != 0.0 ); nRes ^= ( fVal != 0.0 );
......
...@@ -376,6 +376,7 @@ public: ...@@ -376,6 +376,7 @@ public:
void CompareGreaterEqual(); void CompareGreaterEqual();
double And() const; double And() const;
double Or() const; double Or() const;
double Xor() const;
ScMatrix::IterateResult Sum(bool bTextAsZero) const; ScMatrix::IterateResult Sum(bool bTextAsZero) const;
ScMatrix::IterateResult SumSquare(bool bTextAsZero) const; ScMatrix::IterateResult SumSquare(bool bTextAsZero) const;
...@@ -950,6 +951,32 @@ double ScMatrixImpl::Or() const ...@@ -950,6 +951,32 @@ double ScMatrixImpl::Or() const
return EvalMatrix<OrEvaluator>(maMat); 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 { namespace {
struct SumOp struct SumOp
...@@ -1376,6 +1403,11 @@ double ScMatrix::Or() const ...@@ -1376,6 +1403,11 @@ double ScMatrix::Or() const
return pImpl->Or(); return pImpl->Or();
} }
double ScMatrix::Xor() const
{
return pImpl->Xor();
}
ScMatrix::IterateResult ScMatrix::Sum(bool bTextAsZero) const ScMatrix::IterateResult ScMatrix::Sum(bool bTextAsZero) const
{ {
return pImpl->Sum(bTextAsZero); return pImpl->Sum(bTextAsZero);
......
...@@ -2696,7 +2696,7 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS1 ...@@ -2696,7 +2696,7 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS1
}; };
String 3 // Description of Parameter 1 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 #*=- // -=*# Resource for function UND #*=-
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment