Improvements to array arithmetic (MMULT)
Better setup of calculation function tests to ensure consistent environment
This commit is contained in:
parent
b3c5e98022
commit
71dba49fff
|
@ -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,12 +609,13 @@ 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)); }
|
||||||
|
|
||||||
|
try {
|
||||||
$rowA = 0;
|
$rowA = 0;
|
||||||
foreach($matrixData1 as $matrixRow) {
|
foreach($matrixData1 as $matrixRow) {
|
||||||
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
|
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); }
|
||||||
$columnA = 0;
|
$columnA = 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();
|
||||||
}
|
}
|
||||||
$matrixAData[$rowA][$columnA] = $matrixCell;
|
$matrixAData[$rowA][$columnA] = $matrixCell;
|
||||||
|
@ -619,14 +623,13 @@ class PHPExcel_Calculation_MathTrig {
|
||||||
}
|
}
|
||||||
++$rowA;
|
++$rowA;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
$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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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}
|
|
@ -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}
|
||||||
|
|
Loading…
Reference in New Issue