Resolves: tdf#154627 RANK() query value not in data must return error

For all RANK(), RANK.EQ(), RANK.AVG().
Also, use #N/A NotAvailable instead of #VALUE! NoValue.

This made it necessary to adapt sc/qa/unit/data/ods/functions.ods and
result check that had a totally senseless query value with arbitrary
results.

Change-Id: If835b5ed49caf16a813b4ea897e1d7dd1aa02954
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150067
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/qa/unit/data/contentCSV/statistical-functions.csv b/sc/qa/unit/data/contentCSV/statistical-functions.csv
index 2e3c45c..b9dbe2f 100644
--- a/sc/qa/unit/data/contentCSV/statistical-functions.csv
+++ b/sc/qa/unit/data/contentCSV/statistical-functions.csv
@@ -117,9 +117,9 @@
1
-0.1225598712
-0.1363480926
2
9
2
10
11
10
0.5,0.1
121,216
120
diff --git a/sc/qa/unit/data/ods/functions.ods b/sc/qa/unit/data/ods/functions.ods
index 04c6e6e..1ef3a72 100644
--- a/sc/qa/unit/data/ods/functions.ods
+++ b/sc/qa/unit/data/ods/functions.ods
Binary files differ
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index 0153ee6..88b32b4 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -4254,7 +4254,7 @@ void ScInterpreter::ScRank( bool bAverage )
    else
    {
        if ( fVal < aSortArray[ 0 ] || fVal > aSortArray[ nSize - 1 ] )
            PushNoValue();
            PushError( FormulaError::NotAvailable);
        else
        {
            double fLastPos = 0;
@@ -4279,7 +4279,11 @@ void ScInterpreter::ScRank( bool bAverage )
            }
            if ( !bFinished )
                fLastPos = i;
            if ( !bAverage )
            if (fFirstPos <= 0)
            {
                PushError( FormulaError::NotAvailable);
            }
            else if ( !bAverage )
            {
                if ( bAscending )
                    PushDouble( fFirstPos );