Merge branch 'master' into fix_excel_overwrite
This commit is contained in:
commit
93d858a064
|
|
@ -228,7 +228,7 @@ class Calculation
|
||||||
private static $phpSpreadsheetFunctions = [
|
private static $phpSpreadsheetFunctions = [
|
||||||
'ABS' => [
|
'ABS' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'builtinABS'],
|
'functionCall' => [MathTrig\Absolute::class, 'evaluate'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'ACCRINT' => [
|
'ACCRINT' => [
|
||||||
|
|
@ -835,7 +835,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'DEGREES' => [
|
'DEGREES' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'builtinDEGREES'],
|
'functionCall' => [MathTrig\Degrees::class, 'evaluate'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'DELTA' => [
|
'DELTA' => [
|
||||||
|
|
@ -975,7 +975,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'EXP' => [
|
'EXP' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'builtinEXP'],
|
'functionCall' => [MathTrig\Exp::class, 'evaluate'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'EXPONDIST' => [
|
'EXPONDIST' => [
|
||||||
|
|
@ -2038,7 +2038,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'RADIANS' => [
|
'RADIANS' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'builtinRADIANS'],
|
'functionCall' => [MathTrig\Radians::class, 'evaluate'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'RAND' => [
|
'RAND' => [
|
||||||
|
|
@ -2185,7 +2185,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'SERIESSUM' => [
|
'SERIESSUM' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'SERIESSUM'],
|
'functionCall' => [MathTrig\SeriesSum::class, 'funcSeriesSum'],
|
||||||
'argumentCount' => '4',
|
'argumentCount' => '4',
|
||||||
],
|
],
|
||||||
'SHEET' => [
|
'SHEET' => [
|
||||||
|
|
@ -2205,7 +2205,7 @@ class Calculation
|
||||||
],
|
],
|
||||||
'SIN' => [
|
'SIN' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'builtinSIN'],
|
'functionCall' => [MathTrig\Sin::class, 'funcSin'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'SINH' => [
|
'SINH' => [
|
||||||
|
|
@ -2250,12 +2250,12 @@ class Calculation
|
||||||
],
|
],
|
||||||
'SQRT' => [
|
'SQRT' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'builtinSQRT'],
|
'functionCall' => [MathTrig\Sqrt::class, 'evaluate'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'SQRTPI' => [
|
'SQRTPI' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'SQRTPI'],
|
'functionCall' => [MathTrig\SqrtPi::class, 'evaluate'],
|
||||||
'argumentCount' => '1',
|
'argumentCount' => '1',
|
||||||
],
|
],
|
||||||
'STANDARDIZE' => [
|
'STANDARDIZE' => [
|
||||||
|
|
@ -2331,22 +2331,22 @@ class Calculation
|
||||||
],
|
],
|
||||||
'SUMSQ' => [
|
'SUMSQ' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'SUMSQ'],
|
'functionCall' => [MathTrig\SumSquares::class, 'sumSquare'],
|
||||||
'argumentCount' => '1+',
|
'argumentCount' => '1+',
|
||||||
],
|
],
|
||||||
'SUMX2MY2' => [
|
'SUMX2MY2' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'SUMX2MY2'],
|
'functionCall' => [MathTrig\SumSquares::class, 'sumXSquaredMinusYSquared'],
|
||||||
'argumentCount' => '2',
|
'argumentCount' => '2',
|
||||||
],
|
],
|
||||||
'SUMX2PY2' => [
|
'SUMX2PY2' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'SUMX2PY2'],
|
'functionCall' => [MathTrig\SumSquares::class, 'sumXSquaredPlusYSquared'],
|
||||||
'argumentCount' => '2',
|
'argumentCount' => '2',
|
||||||
],
|
],
|
||||||
'SUMXMY2' => [
|
'SUMXMY2' => [
|
||||||
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
'category' => Category::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => [MathTrig::class, 'SUMXMY2'],
|
'functionCall' => [MathTrig\SumSquares::class, 'sumXMinusYSquared'],
|
||||||
'argumentCount' => '2',
|
'argumentCount' => '2',
|
||||||
],
|
],
|
||||||
'SWITCH' => [
|
'SWITCH' => [
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class DateTime
|
||||||
/**
|
/**
|
||||||
* getDateValue.
|
* getDateValue.
|
||||||
*
|
*
|
||||||
* @Deprecated 2.0.0 Use the method getDateValueNoThrow in the DateTimeExcel\Helpers class instead
|
* @Deprecated 2.0.0 Use the method getDateValue in the DateTimeExcel\Helpers class instead
|
||||||
*
|
*
|
||||||
* @param mixed $dateValue
|
* @param mixed $dateValue
|
||||||
*
|
*
|
||||||
|
|
@ -31,7 +31,11 @@ class DateTime
|
||||||
*/
|
*/
|
||||||
public static function getDateValue($dateValue)
|
public static function getDateValue($dateValue)
|
||||||
{
|
{
|
||||||
return DateTimeExcel\Helpers::getDateValueNoThrow($dateValue);
|
try {
|
||||||
|
return DateTimeExcel\Helpers::getDateValue($dateValue);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -56,22 +56,6 @@ class Helpers
|
||||||
return (float) $dateValue;
|
return (float) $dateValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* getDateValueNoThrow.
|
|
||||||
*
|
|
||||||
* @param mixed $dateValue
|
|
||||||
*
|
|
||||||
* @return mixed Excel date/time serial value, or string if error
|
|
||||||
*/
|
|
||||||
public static function getDateValueNoThrow($dateValue)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return self::getDateValue($dateValue);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getTimeValue.
|
* getTimeValue.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -640,23 +640,15 @@ class MathTrig
|
||||||
*
|
*
|
||||||
* Returns the square root of (number * pi).
|
* Returns the square root of (number * pi).
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the evaluate method in the MathTrig\SqrtPi class instead
|
||||||
|
*
|
||||||
* @param float $number Number
|
* @param float $number Number
|
||||||
*
|
*
|
||||||
* @return float|string Square Root of Number * Pi, or a string containing an error
|
* @return float|string Square Root of Number * Pi, or a string containing an error
|
||||||
*/
|
*/
|
||||||
public static function SQRTPI($number)
|
public static function SQRTPI($number)
|
||||||
{
|
{
|
||||||
$number = Functions::flattenSingleValue($number);
|
return MathTrig\SqrtPi::evaluate($number);
|
||||||
|
|
||||||
if (is_numeric($number)) {
|
|
||||||
if ($number < 0) {
|
|
||||||
return Functions::NAN();
|
|
||||||
}
|
|
||||||
|
|
||||||
return sqrt($number * M_PI);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Functions::VALUE();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -769,107 +761,63 @@ class MathTrig
|
||||||
*
|
*
|
||||||
* SUMSQ returns the sum of the squares of the arguments
|
* SUMSQ returns the sum of the squares of the arguments
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the sumSquare method in the MathTrig\SumSquares class instead
|
||||||
|
*
|
||||||
* Excel Function:
|
* Excel Function:
|
||||||
* SUMSQ(value1[,value2[, ...]])
|
* SUMSQ(value1[,value2[, ...]])
|
||||||
*
|
*
|
||||||
* @param mixed ...$args Data values
|
* @param mixed ...$args Data values
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float|string
|
||||||
*/
|
*/
|
||||||
public static function SUMSQ(...$args)
|
public static function SUMSQ(...$args)
|
||||||
{
|
{
|
||||||
$returnValue = 0;
|
return MathTrig\SumSquares::sumSquare(...$args);
|
||||||
|
|
||||||
// Loop through arguments
|
|
||||||
foreach (Functions::flattenArray($args) as $arg) {
|
|
||||||
// Is it a numeric value?
|
|
||||||
if ((is_numeric($arg)) && (!is_string($arg))) {
|
|
||||||
$returnValue += ($arg * $arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $returnValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SUMX2MY2.
|
* SUMX2MY2.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the sumXSquaredMinusYSquared method in the MathTrig\SumSquares class instead
|
||||||
|
*
|
||||||
* @param mixed[] $matrixData1 Matrix #1
|
* @param mixed[] $matrixData1 Matrix #1
|
||||||
* @param mixed[] $matrixData2 Matrix #2
|
* @param mixed[] $matrixData2 Matrix #2
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float|string
|
||||||
*/
|
*/
|
||||||
public static function SUMX2MY2($matrixData1, $matrixData2)
|
public static function SUMX2MY2($matrixData1, $matrixData2)
|
||||||
{
|
{
|
||||||
$array1 = Functions::flattenArray($matrixData1);
|
return MathTrig\SumSquares::sumXSquaredMinusYSquared($matrixData1, $matrixData2);
|
||||||
$array2 = Functions::flattenArray($matrixData2);
|
|
||||||
$count = min(count($array1), count($array2));
|
|
||||||
|
|
||||||
$result = 0;
|
|
||||||
for ($i = 0; $i < $count; ++$i) {
|
|
||||||
if (
|
|
||||||
((is_numeric($array1[$i])) && (!is_string($array1[$i]))) &&
|
|
||||||
((is_numeric($array2[$i])) && (!is_string($array2[$i])))
|
|
||||||
) {
|
|
||||||
$result += ($array1[$i] * $array1[$i]) - ($array2[$i] * $array2[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SUMX2PY2.
|
* SUMX2PY2.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the sumXSquaredPlusYSquared method in the MathTrig\SumSquares class instead
|
||||||
|
*
|
||||||
* @param mixed[] $matrixData1 Matrix #1
|
* @param mixed[] $matrixData1 Matrix #1
|
||||||
* @param mixed[] $matrixData2 Matrix #2
|
* @param mixed[] $matrixData2 Matrix #2
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float|string
|
||||||
*/
|
*/
|
||||||
public static function SUMX2PY2($matrixData1, $matrixData2)
|
public static function SUMX2PY2($matrixData1, $matrixData2)
|
||||||
{
|
{
|
||||||
$array1 = Functions::flattenArray($matrixData1);
|
return MathTrig\SumSquares::sumXSquaredPlusYSquared($matrixData1, $matrixData2);
|
||||||
$array2 = Functions::flattenArray($matrixData2);
|
|
||||||
$count = min(count($array1), count($array2));
|
|
||||||
|
|
||||||
$result = 0;
|
|
||||||
for ($i = 0; $i < $count; ++$i) {
|
|
||||||
if (
|
|
||||||
((is_numeric($array1[$i])) && (!is_string($array1[$i]))) &&
|
|
||||||
((is_numeric($array2[$i])) && (!is_string($array2[$i])))
|
|
||||||
) {
|
|
||||||
$result += ($array1[$i] * $array1[$i]) + ($array2[$i] * $array2[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SUMXMY2.
|
* SUMXMY2.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the sumXMinusYSquared method in the MathTrig\SumSquares class instead
|
||||||
|
*
|
||||||
* @param mixed[] $matrixData1 Matrix #1
|
* @param mixed[] $matrixData1 Matrix #1
|
||||||
* @param mixed[] $matrixData2 Matrix #2
|
* @param mixed[] $matrixData2 Matrix #2
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float|string
|
||||||
*/
|
*/
|
||||||
public static function SUMXMY2($matrixData1, $matrixData2)
|
public static function SUMXMY2($matrixData1, $matrixData2)
|
||||||
{
|
{
|
||||||
$array1 = Functions::flattenArray($matrixData1);
|
return MathTrig\SumSquares::sumXMinusYSquared($matrixData1, $matrixData2);
|
||||||
$array2 = Functions::flattenArray($matrixData2);
|
|
||||||
$count = min(count($array1), count($array2));
|
|
||||||
|
|
||||||
$result = 0;
|
|
||||||
for ($i = 0; $i < $count; ++$i) {
|
|
||||||
if (
|
|
||||||
((is_numeric($array1[$i])) && (!is_string($array1[$i]))) &&
|
|
||||||
((is_numeric($array2[$i])) && (!is_string($array2[$i])))
|
|
||||||
) {
|
|
||||||
$result += ($array1[$i] - $array2[$i]) * ($array1[$i] - $array2[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1057,19 +1005,15 @@ class MathTrig
|
||||||
*
|
*
|
||||||
* Returns the result of builtin function abs after validating args.
|
* Returns the result of builtin function abs after validating args.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the evaluate method in the MathTrig\Absolute class instead
|
||||||
|
*
|
||||||
* @param mixed $number Should be numeric
|
* @param mixed $number Should be numeric
|
||||||
*
|
*
|
||||||
* @return float|int|string Rounded number
|
* @return float|int|string Rounded number
|
||||||
*/
|
*/
|
||||||
public static function builtinABS($number)
|
public static function builtinABS($number)
|
||||||
{
|
{
|
||||||
$number = Functions::flattenSingleValue($number);
|
return MathTrig\Absolute::evaluate($number);
|
||||||
|
|
||||||
if (!is_numeric($number)) {
|
|
||||||
return Functions::VALUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return abs($number);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1205,19 +1149,15 @@ class MathTrig
|
||||||
*
|
*
|
||||||
* Returns the result of builtin function rad2deg after validating args.
|
* Returns the result of builtin function rad2deg after validating args.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the evaluate method in the MathTrig\Degrees class instead
|
||||||
|
*
|
||||||
* @param mixed $number Should be numeric
|
* @param mixed $number Should be numeric
|
||||||
*
|
*
|
||||||
* @return float|string Rounded number
|
* @return float|string Rounded number
|
||||||
*/
|
*/
|
||||||
public static function builtinDEGREES($number)
|
public static function builtinDEGREES($number)
|
||||||
{
|
{
|
||||||
$number = Functions::flattenSingleValue($number);
|
return MathTrig\Degrees::evaluate($number);
|
||||||
|
|
||||||
if (!is_numeric($number)) {
|
|
||||||
return Functions::VALUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return rad2deg($number);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1225,19 +1165,15 @@ class MathTrig
|
||||||
*
|
*
|
||||||
* Returns the result of builtin function exp after validating args.
|
* Returns the result of builtin function exp after validating args.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the evaluate method in the MathTrig\Exp class instead
|
||||||
|
*
|
||||||
* @param mixed $number Should be numeric
|
* @param mixed $number Should be numeric
|
||||||
*
|
*
|
||||||
* @return float|string Rounded number
|
* @return float|string Rounded number
|
||||||
*/
|
*/
|
||||||
public static function builtinEXP($number)
|
public static function builtinEXP($number)
|
||||||
{
|
{
|
||||||
$number = Functions::flattenSingleValue($number);
|
return MathTrig\Exp::evaluate($number);
|
||||||
|
|
||||||
if (!is_numeric($number)) {
|
|
||||||
return Functions::VALUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return exp($number);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1277,19 +1213,15 @@ class MathTrig
|
||||||
*
|
*
|
||||||
* Returns the result of builtin function deg2rad after validating args.
|
* Returns the result of builtin function deg2rad after validating args.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the funcSin method in the MathTrig\Sin class instead
|
||||||
|
*
|
||||||
* @param mixed $number Should be numeric
|
* @param mixed $number Should be numeric
|
||||||
*
|
*
|
||||||
* @return float|string Rounded number
|
* @return float|string Rounded number
|
||||||
*/
|
*/
|
||||||
public static function builtinRADIANS($number)
|
public static function builtinRADIANS($number)
|
||||||
{
|
{
|
||||||
$number = Functions::flattenSingleValue($number);
|
return MathTrig\Radians::evaluate($number);
|
||||||
|
|
||||||
if (!is_numeric($number)) {
|
|
||||||
return Functions::VALUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return deg2rad($number);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1329,19 +1261,15 @@ class MathTrig
|
||||||
*
|
*
|
||||||
* Returns the result of builtin function sqrt after validating args.
|
* Returns the result of builtin function sqrt after validating args.
|
||||||
*
|
*
|
||||||
|
* @Deprecated 2.0.0 Use the evaluate method in the MathTrig\Sqrt class instead
|
||||||
|
*
|
||||||
* @param mixed $number Should be numeric
|
* @param mixed $number Should be numeric
|
||||||
*
|
*
|
||||||
* @return float|string Rounded number
|
* @return float|string Rounded number
|
||||||
*/
|
*/
|
||||||
public static function builtinSQRT($number)
|
public static function builtinSQRT($number)
|
||||||
{
|
{
|
||||||
$number = Functions::flattenSingleValue($number);
|
return MathTrig\Sqrt::evaluate($number);
|
||||||
|
|
||||||
if (!is_numeric($number)) {
|
|
||||||
return Functions::VALUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::numberOrNan(sqrt($number));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class Absolute
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* ABS.
|
||||||
|
*
|
||||||
|
* Returns the result of builtin function abs after validating args.
|
||||||
|
*
|
||||||
|
* @param mixed $number Should be numeric
|
||||||
|
*
|
||||||
|
* @return float|int|string Rounded number
|
||||||
|
*/
|
||||||
|
public static function evaluate($number)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$number = Helpers::validateNumericNullBool($number);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return abs($number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class Degrees
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* DEGREES.
|
||||||
|
*
|
||||||
|
* Returns the result of builtin function rad2deg after validating args.
|
||||||
|
*
|
||||||
|
* @param mixed $number Should be numeric
|
||||||
|
*
|
||||||
|
* @return float|string Rounded number
|
||||||
|
*/
|
||||||
|
public static function evaluate($number)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$number = Helpers::validateNumericNullBool($number);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rad2deg($number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class Exp
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* EXP.
|
||||||
|
*
|
||||||
|
* Returns the result of builtin function exp after validating args.
|
||||||
|
*
|
||||||
|
* @param mixed $number Should be numeric
|
||||||
|
*
|
||||||
|
* @return float|string Rounded number
|
||||||
|
*/
|
||||||
|
public static function evaluate($number)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$number = Helpers::validateNumericNullBool($number);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return exp($number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class Radians
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* RADIANS.
|
||||||
|
*
|
||||||
|
* Returns the result of builtin function deg2rad after validating args.
|
||||||
|
*
|
||||||
|
* @param mixed $number Should be numeric
|
||||||
|
*
|
||||||
|
* @return float|string Rounded number
|
||||||
|
*/
|
||||||
|
public static function evaluate($number)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$number = Helpers::validateNumericNullBool($number);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return deg2rad($number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class Sqrt
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* SQRT.
|
||||||
|
*
|
||||||
|
* Returns the result of builtin function sqrt after validating args.
|
||||||
|
*
|
||||||
|
* @param mixed $number Should be numeric
|
||||||
|
*
|
||||||
|
* @return float|string Rounded number
|
||||||
|
*/
|
||||||
|
public static function evaluate($number)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$number = Helpers::validateNumericNullBool($number);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Helpers::numberOrNan(sqrt($number));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class SqrtPi
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* SQRTPI.
|
||||||
|
*
|
||||||
|
* Returns the square root of (number * pi).
|
||||||
|
*
|
||||||
|
* @param float $number Number
|
||||||
|
*
|
||||||
|
* @return float|string Square Root of Number * Pi, or a string containing an error
|
||||||
|
*/
|
||||||
|
public static function evaluate($number)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$number = Helpers::validateNumericNullSubstitution($number, 0);
|
||||||
|
Helpers::validateNotNegative($number);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return sqrt($number * M_PI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,142 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
|
class SumSquares
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* SUMSQ.
|
||||||
|
*
|
||||||
|
* SUMSQ returns the sum of the squares of the arguments
|
||||||
|
*
|
||||||
|
* Excel Function:
|
||||||
|
* SUMSQ(value1[,value2[, ...]])
|
||||||
|
*
|
||||||
|
* @param mixed ...$args Data values
|
||||||
|
*
|
||||||
|
* @return float|string
|
||||||
|
*/
|
||||||
|
public static function sumSquare(...$args)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$returnValue = 0;
|
||||||
|
|
||||||
|
// Loop through arguments
|
||||||
|
foreach (Functions::flattenArray($args) as $arg) {
|
||||||
|
$arg1 = Helpers::validateNumericNullSubstitution($arg, 0);
|
||||||
|
$returnValue += ($arg1 * $arg1);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getCount(array $array1, array $array2): int
|
||||||
|
{
|
||||||
|
$count = count($array1);
|
||||||
|
if ($count !== count($array2)) {
|
||||||
|
throw new Exception(Functions::NA());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These functions accept only numeric arguments, not even strings which are numeric.
|
||||||
|
*
|
||||||
|
* @param mixed $item
|
||||||
|
*/
|
||||||
|
private static function numericNotString($item): bool
|
||||||
|
{
|
||||||
|
return is_numeric($item) && !is_string($item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SUMX2MY2.
|
||||||
|
*
|
||||||
|
* @param mixed[] $matrixData1 Matrix #1
|
||||||
|
* @param mixed[] $matrixData2 Matrix #2
|
||||||
|
*
|
||||||
|
* @return float|string
|
||||||
|
*/
|
||||||
|
public static function sumXSquaredMinusYSquared($matrixData1, $matrixData2)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$array1 = Functions::flattenArray($matrixData1);
|
||||||
|
$array2 = Functions::flattenArray($matrixData2);
|
||||||
|
$count = self::getCount($array1, $array2);
|
||||||
|
|
||||||
|
$result = 0;
|
||||||
|
for ($i = 0; $i < $count; ++$i) {
|
||||||
|
if (self::numericNotString($array1[$i]) && self::numericNotString($array2[$i])) {
|
||||||
|
$result += ($array1[$i] * $array1[$i]) - ($array2[$i] * $array2[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SUMX2PY2.
|
||||||
|
*
|
||||||
|
* @param mixed[] $matrixData1 Matrix #1
|
||||||
|
* @param mixed[] $matrixData2 Matrix #2
|
||||||
|
*
|
||||||
|
* @return float|string
|
||||||
|
*/
|
||||||
|
public static function sumXSquaredPlusYSquared($matrixData1, $matrixData2)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$array1 = Functions::flattenArray($matrixData1);
|
||||||
|
$array2 = Functions::flattenArray($matrixData2);
|
||||||
|
$count = self::getCount($array1, $array2);
|
||||||
|
|
||||||
|
$result = 0;
|
||||||
|
for ($i = 0; $i < $count; ++$i) {
|
||||||
|
if (self::numericNotString($array1[$i]) && self::numericNotString($array2[$i])) {
|
||||||
|
$result += ($array1[$i] * $array1[$i]) + ($array2[$i] * $array2[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SUMXMY2.
|
||||||
|
*
|
||||||
|
* @param mixed[] $matrixData1 Matrix #1
|
||||||
|
* @param mixed[] $matrixData2 Matrix #2
|
||||||
|
*
|
||||||
|
* @return float|string
|
||||||
|
*/
|
||||||
|
public static function sumXMinusYSquared($matrixData1, $matrixData2)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$array1 = Functions::flattenArray($matrixData1);
|
||||||
|
$array2 = Functions::flattenArray($matrixData2);
|
||||||
|
$count = self::getCount($array1, $array2);
|
||||||
|
|
||||||
|
$result = 0;
|
||||||
|
for ($i = 0; $i < $count; ++$i) {
|
||||||
|
if (self::numericNotString($array1[$i]) && self::numericNotString($array2[$i])) {
|
||||||
|
$result += ($array1[$i] - $array2[$i]) * ($array1[$i] - $array2[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,7 +17,7 @@ class FractionFormatter extends BaseFormatter
|
||||||
$decimalLength = strlen($decimalPart);
|
$decimalLength = strlen($decimalPart);
|
||||||
$decimalDivisor = 10 ** $decimalLength;
|
$decimalDivisor = 10 ** $decimalLength;
|
||||||
|
|
||||||
$GCD = MathTrig::GCD($decimalPart, $decimalDivisor);
|
$GCD = MathTrig\Gcd::evaluate($decimalPart, $decimalDivisor);
|
||||||
|
|
||||||
$adjustedDecimalPart = $decimalPart / $GCD;
|
$adjustedDecimalPart = $decimalPart / $GCD;
|
||||||
$adjustedDecimalDivisor = $decimalDivisor / $GCD;
|
$adjustedDecimalDivisor = $decimalDivisor / $GCD;
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,26 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
class AbsTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class AbsTest extends TestCase
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerAbs
|
* @dataProvider providerAbs
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
* @param mixed $val
|
* @param mixed $number
|
||||||
*/
|
*/
|
||||||
public function testRound($expectedResult, $val = null): void
|
public function testRound($expectedResult, $number = 'omitted'): void
|
||||||
{
|
{
|
||||||
if ($val === null) {
|
$sheet = $this->sheet;
|
||||||
$this->expectException(CalcExp::class);
|
$this->mightHaveException($expectedResult);
|
||||||
$formula = '=ABS()';
|
$this->setCell('A1', $number);
|
||||||
|
if ($number === 'omitted') {
|
||||||
|
$sheet->getCell('B1')->setValue('=ABS()');
|
||||||
} else {
|
} else {
|
||||||
$formula = "=ABS($val)";
|
$sheet->getCell('B1')->setValue('=ABS(A1)');
|
||||||
}
|
}
|
||||||
$spreadsheet = new Spreadsheet();
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
self::assertSame($expectedResult, $result);
|
||||||
$sheet->getCell('A1')->setValue($formula);
|
|
||||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerAbs()
|
public function providerAbs()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
|
@ -49,4 +50,18 @@ class AllSetupTeardown extends TestCase
|
||||||
$this->expectException(CalcException::class);
|
$this->expectException(CalcException::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
protected function setCell(string $cell, $value): void
|
||||||
|
{
|
||||||
|
if ($value !== null) {
|
||||||
|
if (is_string($value) && is_numeric($value)) {
|
||||||
|
$this->sheet->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
|
||||||
|
} else {
|
||||||
|
$this->sheet->getCell($cell)->setValue($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,26 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
class DegreesTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class DegreesTest extends TestCase
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerDEGREES
|
* @dataProvider providerDEGREES
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
* @param mixed $val
|
* @param mixed $number
|
||||||
*/
|
*/
|
||||||
public function testDEGREES($expectedResult, $val = null): void
|
public function testDegrees($expectedResult, $number = 'omitted'): void
|
||||||
{
|
{
|
||||||
if ($val === null) {
|
$sheet = $this->sheet;
|
||||||
$this->expectException(CalcExp::class);
|
$this->mightHaveException($expectedResult);
|
||||||
$formula = '=DEGREES()';
|
$this->setCell('A1', $number);
|
||||||
|
if ($number === 'omitted') {
|
||||||
|
$sheet->getCell('B1')->setValue('=DEGREES()');
|
||||||
} else {
|
} else {
|
||||||
$formula = "=DEGREES($val)";
|
$sheet->getCell('B1')->setValue('=DEGREES(A1)');
|
||||||
}
|
}
|
||||||
$spreadsheet = new Spreadsheet();
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
||||||
$sheet->getCell('A1')->setValue($formula);
|
|
||||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerDegrees()
|
public function providerDegrees()
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,28 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
class ExpTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class ExpTest extends TestCase
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerEXP
|
* @dataProvider providerEXP
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
* @param mixed $val
|
* @param mixed $number
|
||||||
*/
|
*/
|
||||||
public function testEXP($expectedResult, $val = null): void
|
public function testEXP($expectedResult, $number = 'omitted'): void
|
||||||
{
|
{
|
||||||
if ($val === null) {
|
$this->mightHaveException($expectedResult);
|
||||||
$this->expectException(CalcExp::class);
|
$sheet = $this->sheet;
|
||||||
$formula = '=EXP()';
|
if ($number !== null) {
|
||||||
} else {
|
$sheet->getCell('A1')->setValue($number);
|
||||||
$formula = "=EXP($val)";
|
|
||||||
}
|
}
|
||||||
$spreadsheet = new Spreadsheet();
|
if ($number === 'omitted') {
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet->getCell('B1')->setValue('=EXP()');
|
||||||
$sheet->getCell('A1')->setValue($formula);
|
} else {
|
||||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
$sheet->getCell('B1')->setValue('=EXP(A1)');
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
}
|
||||||
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerEXP()
|
public function providerEXP()
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ class MInverseTest extends AllSetupTeardown
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
*/
|
*/
|
||||||
public function testMINVERSE($expectedResult, ...$args): void
|
public function testMINVERSE($expectedResult, array $args): void
|
||||||
{
|
{
|
||||||
$result = MathTrig::MINVERSE(...$args);
|
$result = MathTrig\MatrixFunctions::funcMInverse($args);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class MMultTest extends AllSetupTeardown
|
||||||
*/
|
*/
|
||||||
public function testMMULT($expectedResult, ...$args): void
|
public function testMMULT($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = MathTrig::MMULT(...$args);
|
$result = MathTrig\MatrixFunctions::funcMMult(...$args);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class MovedFunctionsTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testMovedFunctions(): void
|
public function testMovedFunctions(): void
|
||||||
{
|
{
|
||||||
|
self::assertSame(1, MathTrig::builtinABS(1));
|
||||||
self::assertEqualsWithDelta(0, MathTrig::builtinACOS(1), 1E-9);
|
self::assertEqualsWithDelta(0, MathTrig::builtinACOS(1), 1E-9);
|
||||||
self::assertEqualsWithDelta(0, MathTrig::builtinACOSH(1), 1E-9);
|
self::assertEqualsWithDelta(0, MathTrig::builtinACOSH(1), 1E-9);
|
||||||
self::assertEqualsWithDelta(3.04192400109863, MathTrig::ACOT(-10), 1E-9);
|
self::assertEqualsWithDelta(3.04192400109863, MathTrig::ACOT(-10), 1E-9);
|
||||||
|
|
@ -35,12 +36,15 @@ class MovedFunctionsTest extends TestCase
|
||||||
self::assertEquals('#DIV/0!', MathTrig::COTH(0));
|
self::assertEquals('#DIV/0!', MathTrig::COTH(0));
|
||||||
self::assertEquals('#DIV/0!', MathTrig::CSC(0));
|
self::assertEquals('#DIV/0!', MathTrig::CSC(0));
|
||||||
self::assertEquals('#DIV/0!', MathTrig::CSCH(0));
|
self::assertEquals('#DIV/0!', MathTrig::CSCH(0));
|
||||||
|
self::assertEquals(0, MathTrig::builtinDEGREES(0));
|
||||||
self::assertEquals(6, MathTrig::EVEN(4.5));
|
self::assertEquals(6, MathTrig::EVEN(4.5));
|
||||||
|
self::assertEquals(1, MathTrig::builtinEXP(0));
|
||||||
self::assertEquals(6, MathTrig::FACT(3));
|
self::assertEquals(6, MathTrig::FACT(3));
|
||||||
self::assertEquals(105, MathTrig::FACTDOUBLE(7));
|
self::assertEquals(105, MathTrig::FACTDOUBLE(7));
|
||||||
self::assertEquals(-6, MathTrig::FLOOR(-4.5, 2));
|
self::assertEquals(-6, MathTrig::FLOOR(-4.5, 2));
|
||||||
self::assertEquals(0.23, MathTrig::FLOORMATH(0.234, 0.01));
|
self::assertEquals(0.23, MathTrig::FLOORMATH(0.234, 0.01));
|
||||||
self::assertEquals(-4, MathTrig::FLOORPRECISE(-2.5, 2));
|
self::assertEquals(-4, MathTrig::FLOORPRECISE(-2.5, 2));
|
||||||
|
self::assertEquals(2, MathTrig::GCD(4, 6));
|
||||||
self::assertEquals(-9, MathTrig::INT(-8.3));
|
self::assertEquals(-9, MathTrig::INT(-8.3));
|
||||||
self::assertEquals(12, MathTrig::LCM(4, 6));
|
self::assertEquals(12, MathTrig::LCM(4, 6));
|
||||||
self::assertEqualswithDelta(2.302585, MathTrig::builtinLN(10), 1E-6);
|
self::assertEqualswithDelta(2.302585, MathTrig::builtinLN(10), 1E-6);
|
||||||
|
|
@ -58,10 +62,12 @@ class MovedFunctionsTest extends TestCase
|
||||||
self::assertEquals(1, MathTrig::MOD(5, 2));
|
self::assertEquals(1, MathTrig::MOD(5, 2));
|
||||||
self::assertEquals(6, MathTrig::MROUND(7.3, 3));
|
self::assertEquals(6, MathTrig::MROUND(7.3, 3));
|
||||||
self::assertEquals(1, MathTrig::MULTINOMIAL(1));
|
self::assertEquals(1, MathTrig::MULTINOMIAL(1));
|
||||||
|
self::assertEquals(0, MathTrig::numberOrNan(0));
|
||||||
self::assertEquals(5, MathTrig::ODD(4.5));
|
self::assertEquals(5, MathTrig::ODD(4.5));
|
||||||
self::assertEquals(8, MathTrig::POWER(2, 3));
|
self::assertEquals(8, MathTrig::POWER(2, 3));
|
||||||
self::assertEquals(8, MathTrig::PRODUCT(1, 2, 4));
|
self::assertEquals(8, MathTrig::PRODUCT(1, 2, 4));
|
||||||
self::assertEquals(8, MathTrig::QUOTIENT(17, 2));
|
self::assertEquals(8, MathTrig::QUOTIENT(17, 2));
|
||||||
|
self::assertEquals(0, MathTrig::builtinRADIANS(0));
|
||||||
self::assertGreaterThanOrEqual(0, MATHTRIG::RAND());
|
self::assertGreaterThanOrEqual(0, MATHTRIG::RAND());
|
||||||
self::assertEquals('I', MathTrig::ROMAN(1));
|
self::assertEquals('I', MathTrig::ROMAN(1));
|
||||||
self::assertEquals(3.3, MathTrig::builtinROUND(3.27, 1));
|
self::assertEquals(3.3, MathTrig::builtinROUND(3.27, 1));
|
||||||
|
|
@ -73,10 +79,23 @@ class MovedFunctionsTest extends TestCase
|
||||||
self::assertEquals(1, MathTrig::SIGN(79.2));
|
self::assertEquals(1, MathTrig::SIGN(79.2));
|
||||||
self::assertEquals(0, MathTrig::builtinSIN(0));
|
self::assertEquals(0, MathTrig::builtinSIN(0));
|
||||||
self::assertEquals(0, MathTrig::builtinSINH(0));
|
self::assertEquals(0, MathTrig::builtinSINH(0));
|
||||||
|
self::assertEquals(0, MathTrig::builtinSQRT(0));
|
||||||
|
self::assertEqualswithDelta(3.54490770181103, MathTrig::SQRTPI(4), 1E-6);
|
||||||
self::assertEquals(0, MathTrig::SUBTOTAL(2, [0, 0]));
|
self::assertEquals(0, MathTrig::SUBTOTAL(2, [0, 0]));
|
||||||
self::assertEquals(7, MathTrig::SUM(1, 2, 4));
|
self::assertEquals(7, MathTrig::SUM(1, 2, 4));
|
||||||
self::assertEquals(4, MathTrig::SUMIF([[2], [4]], '>2'));
|
self::assertEquals(4, MathTrig::SUMIF([[2], [4]], '>2'));
|
||||||
|
self::assertEquals(2, MathTrig::SUMIFS(
|
||||||
|
[[1], [1], [1]],
|
||||||
|
[['Y'], ['Y'], ['N']],
|
||||||
|
'=Y',
|
||||||
|
[['H'], ['H'], ['H']],
|
||||||
|
'=H'
|
||||||
|
));
|
||||||
self::assertEquals(17, MathTrig::SUMPRODUCT([1, 2, 3], [5, 0, 4]));
|
self::assertEquals(17, MathTrig::SUMPRODUCT([1, 2, 3], [5, 0, 4]));
|
||||||
|
self::assertEquals(21, MathTrig::SUMSQ(1, 2, 4));
|
||||||
|
self::assertEquals(-20, MathTrig::SUMX2MY2([1, 2], [3, 4]));
|
||||||
|
self::assertEquals(30, MathTrig::SUMX2PY2([1, 2], [3, 4]));
|
||||||
|
self::assertEquals(8, MathTrig::SUMXMY2([1, 2], [3, 4]));
|
||||||
self::assertEquals(0, MathTrig::builtinTAN(0));
|
self::assertEquals(0, MathTrig::builtinTAN(0));
|
||||||
self::assertEquals(0, MathTrig::builtinTANH(0));
|
self::assertEquals(0, MathTrig::builtinTANH(0));
|
||||||
self::assertEquals(70, MathTrig::TRUNC(79.2, -1));
|
self::assertEquals(70, MathTrig::TRUNC(79.2, -1));
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,26 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
class RadiansTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class RadiansTest extends TestCase
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerRADIANS
|
* @dataProvider providerRADIANS
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
* @param mixed $val
|
* @param mixed $number
|
||||||
*/
|
*/
|
||||||
public function testRADIANS($expectedResult, $val = null): void
|
public function testRADIANS($expectedResult, $number = 'omitted'): void
|
||||||
{
|
{
|
||||||
if ($val === null) {
|
$sheet = $this->sheet;
|
||||||
$this->expectException(CalcExp::class);
|
$this->mightHaveException($expectedResult);
|
||||||
$formula = '=RADIANS()';
|
$this->setCell('A1', $number);
|
||||||
|
if ($number === 'omitted') {
|
||||||
|
$sheet->getCell('B1')->setValue('=RADIANS()');
|
||||||
} else {
|
} else {
|
||||||
$formula = "=RADIANS($val)";
|
$sheet->getCell('B1')->setValue('=RADIANS(A1)');
|
||||||
}
|
}
|
||||||
$spreadsheet = new Spreadsheet();
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
|
||||||
$sheet->getCell('A1')->setValue($formula);
|
|
||||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerRADIANS()
|
public function providerRADIANS()
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,27 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
class SqrtPiTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class SqrtPiTest extends TestCase
|
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerSQRTPI
|
* @dataProvider providerSQRTPI
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
* @param mixed $value
|
* @param mixed $number
|
||||||
*/
|
*/
|
||||||
public function testSQRTPI($expectedResult, $value): void
|
public function testSQRTPI($expectedResult, $number): void
|
||||||
{
|
{
|
||||||
$result = MathTrig::SQRTPI($value);
|
$this->mightHaveException($expectedResult);
|
||||||
|
$sheet = $this->sheet;
|
||||||
|
if ($number !== null) {
|
||||||
|
$sheet->getCell('A1')->setValue($number);
|
||||||
|
}
|
||||||
|
if ($number === 'omitted') {
|
||||||
|
$sheet->getCell('B1')->setValue('=SQRTPI()');
|
||||||
|
} else {
|
||||||
|
$sheet->getCell('B1')->setValue('=SQRTPI(A1)');
|
||||||
|
}
|
||||||
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,25 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
class SqrtTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class SqrtTest extends TestCase
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerSQRT
|
* @dataProvider providerSQRT
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
* @param mixed $val
|
* @param mixed $number
|
||||||
*/
|
*/
|
||||||
public function testSQRT($expectedResult, $val = null): void
|
public function testSQRT($expectedResult, $number = 'omitted'): void
|
||||||
{
|
{
|
||||||
if ($val === null) {
|
$sheet = $this->sheet;
|
||||||
$this->expectException(CalcExp::class);
|
$this->mightHaveException($expectedResult);
|
||||||
$formula = '=SQRT()';
|
$this->setCell('A1', $number);
|
||||||
|
if ($number === 'omitted') {
|
||||||
|
$sheet->getCell('B1')->setValue('=SQRT()');
|
||||||
} else {
|
} else {
|
||||||
$formula = "=SQRT($val)";
|
$sheet->getCell('B1')->setValue('=SQRT(A1)');
|
||||||
}
|
}
|
||||||
$spreadsheet = new Spreadsheet();
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
|
||||||
$sheet->getCell('A1')->setValue($formula);
|
|
||||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,10 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class SumIfsTest extends TestCase
|
class SumIfsTest extends AllSetupTeardown
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerSUMIFS
|
* @dataProvider providerSUMIFS
|
||||||
*
|
*
|
||||||
|
|
@ -20,7 +13,7 @@ class SumIfsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testSUMIFS($expectedResult, ...$args): void
|
public function testSUMIFS($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = MathTrig::SUMIFS(...$args);
|
$result = Statistical\Conditional::SUMIFS(...$args);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
class SumSqTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class SumSqTest extends TestCase
|
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerSUMSQ
|
* @dataProvider providerSUMSQ
|
||||||
*
|
*
|
||||||
|
|
@ -20,7 +11,19 @@ class SumSqTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testSUMSQ($expectedResult, ...$args): void
|
public function testSUMSQ($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = MathTrig::SUMSQ(...$args);
|
$this->mightHaveException($expectedResult);
|
||||||
|
$maxRow = 0;
|
||||||
|
$funcArg = '';
|
||||||
|
$sheet = $this->sheet;
|
||||||
|
foreach ($args as $arg) {
|
||||||
|
++$maxRow;
|
||||||
|
$funcArg = "A1:A$maxRow";
|
||||||
|
if ($arg !== null) {
|
||||||
|
$sheet->getCell("A$maxRow")->setValue($arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sheet->getCell('B1')->setValue("=SUMSQ($funcArg)");
|
||||||
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,34 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class SumX2MY2Test extends TestCase
|
class SumX2MY2Test extends AllSetupTeardown
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerSUMX2MY2
|
* @dataProvider providerSUMX2MY2
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
*/
|
*/
|
||||||
public function testSUMX2MY2($expectedResult, ...$args): void
|
public function testSUMX2MY2($expectedResult, array $matrixData1, array $matrixData2): void
|
||||||
{
|
{
|
||||||
$result = MathTrig::SUMX2MY2(...$args);
|
$this->mightHaveException($expectedResult);
|
||||||
|
$sheet = $this->sheet;
|
||||||
|
$maxRow = 0;
|
||||||
|
$funcArg1 = '';
|
||||||
|
foreach (Functions::flattenArray($matrixData1) as $arg) {
|
||||||
|
++$maxRow;
|
||||||
|
$funcArg1 = "A1:A$maxRow";
|
||||||
|
$this->setCell("A$maxRow", $arg);
|
||||||
|
}
|
||||||
|
$maxRow = 0;
|
||||||
|
$funcArg2 = '';
|
||||||
|
foreach (Functions::flattenArray($matrixData2) as $arg) {
|
||||||
|
++$maxRow;
|
||||||
|
$funcArg2 = "C1:C$maxRow";
|
||||||
|
$this->setCell("C$maxRow", $arg);
|
||||||
|
}
|
||||||
|
$sheet->getCell('B1')->setValue("=SUMX2MY2($funcArg1, $funcArg2)");
|
||||||
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,34 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class SumX2PY2Test extends TestCase
|
class SumX2PY2Test extends AllSetupTeardown
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerSUMX2PY2
|
* @dataProvider providerSUMX2PY2
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
*/
|
*/
|
||||||
public function testSUMX2PY2($expectedResult, ...$args): void
|
public function testSUMX2PY2($expectedResult, array $matrixData1, array $matrixData2): void
|
||||||
{
|
{
|
||||||
$result = MathTrig::SUMX2PY2(...$args);
|
$this->mightHaveException($expectedResult);
|
||||||
|
$sheet = $this->sheet;
|
||||||
|
$maxRow = 0;
|
||||||
|
$funcArg1 = '';
|
||||||
|
foreach (Functions::flattenArray($matrixData1) as $arg) {
|
||||||
|
++$maxRow;
|
||||||
|
$funcArg1 = "A1:A$maxRow";
|
||||||
|
$this->setCell("A$maxRow", $arg);
|
||||||
|
}
|
||||||
|
$maxRow = 0;
|
||||||
|
$funcArg2 = '';
|
||||||
|
foreach (Functions::flattenArray($matrixData2) as $arg) {
|
||||||
|
++$maxRow;
|
||||||
|
$funcArg2 = "C1:C$maxRow";
|
||||||
|
$this->setCell("C$maxRow", $arg);
|
||||||
|
}
|
||||||
|
$sheet->getCell('B1')->setValue("=SUMX2PY2($funcArg1, $funcArg2)");
|
||||||
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,34 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class SumXMY2Test extends TestCase
|
class SumXMY2Test extends AllSetupTeardown
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerSUMXMY2
|
* @dataProvider providerSUMXMY2
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
*/
|
*/
|
||||||
public function testSUMXMY2($expectedResult, ...$args): void
|
public function testSUMXMY2($expectedResult, array $matrixData1, array $matrixData2): void
|
||||||
{
|
{
|
||||||
$result = MathTrig::SUMXMY2(...$args);
|
$this->mightHaveException($expectedResult);
|
||||||
|
$sheet = $this->sheet;
|
||||||
|
$maxRow = 0;
|
||||||
|
$funcArg1 = '';
|
||||||
|
foreach (Functions::flattenArray($matrixData1) as $arg) {
|
||||||
|
++$maxRow;
|
||||||
|
$funcArg1 = "A1:A$maxRow";
|
||||||
|
$this->setCell("A$maxRow", $arg);
|
||||||
|
}
|
||||||
|
$maxRow = 0;
|
||||||
|
$funcArg2 = '';
|
||||||
|
foreach (Functions::flattenArray($matrixData2) as $arg) {
|
||||||
|
++$maxRow;
|
||||||
|
$funcArg2 = "C1:C$maxRow";
|
||||||
|
$this->setCell("C$maxRow", $arg);
|
||||||
|
}
|
||||||
|
$sheet->getCell('B1')->setValue("=SUMXMY2($funcArg1, $funcArg2)");
|
||||||
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['#VALUE!'], // exception - not enough args
|
['exception'], // exception - not enough args
|
||||||
['#VALUE!', '"ABC"'],
|
['#VALUE!', 'ABC'],
|
||||||
[35.51, '"35.51"'],
|
[35.51, '35.51'],
|
||||||
|
[35.51, '=35.51'],
|
||||||
|
[35.51, '="35.51"'],
|
||||||
[35.51, 35.51],
|
[35.51, 35.51],
|
||||||
[35.51, -35.51],
|
[35.51, -35.51],
|
||||||
[6, '"6"'],
|
[6, '6'],
|
||||||
[7, '"-7"'],
|
[7, '-7'],
|
||||||
[0, 0],
|
[0, 0],
|
||||||
|
[0, null],
|
||||||
|
[0, false],
|
||||||
|
[1, true],
|
||||||
|
['#VALUE!', ''],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['#VALUE!'], // exception not enough args
|
['exception'], // exception not enough args
|
||||||
['#VALUE!', '"ABC"'],
|
['#VALUE!', 'ABC'],
|
||||||
[45, M_PI / 4],
|
[45, M_PI / 4],
|
||||||
|
[0, 0],
|
||||||
|
[0, null],
|
||||||
|
[0, false],
|
||||||
|
['#VALUE!', ''],
|
||||||
|
[57.29577951, true],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['#VALUE!'], // exception not enough args
|
['exception'], // exception not enough args
|
||||||
['#VALUE!', '"ABC"'],
|
['#VALUE!', 'ABC'],
|
||||||
[2.718282, 1],
|
[2.7182818284590, 1],
|
||||||
|
[2.7182818284590, true],
|
||||||
|
[1, false],
|
||||||
|
[1, null],
|
||||||
|
['#VALUE!', ''],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['#VALUE!'], // exception not enough args
|
['exception'], // exception not enough args
|
||||||
['#VALUE!', '"ABC"'],
|
['#VALUE!', 'ABC'],
|
||||||
[M_PI / 4, 45],
|
[M_PI / 4, 45],
|
||||||
|
[0, 0],
|
||||||
|
[0, null],
|
||||||
|
[0, false],
|
||||||
|
['#VALUE!', ''],
|
||||||
|
['#VALUE!', '=15+""'],
|
||||||
|
[0, '=15+"-15"'],
|
||||||
|
[0.017453293, true],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['#VALUE!'], // exception not enough args
|
['exception'], // exception not enough args
|
||||||
['#VALUE!', '"ABC"'],
|
['#VALUE!', 'ABC'],
|
||||||
[0, 0],
|
[0, 0],
|
||||||
|
[0, null],
|
||||||
|
[0, false],
|
||||||
|
['#VALUE!', ''],
|
||||||
|
[1, true],
|
||||||
[1.5, 2.25],
|
[1.5, 2.25],
|
||||||
|
[1.5, '2.25'],
|
||||||
|
[1.5, '="2.25"'],
|
||||||
[1.772454, M_PI],
|
[1.772454, M_PI],
|
||||||
['#NUM!', -2.1],
|
['#NUM!', -2.1],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -61,4 +61,8 @@ return [
|
||||||
3.9633272976060101,
|
3.9633272976060101,
|
||||||
5,
|
5,
|
||||||
],
|
],
|
||||||
|
['#VALUE!', true],
|
||||||
|
['#VALUE!', false],
|
||||||
|
['0', null],
|
||||||
|
['exception', 'omitted'],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -44,4 +44,13 @@ return [
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
],
|
],
|
||||||
|
[14, 1, '2', 3],
|
||||||
|
[14, 1, '=2', 3],
|
||||||
|
[14, 1, '="2"', 3],
|
||||||
|
['#VALUE!', 1, 'X', 3],
|
||||||
|
['#VALUE!', 1, '', 3],
|
||||||
|
['#VALUE!', false, 2, 3],
|
||||||
|
['#VALUE!', 1, 2, true],
|
||||||
|
[5, 1, 2, null],
|
||||||
|
[10, 1, null, 3, null],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,14 @@ return [
|
||||||
[[1, 2], [3, 4]],
|
[[1, 2], [3, 4]],
|
||||||
[[5, 6], [7, 8]],
|
[[5, 6], [7, 8]],
|
||||||
],
|
],
|
||||||
|
[-20, [1, 2], [3, 4]],
|
||||||
|
[-20, [1, '=2'], [3, 4]],
|
||||||
|
[-8, [1, '2'], [3, 4]],
|
||||||
|
[-8, [1, '="2"'], [3, 4]],
|
||||||
|
[-8, [1, 'X'], [3, 4]],
|
||||||
|
[-8, [1, false], [3, 4]],
|
||||||
|
[-12, [1, 2], ['', 4]],
|
||||||
|
[-12, [1, 2], [null, 4]],
|
||||||
|
[-12, [1, 2], [true, 4]],
|
||||||
|
['#N/A', [1, 2], [3, 4, 5]], // different dimensions
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,14 @@ return [
|
||||||
[[1, 2], [3, 4]],
|
[[1, 2], [3, 4]],
|
||||||
[[5, 6], [7, 8]],
|
[[5, 6], [7, 8]],
|
||||||
],
|
],
|
||||||
|
[30, [1, 2], [3, 4]],
|
||||||
|
[30, [1, '=2'], [3, 4]],
|
||||||
|
[10, [1, ''], [3, 4]],
|
||||||
|
[10, [1, '2'], [3, 4]],
|
||||||
|
[10, [1, '="2"'], [3, 4]],
|
||||||
|
[10, [1, 'X'], [3, 4]],
|
||||||
|
[10, [1, false], [3, 4]],
|
||||||
|
[20, [1, 2], [null, 4]],
|
||||||
|
[20, [1, 2], [true, 4]],
|
||||||
|
['#N/A', [1, 2], [3, 4, 5]], // different dimensions
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,14 @@ return [
|
||||||
[[1, 2], [3, 4]],
|
[[1, 2], [3, 4]],
|
||||||
[[5, 6], [7, 8]],
|
[[5, 6], [7, 8]],
|
||||||
],
|
],
|
||||||
|
[8, [1, 2], [3, 4]],
|
||||||
|
[8, [1, '=2'], [3, 4]],
|
||||||
|
[4, [1, ''], [3, 4]],
|
||||||
|
[4, [1, '2'], [3, 4]],
|
||||||
|
[4, [1, '="2"'], [3, 4]],
|
||||||
|
[4, [1, 'X'], [3, 4]],
|
||||||
|
[4, [1, false], [3, 4]],
|
||||||
|
[4, [1, 2], [null, 4]],
|
||||||
|
[4, [1, 2], [true, 4]],
|
||||||
|
['#N/A', [1, 2], [3, 4, 5]], // different dimensions
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue