Improvements to array arithmetic (MMULT)

Better setup of calculation function tests to ensure consistent environment
This commit is contained in:
MarkBaker 2015-01-23 23:44:32 +00:00
parent b3c5e98022
commit 71dba49fff
13 changed files with 56 additions and 32 deletions

View File

@ -316,14 +316,17 @@ class PHPExcel_Calculation_MathTrig {
} }
if ((is_numeric($number)) && (is_numeric($significance))) { if ((is_numeric($number)) && (is_numeric($significance))) {
if (($number == 0.0 ) || ($significance == 0.0)) { if ($significance == 0.0) {
return PHPExcel_Calculation_Functions::DIV0();
} elseif ($number == 0.0) {
return 0.0; return 0.0;
} elseif (self::SIGN($number) == self::SIGN($significance)) { } elseif (self::SIGN($number) == self::SIGN($significance)) {
return floor($number / $significance) * $significance; return floor($number / $significance) * $significance;
} else { } else {
return PHPExcel_Calculation_Functions::NaN(); return PHPExcel_Calculation_Functions::NaN();
} }
} } else
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function FLOOR() } // function FLOOR()
@ -606,27 +609,27 @@ class PHPExcel_Calculation_MathTrig {
if (!is_array($matrixData1)) { $matrixData1 = array(array($matrixData1)); } if (!is_array($matrixData1)) { $matrixData1 = array(array($matrixData1)); }
if (!is_array($matrixData2)) { $matrixData2 = array(array($matrixData2)); } if (!is_array($matrixData2)) { $matrixData2 = array(array($matrixData2)); }
$rowA = 0;
foreach($matrixData1 as $matrixRow) {
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
$columnA = 0;
foreach($matrixRow as $matrixCell) {
if ((is_string($matrixCell)) || ($matrixCell === null)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$matrixAData[$rowA][$columnA] = $matrixCell;
++$columnA;
}
++$rowA;
}
try { try {
$rowA = 0;
foreach($matrixData1 as $matrixRow) {
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
$columnA = 0;
foreach($matrixRow as $matrixCell) {
if ((!is_numeric($matrixCell)) || ($matrixCell === null)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$matrixAData[$rowA][$columnA] = $matrixCell;
++$columnA;
}
++$rowA;
}
$matrixA = new PHPExcel_Shared_JAMA_Matrix($matrixAData); $matrixA = new PHPExcel_Shared_JAMA_Matrix($matrixAData);
$rowB = 0; $rowB = 0;
foreach($matrixData2 as $matrixRow) { foreach($matrixData2 as $matrixRow) {
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
$columnB = 0; $columnB = 0;
foreach($matrixRow as $matrixCell) { foreach($matrixRow as $matrixCell) {
if ((is_string($matrixCell)) || ($matrixCell === null)) { if ((!is_numeric($matrixCell)) || ($matrixCell === null)) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
$matrixBData[$rowB][$columnB] = $matrixCell; $matrixBData[$rowB][$columnB] = $matrixCell;
@ -636,12 +639,13 @@ class PHPExcel_Calculation_MathTrig {
} }
$matrixB = new PHPExcel_Shared_JAMA_Matrix($matrixBData); $matrixB = new PHPExcel_Shared_JAMA_Matrix($matrixBData);
if (($rowA != $columnB) || ($rowB != $columnA)) { if ($columnA != $rowB) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
return $matrixA->times($matrixB)->getArray(); return $matrixA->times($matrixB)->getArray();
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
var_dump($ex->getMessage());
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
} // function MMULT() } // function MMULT()

View File

@ -1028,7 +1028,7 @@ class PHPExcel_Shared_JAMA_Matrix {
$LU = new PHPExcel_Shared_JAMA_LUDecomposition($this); $LU = new PHPExcel_Shared_JAMA_LUDecomposition($this);
return $LU->solve($B); return $LU->solve($B);
} else { } else {
$QR = new QRDecomposition($this); $QR = new PHPExcel_Shared_JAMA_QRDecomposition($this);
return $QR->solve($B); return $QR->solve($B);
} }
} // function solve() } // function solve()
@ -1054,6 +1054,4 @@ class PHPExcel_Shared_JAMA_Matrix {
$L = new PHPExcel_Shared_JAMA_LUDecomposition($this); $L = new PHPExcel_Shared_JAMA_LUDecomposition($this);
return $L->det(); return $L->det();
} // function det() } // function det()
} // class PHPExcel_Shared_JAMA_Matrix } // class PHPExcel_Shared_JAMA_Matrix

View File

@ -13,6 +13,8 @@ class DateTimeTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
/** /**

View File

@ -17,6 +17,8 @@ class EngineeringTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
/** /**

View File

@ -13,6 +13,8 @@ class FinancialTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
/** /**

View File

@ -13,6 +13,8 @@ class FunctionsTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
public function testDUMMY() public function testDUMMY()

View File

@ -13,6 +13,8 @@ class LogicalTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
public function testTRUE() public function testTRUE()

View File

@ -13,6 +13,8 @@ class LookupRefTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
/** /**

View File

@ -13,6 +13,8 @@ class MathTrigTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
/** /**

View File

@ -13,6 +13,8 @@ class TextDataTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
/** /**

View File

@ -11,6 +11,8 @@ class CalculationTest extends PHPUnit_Framework_TestCase
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
/** /**
@ -25,8 +27,6 @@ class CalculationTest extends PHPUnit_Framework_TestCase
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE); PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE);
$resultOpenOffice = \PHPExcel_Calculation::getInstance()->_calculateFormulaValue($formula); $resultOpenOffice = \PHPExcel_Calculation::getInstance()->_calculateFormulaValue($formula);
$this->assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible'); $this->assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible');
PHPExcel_Calculation_Functions::setCompatibilityMode(PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL);
} }
public function providerBinaryComparisonOperation() public function providerBinaryComparisonOperation()

View File

@ -1,4 +1,4 @@
{1|2|3;4|5|6;7|8|9}, {-4.50359962737050E+15|9.00719925474099E+15|-4.50359962737050E+15;9.00719925474100E+15|-1.80143985094820E+16|9.00719925474099E+15;-4.50359962737050E+15|9.00719925474099E+15|-4.50359962737050E+15} {1|2|3;4|5|6;7|8|9}, {-4.50359962737050E+15|9.00719925474099E+15|-4.50359962737050E+15;9.00719925474100E+15|-1.80143985094820E+16|9.00719925474099E+15;-4.50359962737050E+15|9.00719925474099E+15|-4.50359962737050E+15}
{10|20|30;40|50|60;70|80|90}, {7.03687441776639E+13|-1.40737488355328E+14|7.03687441776640E+13;-1.40737488355328E+14|2.81474976710656E+14|-1.40737488355328E+14;7.03687441776641E+13|-1.40737488355328E+14|7.03687441776640E+13} {10|20|30;40|50|60;70|80|90}, {7.03687441776639E+13|-1.40737488355328E+14|7.03687441776640E+13;-1.40737488355328E+14|2.81474976710656E+14|-1.40737488355328E+14;7.03687441776641E+13|-1.40737488355328E+14|7.03687441776640E+13}
{8|1|6;3|5|7;4|9|2}, {1.47222222222222E-01|-1.44444444444444E-01|6.38888888888889E-02;-6.11111111111111E-02|2.22222222222222E-02|1.05555555555556E-01;-1.94444444444444E-02|1.88888888888889E-01|-1.02777777777778E-01} {8|1|6;3|5|7;4|9|2}, {1.47222222222222E-01|-1.44444444444444E-01|6.38888888888889E-02;-6.11111111111111E-02|2.22222222222222E-02|1.05555555555556E-01;-1.94444444444444E-02|1.88888888888889E-01|-1.02777777777778E-01}
{4|-1;2|0}, {0|0.5;-1|2} {4|-1;2|0}, {0|0.5;-1|2}
@ -8,3 +8,8 @@
{0.2|1|-0.9;0.35|10.8|4;-3.15|5}, "#VALUE!" {0.2|1|-0.9;0.35|10.8|4;-3.15|5}, "#VALUE!"
{1|2;3|4}, {-2|1;1.5|-0.5} {1|2;3|4}, {-2|1;1.5|-0.5}
{1|2|1;3|4|2;1|1|2}, {-2|1|0;1.33333333333333|-0.33333333333333|-0.33333333333333;0.33333333333333|-0.33333333333333|0.66666666666667} {1|2|1;3|4|2;1|1|2}, {-2|1|0;1.33333333333333|-0.33333333333333|-0.33333333333333;0.33333333333333|-0.33333333333333|0.66666666666667}
{2|3;4|5}, {-2.5|1.5;2|-1}
{5|8;7|9}, {-0.818181818181818|0.727272727272727;0.636363636363636|-0.454545454545455}
{45|78;17|50}, {0.054112554112554|-0.084415584415584;-0.018398268398268|0.048701298701299}
{2|2;2|1}, {-0.5|1.0;1|-1}
{1|4|6;7|4|10;15|16|20}, {-0.2941176470588230|0.0588235294117647|0.0588235294117647;0.0367647058823529|-0.2573529411764710|0.1176470588235290;0.1911764705882350|0.1617647058823530|-0.0882352941176471}

View File

@ -1,11 +1,12 @@
{1|2;3|4}, {1|2;3|4}, {7|10;15|22} {1|2;3|4}, {1|2;3|4}, {7|10;15|22}
{1|2|3;4|5|6;7|8|9}, {1|2|3;4|5|6;7|8|9}, {30|36|42;66|81|96;102|126|150} {1|2|3;4|5|6;7|8|9}, {1|2|3;4|5|6;7|8|9}, {30|36|42;66|81|96;102|126|150}
{1|2;3|4}, 2, {2|4;6|8} {1|2;3|4}, 2, "#VALUE!" // Mismatched dimensions
{1|2;3|4}, {2}, {2|4;6|8} {1|2;3|4}, {2}, "#VALUE!" // Mismatched dimensions
2, {1|2;3|4}, {2|4;6|8} {1.2;2.4}, {3.6|4.5}, {14.43|14.43;14.43|14.43}
{2}, {1|2;3|4}, {2|4;6|8} 2, {1|2;3|4}, "#VALUE!" // Mismatched dimensions
{1|2;3|4}, {2|4}, {2|4;6|8} {2}, {1|2;3|4}, "#VALUE!" // Mismatched dimensions
{1|2;3|4}, {2;4}, {2|4;6|8} {1|2;3|4}, {2|4}, "#VALUE!"
{2|4}, {1|2;3|4}, {2|4;6|8} {1|2;3|4}, {2;4}, {{10};{22}}
{2;4}, {1|2;3|4}, {2|4;6|8} {2|4}, {1|2;3|4}, {14|20}
{1|2;3|4;5|6}, {1|2|3;4|5|6}, {1|2|3;4|5|6;7|8|9} {2;4}, {1|2;3|4}, "#VALUE!" // Mismatched dimensions
{1|2;3|4;5|6}, {1|2|3;4|5|6}, {9|12|15;19|26|33;29|40|51}