Get started with array-enabling the Engineering functions - Erf, Bessel, bitwise, comparisons Unit of Measure and Number base conversions first (#2594)

This commit is contained in:
Mark Baker 2022-02-16 18:32:07 +01:00 committed by GitHub
parent cdbe5c7c9b
commit ef839f56be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 1118 additions and 163 deletions

View File

@ -340,16 +340,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Engine/Logger.php path: src/PhpSpreadsheet/Calculation/Engine/Logger.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\:\\:BITLSHIFT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Engineering.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\:\\:BITRSHIFT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Engineering.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:besselj2a\\(\\) has no return type specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:besselj2a\\(\\) has no return type specified\\.$#"
count: 1 count: 1

View File

@ -61,7 +61,7 @@ class Engineering
* If $ord is nonnumeric, BESSELI returns the #VALUE! error value. * If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
* If $ord < 0, BESSELI returns the #NUM! error value. * If $ord < 0, BESSELI returns the #NUM! error value.
* *
* @return float|string Result, or a string containing an error * @return array|float|string Result, or a string containing an error
*/ */
public static function BESSELI($x, $ord) public static function BESSELI($x, $ord)
{ {
@ -86,7 +86,7 @@ class Engineering
* If $ord is nonnumeric, BESSELJ returns the #VALUE! error value. * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
* If $ord < 0, BESSELJ returns the #NUM! error value. * If $ord < 0, BESSELJ returns the #NUM! error value.
* *
* @return float|string Result, or a string containing an error * @return array|float|string Result, or a string containing an error
*/ */
public static function BESSELJ($x, $ord) public static function BESSELJ($x, $ord)
{ {
@ -112,7 +112,7 @@ class Engineering
* If $ord is nonnumeric, BESSELK returns the #VALUE! error value. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
* If $ord < 0, BESSELK returns the #NUM! error value. * If $ord < 0, BESSELK returns the #NUM! error value.
* *
* @return float|string Result, or a string containing an error * @return array|float|string Result, or a string containing an error
*/ */
public static function BESSELK($x, $ord) public static function BESSELK($x, $ord)
{ {
@ -137,7 +137,7 @@ class Engineering
* If $ord is nonnumeric, BESSELY returns the #VALUE! error value. * If $ord is nonnumeric, BESSELY returns the #VALUE! error value.
* If $ord < 0, BESSELY returns the #NUM! error value. * If $ord < 0, BESSELY returns the #NUM! error value.
* *
* @return float|string Result, or a string containing an error * @return array|float|string Result, or a string containing an error
*/ */
public static function BESSELY($x, $ord) public static function BESSELY($x, $ord)
{ {
@ -163,7 +163,7 @@ class Engineering
* If number is not a valid binary number, or if number contains more than * If number is not a valid binary number, or if number contains more than
* 10 characters (10 bits), BIN2DEC returns the #NUM! error value. * 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function BINTODEC($x) public static function BINTODEC($x)
{ {
@ -195,7 +195,7 @@ class Engineering
* If places is nonnumeric, BIN2HEX returns the #VALUE! error value. * If places is nonnumeric, BIN2HEX returns the #VALUE! error value.
* If places is negative, BIN2HEX returns the #NUM! error value. * If places is negative, BIN2HEX returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function BINTOHEX($x, $places = null) public static function BINTOHEX($x, $places = null)
{ {
@ -227,7 +227,7 @@ class Engineering
* If places is nonnumeric, BIN2OCT returns the #VALUE! error value. * If places is nonnumeric, BIN2OCT returns the #VALUE! error value.
* If places is negative, BIN2OCT returns the #NUM! error value. * If places is negative, BIN2OCT returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function BINTOOCT($x, $places = null) public static function BINTOOCT($x, $places = null)
{ {
@ -263,7 +263,7 @@ class Engineering
* If places is nonnumeric, DEC2BIN returns the #VALUE! error value. * If places is nonnumeric, DEC2BIN returns the #VALUE! error value.
* If places is zero or negative, DEC2BIN returns the #NUM! error value. * If places is zero or negative, DEC2BIN returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function DECTOBIN($x, $places = null) public static function DECTOBIN($x, $places = null)
{ {
@ -299,7 +299,7 @@ class Engineering
* If places is nonnumeric, DEC2HEX returns the #VALUE! error value. * If places is nonnumeric, DEC2HEX returns the #VALUE! error value.
* If places is zero or negative, DEC2HEX returns the #NUM! error value. * If places is zero or negative, DEC2HEX returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function DECTOHEX($x, $places = null) public static function DECTOHEX($x, $places = null)
{ {
@ -335,7 +335,7 @@ class Engineering
* If places is nonnumeric, DEC2OCT returns the #VALUE! error value. * If places is nonnumeric, DEC2OCT returns the #VALUE! error value.
* If places is zero or negative, DEC2OCT returns the #NUM! error value. * If places is zero or negative, DEC2OCT returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function DECTOOCT($x, $places = null) public static function DECTOOCT($x, $places = null)
{ {
@ -371,7 +371,7 @@ class Engineering
* If places is nonnumeric, HEX2BIN returns the #VALUE! error value. * If places is nonnumeric, HEX2BIN returns the #VALUE! error value.
* If places is negative, HEX2BIN returns the #NUM! error value. * If places is negative, HEX2BIN returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function HEXTOBIN($x, $places = null) public static function HEXTOBIN($x, $places = null)
{ {
@ -398,7 +398,7 @@ class Engineering
* If number is not a valid hexadecimal number, HEX2DEC returns the * If number is not a valid hexadecimal number, HEX2DEC returns the
* #NUM! error value. * #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function HEXTODEC($x) public static function HEXTODEC($x)
{ {
@ -438,7 +438,7 @@ class Engineering
* value. * value.
* If places is negative, HEX2OCT returns the #NUM! error value. * If places is negative, HEX2OCT returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function HEXTOOCT($x, $places = null) public static function HEXTOOCT($x, $places = null)
{ {
@ -480,7 +480,7 @@ class Engineering
* If places is negative, OCT2BIN returns the #NUM! error * If places is negative, OCT2BIN returns the #NUM! error
* value. * value.
* *
* @return string * @return array|string
*/ */
public static function OCTTOBIN($x, $places = null) public static function OCTTOBIN($x, $places = null)
{ {
@ -507,7 +507,7 @@ class Engineering
* If number is not a valid octal number, OCT2DEC returns the * If number is not a valid octal number, OCT2DEC returns the
* #NUM! error value. * #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function OCTTODEC($x) public static function OCTTODEC($x)
{ {
@ -544,7 +544,7 @@ class Engineering
* If places is nonnumeric, OCT2HEX returns the #VALUE! error value. * If places is nonnumeric, OCT2HEX returns the #VALUE! error value.
* If places is negative, OCT2HEX returns the #NUM! error value. * If places is negative, OCT2HEX returns the #NUM! error value.
* *
* @return string * @return array|string
*/ */
public static function OCTTOHEX($x, $places = null) public static function OCTTOHEX($x, $places = null)
{ {
@ -1123,7 +1123,7 @@ class Engineering
* @param float $a the first number * @param float $a the first number
* @param float $b The second number. If omitted, b is assumed to be zero. * @param float $b The second number. If omitted, b is assumed to be zero.
* *
* @return int|string (string in the event of an error) * @return array|int|string (string in the event of an error)
*/ */
public static function DELTA($a, $b = 0) public static function DELTA($a, $b = 0)
{ {
@ -1147,7 +1147,7 @@ class Engineering
* @param float $number the value to test against step * @param float $number the value to test against step
* @param float $step The threshold value. If you omit a value for step, GESTEP uses zero. * @param float $step The threshold value. If you omit a value for step, GESTEP uses zero.
* *
* @return int|string (string in the event of an error) * @return array|int|string (string in the event of an error)
*/ */
public static function GESTEP($number, $step = 0) public static function GESTEP($number, $step = 0)
{ {
@ -1169,7 +1169,7 @@ class Engineering
* @param int $number1 * @param int $number1
* @param int $number2 * @param int $number2
* *
* @return int|string * @return array|int|string
*/ */
public static function BITAND($number1, $number2) public static function BITAND($number1, $number2)
{ {
@ -1191,7 +1191,7 @@ class Engineering
* @param int $number1 * @param int $number1
* @param int $number2 * @param int $number2
* *
* @return int|string * @return array|int|string
*/ */
public static function BITOR($number1, $number2) public static function BITOR($number1, $number2)
{ {
@ -1213,7 +1213,7 @@ class Engineering
* @param int $number1 * @param int $number1
* @param int $number2 * @param int $number2
* *
* @return int|string * @return array|int|string
*/ */
public static function BITXOR($number1, $number2) public static function BITXOR($number1, $number2)
{ {
@ -1235,7 +1235,7 @@ class Engineering
* @param int $number * @param int $number
* @param int $shiftAmount * @param int $shiftAmount
* *
* @return int|string * @return array|float|int|string
*/ */
public static function BITLSHIFT($number, $shiftAmount) public static function BITLSHIFT($number, $shiftAmount)
{ {
@ -1257,7 +1257,7 @@ class Engineering
* @param int $number * @param int $number
* @param int $shiftAmount * @param int $shiftAmount
* *
* @return int|string * @return array|float|int|string
*/ */
public static function BITRSHIFT($number, $shiftAmount) public static function BITRSHIFT($number, $shiftAmount)
{ {
@ -1285,7 +1285,7 @@ class Engineering
* @param float $upper upper bound for integrating ERF. * @param float $upper upper bound for integrating ERF.
* If omitted, ERF integrates between zero and lower_limit * If omitted, ERF integrates between zero and lower_limit
* *
* @return float|string * @return array|float|string
*/ */
public static function ERF($lower, $upper = null) public static function ERF($lower, $upper = null)
{ {
@ -1306,7 +1306,7 @@ class Engineering
* *
* @param float $limit bound for integrating ERF * @param float $limit bound for integrating ERF
* *
* @return float|string * @return array|float|string
*/ */
public static function ERFPRECISE($limit) public static function ERFPRECISE($limit)
{ {
@ -1332,7 +1332,7 @@ class Engineering
* *
* @param float $x The lower bound for integrating ERFC * @param float $x The lower bound for integrating ERFC
* *
* @return float|string * @return array|float|string
*/ */
public static function ERFC($x) public static function ERFC($x)
{ {
@ -1437,7 +1437,7 @@ class Engineering
* @param string $fromUOM the units for value * @param string $fromUOM the units for value
* @param string $toUOM the units for the result * @param string $toUOM the units for the result
* *
* @return float|string * @return array|float|string
*/ */
public static function CONVERTUOM($value, $fromUOM, $toUOM) public static function CONVERTUOM($value, $fromUOM, $toUOM)
{ {

View File

@ -2,11 +2,14 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class BesselI class BesselI
{ {
use ArrayEnabled;
/** /**
* BESSELI. * BESSELI.
* *
@ -21,17 +24,22 @@ class BesselI
* *
* @param mixed $x A float value at which to evaluate the function. * @param mixed $x A float value at which to evaluate the function.
* If x is nonnumeric, BESSELI returns the #VALUE! error value. * If x is nonnumeric, BESSELI returns the #VALUE! error value.
* Or can be an array of values
* @param mixed $ord The integer order of the Bessel function. * @param mixed $ord The integer order of the Bessel function.
* If ord is not an integer, it is truncated. * If ord is not an integer, it is truncated.
* If $ord is nonnumeric, BESSELI returns the #VALUE! error value. * If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
* If $ord < 0, BESSELI returns the #NUM! error value. * If $ord < 0, BESSELI returns the #NUM! error value.
* Or can be an array of values
* *
* @return float|string Result, or a string containing an error * @return array|float|string Result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BESSELI($x, $ord) public static function BESSELI($x, $ord)
{ {
$x = Functions::flattenSingleValue($x); if (is_array($x) || is_array($ord)) {
$ord = Functions::flattenSingleValue($ord); return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
}
try { try {
$x = EngineeringValidations::validateFloat($x); $x = EngineeringValidations::validateFloat($x);

View File

@ -2,11 +2,14 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class BesselJ class BesselJ
{ {
use ArrayEnabled;
/** /**
* BESSELJ. * BESSELJ.
* *
@ -20,17 +23,22 @@ class BesselJ
* *
* @param mixed $x A float value at which to evaluate the function. * @param mixed $x A float value at which to evaluate the function.
* If x is nonnumeric, BESSELJ returns the #VALUE! error value. * If x is nonnumeric, BESSELJ returns the #VALUE! error value.
* Or can be an array of values
* @param mixed $ord The integer order of the Bessel function. * @param mixed $ord The integer order of the Bessel function.
* If ord is not an integer, it is truncated. * If ord is not an integer, it is truncated.
* If $ord is nonnumeric, BESSELJ returns the #VALUE! error value. * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
* If $ord < 0, BESSELJ returns the #NUM! error value. * If $ord < 0, BESSELJ returns the #NUM! error value.
* Or can be an array of values
* *
* @return float|string Result, or a string containing an error * @return array|float|string Result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BESSELJ($x, $ord) public static function BESSELJ($x, $ord)
{ {
$x = Functions::flattenSingleValue($x); if (is_array($x) || is_array($ord)) {
$ord = Functions::flattenSingleValue($ord); return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
}
try { try {
$x = EngineeringValidations::validateFloat($x); $x = EngineeringValidations::validateFloat($x);

View File

@ -2,11 +2,14 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class BesselK class BesselK
{ {
use ArrayEnabled;
/** /**
* BESSELK. * BESSELK.
* *
@ -18,17 +21,22 @@ class BesselK
* *
* @param mixed $x A float value at which to evaluate the function. * @param mixed $x A float value at which to evaluate the function.
* If x is nonnumeric, BESSELK returns the #VALUE! error value. * If x is nonnumeric, BESSELK returns the #VALUE! error value.
* Or can be an array of values
* @param mixed $ord The integer order of the Bessel function. * @param mixed $ord The integer order of the Bessel function.
* If ord is not an integer, it is truncated. * If ord is not an integer, it is truncated.
* If $ord is nonnumeric, BESSELK returns the #VALUE! error value. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
* If $ord < 0, BESSELKI returns the #NUM! error value. * If $ord < 0, BESSELKI returns the #NUM! error value.
* Or can be an array of values
* *
* @return float|string Result, or a string containing an error * @return array|float|string Result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BESSELK($x, $ord) public static function BESSELK($x, $ord)
{ {
$x = Functions::flattenSingleValue($x); if (is_array($x) || is_array($ord)) {
$ord = Functions::flattenSingleValue($ord); return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
}
try { try {
$x = EngineeringValidations::validateFloat($x); $x = EngineeringValidations::validateFloat($x);

View File

@ -2,11 +2,14 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class BesselY class BesselY
{ {
use ArrayEnabled;
/** /**
* BESSELY. * BESSELY.
* *
@ -17,17 +20,22 @@ class BesselY
* *
* @param mixed $x A float value at which to evaluate the function. * @param mixed $x A float value at which to evaluate the function.
* If x is nonnumeric, BESSELY returns the #VALUE! error value. * If x is nonnumeric, BESSELY returns the #VALUE! error value.
* Or can be an array of values
* @param mixed $ord The integer order of the Bessel function. * @param mixed $ord The integer order of the Bessel function.
* If ord is not an integer, it is truncated. * If ord is not an integer, it is truncated.
* If $ord is nonnumeric, BESSELY returns the #VALUE! error value. * If $ord is nonnumeric, BESSELY returns the #VALUE! error value.
* If $ord < 0, BESSELY returns the #NUM! error value. * If $ord < 0, BESSELY returns the #NUM! error value.
* Or can be an array of values
* *
* @return float|string Result, or a string containing an error * @return array|float|string Result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BESSELY($x, $ord) public static function BESSELY($x, $ord)
{ {
$x = Functions::flattenSingleValue($x); if (is_array($x) || is_array($ord)) {
$ord = Functions::flattenSingleValue($ord); return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord);
}
try { try {
$x = EngineeringValidations::validateFloat($x); $x = EngineeringValidations::validateFloat($x);

View File

@ -2,11 +2,14 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class BitWise class BitWise
{ {
use ArrayEnabled;
const SPLIT_DIVISOR = 2 ** 24; const SPLIT_DIVISOR = 2 ** 24;
/** /**
@ -27,13 +30,21 @@ class BitWise
* Excel Function: * Excel Function:
* BITAND(number1, number2) * BITAND(number1, number2)
* *
* @param int $number1 * @param array|int $number1
* @param int $number2 * Or can be an array of values
* @param array|int $number2
* Or can be an array of values
* *
* @return int|string * @return array|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BITAND($number1, $number2) public static function BITAND($number1, $number2)
{ {
if (is_array($number1) || is_array($number2)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
}
try { try {
$number1 = self::validateBitwiseArgument($number1); $number1 = self::validateBitwiseArgument($number1);
$number2 = self::validateBitwiseArgument($number2); $number2 = self::validateBitwiseArgument($number2);
@ -54,13 +65,21 @@ class BitWise
* Excel Function: * Excel Function:
* BITOR(number1, number2) * BITOR(number1, number2)
* *
* @param int $number1 * @param array|int $number1
* @param int $number2 * Or can be an array of values
* @param array|int $number2
* Or can be an array of values
* *
* @return int|string * @return array|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BITOR($number1, $number2) public static function BITOR($number1, $number2)
{ {
if (is_array($number1) || is_array($number2)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
}
try { try {
$number1 = self::validateBitwiseArgument($number1); $number1 = self::validateBitwiseArgument($number1);
$number2 = self::validateBitwiseArgument($number2); $number2 = self::validateBitwiseArgument($number2);
@ -82,13 +101,21 @@ class BitWise
* Excel Function: * Excel Function:
* BITXOR(number1, number2) * BITXOR(number1, number2)
* *
* @param int $number1 * @param array|int $number1
* @param int $number2 * Or can be an array of values
* @param array|int $number2
* Or can be an array of values
* *
* @return int|string * @return array|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BITXOR($number1, $number2) public static function BITXOR($number1, $number2)
{ {
if (is_array($number1) || is_array($number2)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
}
try { try {
$number1 = self::validateBitwiseArgument($number1); $number1 = self::validateBitwiseArgument($number1);
$number2 = self::validateBitwiseArgument($number2); $number2 = self::validateBitwiseArgument($number2);
@ -110,13 +137,21 @@ class BitWise
* Excel Function: * Excel Function:
* BITLSHIFT(number, shift_amount) * BITLSHIFT(number, shift_amount)
* *
* @param int $number * @param array|int $number
* @param int $shiftAmount * Or can be an array of values
* @param array|int $shiftAmount
* Or can be an array of values
* *
* @return float|int|string * @return array|float|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BITLSHIFT($number, $shiftAmount) public static function BITLSHIFT($number, $shiftAmount)
{ {
if (is_array($number) || is_array($shiftAmount)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $shiftAmount);
}
try { try {
$number = self::validateBitwiseArgument($number); $number = self::validateBitwiseArgument($number);
$shiftAmount = self::validateShiftAmount($shiftAmount); $shiftAmount = self::validateShiftAmount($shiftAmount);
@ -140,13 +175,21 @@ class BitWise
* Excel Function: * Excel Function:
* BITRSHIFT(number, shift_amount) * BITRSHIFT(number, shift_amount)
* *
* @param int $number * @param array|int $number
* @param int $shiftAmount * Or can be an array of values
* @param array|int $shiftAmount
* Or can be an array of values
* *
* @return float|int|string * @return array|float|int|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function BITRSHIFT($number, $shiftAmount) public static function BITRSHIFT($number, $shiftAmount)
{ {
if (is_array($number) || is_array($shiftAmount)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $shiftAmount);
}
try { try {
$number = self::validateBitwiseArgument($number); $number = self::validateBitwiseArgument($number);
$shiftAmount = self::validateShiftAmount($shiftAmount); $shiftAmount = self::validateShiftAmount($shiftAmount);
@ -171,7 +214,7 @@ class BitWise
*/ */
private static function validateBitwiseArgument($value) private static function validateBitwiseArgument($value)
{ {
self::nullFalseTrueToNumber($value); $value = self::nullFalseTrueToNumber($value);
if (is_numeric($value)) { if (is_numeric($value)) {
if ($value == floor($value)) { if ($value == floor($value)) {
@ -197,7 +240,7 @@ class BitWise
*/ */
private static function validateShiftAmount($value) private static function validateShiftAmount($value)
{ {
self::nullFalseTrueToNumber($value); $value = self::nullFalseTrueToNumber($value);
if (is_numeric($value)) { if (is_numeric($value)) {
if (abs($value) > 53) { if (abs($value) > 53) {
@ -214,14 +257,17 @@ class BitWise
* Many functions accept null/false/true argument treated as 0/0/1. * Many functions accept null/false/true argument treated as 0/0/1.
* *
* @param mixed $number * @param mixed $number
*
* @return mixed
*/ */
public static function nullFalseTrueToNumber(&$number): void private static function nullFalseTrueToNumber(&$number)
{ {
$number = Functions::flattenSingleValue($number);
if ($number === null) { if ($number === null) {
$number = 0; $number = 0;
} elseif (is_bool($number)) { } elseif (is_bool($number)) {
$number = (int) $number; $number = (int) $number;
} }
return $number;
} }
} }

View File

@ -2,11 +2,13 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Compare class Compare
{ {
use ArrayEnabled;
/** /**
* DELTA. * DELTA.
* *
@ -18,15 +20,20 @@ class Compare
* functions you calculate the count of equal pairs. This function is also known as the * functions you calculate the count of equal pairs. This function is also known as the
* Kronecker Delta function. * Kronecker Delta function.
* *
* @param float $a the first number * @param array|float $a the first number
* @param float $b The second number. If omitted, b is assumed to be zero. * Or can be an array of values
* @param array|float $b The second number. If omitted, b is assumed to be zero.
* Or can be an array of values
* *
* @return int|string (string in the event of an error) * @return array|int|string (string in the event of an error)
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function DELTA($a, $b = 0) public static function DELTA($a, $b = 0.0)
{ {
$a = Functions::flattenSingleValue($a); if (is_array($a) || is_array($b)) {
$b = Functions::flattenSingleValue($b); return self::evaluateArrayArguments([self::class, __FUNCTION__], $a, $b);
}
try { try {
$a = EngineeringValidations::validateFloat($a); $a = EngineeringValidations::validateFloat($a);
@ -35,7 +42,7 @@ class Compare
return $e->getMessage(); return $e->getMessage();
} }
return (int) ($a == $b); return (int) (abs($a - $b) < 1.0e-15);
} }
/** /**
@ -48,15 +55,20 @@ class Compare
* Use this function to filter a set of values. For example, by summing several GESTEP * Use this function to filter a set of values. For example, by summing several GESTEP
* functions you calculate the count of values that exceed a threshold. * functions you calculate the count of values that exceed a threshold.
* *
* @param float $number the value to test against step * @param array|float $number the value to test against step
* @param float $step The threshold value. If you omit a value for step, GESTEP uses zero. * Or can be an array of values
* @param array|float $step The threshold value. If you omit a value for step, GESTEP uses zero.
* Or can be an array of values
* *
* @return int|string (string in the event of an error) * @return array|int|string (string in the event of an error)
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function GESTEP($number, $step = 0) public static function GESTEP($number, $step = 0.0)
{ {
$number = Functions::flattenSingleValue($number); if (is_array($number) || is_array($step)) {
$step = Functions::flattenSingleValue($step); return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $step);
}
try { try {
$number = EngineeringValidations::validateFloat($number); $number = EngineeringValidations::validateFloat($number);

View File

@ -2,11 +2,14 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class ConvertBase abstract class ConvertBase
{ {
use ArrayEnabled;
protected static function validateValue($value): string protected static function validateValue($value): string
{ {
if (is_bool($value)) { if (is_bool($value)) {

View File

@ -15,17 +15,26 @@ class ConvertBinary extends ConvertBase
* Excel Function: * Excel Function:
* BIN2DEC(x) * BIN2DEC(x)
* *
* @param string $value The binary number (as a string) that you want to convert. The number * @param array|string $value The binary number (as a string) that you want to convert. The number
* cannot contain more than 10 characters (10 bits). The most significant * cannot contain more than 10 characters (10 bits). The most significant
* bit of number is the sign bit. The remaining 9 bits are magnitude bits. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
* Negative numbers are represented using two's-complement notation. * Negative numbers are represented using two's-complement notation.
* If number is not a valid binary number, or if number contains more than * If number is not a valid binary number, or if number contains more than
* 10 characters (10 bits), BIN2DEC returns the #NUM! error value. * 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toDecimal($value): string public static function toDecimal($value)
{ {
if (is_array($value)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateBinary($value); $value = self::validateBinary($value);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
@ -49,25 +58,35 @@ class ConvertBinary extends ConvertBase
* Excel Function: * Excel Function:
* BIN2HEX(x[,places]) * BIN2HEX(x[,places])
* *
* @param string $value The binary number (as a string) that you want to convert. The number * @param array|string $value The binary number (as a string) that you want to convert. The number
* cannot contain more than 10 characters (10 bits). The most significant * cannot contain more than 10 characters (10 bits). The most significant
* bit of number is the sign bit. The remaining 9 bits are magnitude bits. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
* Negative numbers are represented using two's-complement notation. * Negative numbers are represented using two's-complement notation.
* If number is not a valid binary number, or if number contains more than * If number is not a valid binary number, or if number contains more than
* 10 characters (10 bits), BIN2HEX returns the #NUM! error value. * 10 characters (10 bits), BIN2HEX returns the #NUM! error value.
* @param int $places The number of characters to use. If places is omitted, BIN2HEX uses the * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted, BIN2HEX uses the
* minimum number of characters necessary. Places is useful for padding the * minimum number of characters necessary. Places is useful for padding the
* return value with leading 0s (zeros). * return value with leading 0s (zeros).
* If places is not an integer, it is truncated. * If places is not an integer, it is truncated.
* If places is nonnumeric, BIN2HEX returns the #VALUE! error value. * If places is nonnumeric, BIN2HEX returns the #VALUE! error value.
* If places is negative, BIN2HEX returns the #NUM! error value. * If places is negative, BIN2HEX returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toHex($value, $places = null): string public static function toHex($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateBinary($value); $value = self::validateBinary($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -92,25 +111,35 @@ class ConvertBinary extends ConvertBase
* Excel Function: * Excel Function:
* BIN2OCT(x[,places]) * BIN2OCT(x[,places])
* *
* @param string $value The binary number (as a string) that you want to convert. The number * @param array|string $value The binary number (as a string) that you want to convert. The number
* cannot contain more than 10 characters (10 bits). The most significant * cannot contain more than 10 characters (10 bits). The most significant
* bit of number is the sign bit. The remaining 9 bits are magnitude bits. * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
* Negative numbers are represented using two's-complement notation. * Negative numbers are represented using two's-complement notation.
* If number is not a valid binary number, or if number contains more than * If number is not a valid binary number, or if number contains more than
* 10 characters (10 bits), BIN2OCT returns the #NUM! error value. * 10 characters (10 bits), BIN2OCT returns the #NUM! error value.
* @param int $places The number of characters to use. If places is omitted, BIN2OCT uses the * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted, BIN2OCT uses the
* minimum number of characters necessary. Places is useful for padding the * minimum number of characters necessary. Places is useful for padding the
* return value with leading 0s (zeros). * return value with leading 0s (zeros).
* If places is not an integer, it is truncated. * If places is not an integer, it is truncated.
* If places is nonnumeric, BIN2OCT returns the #VALUE! error value. * If places is nonnumeric, BIN2OCT returns the #VALUE! error value.
* If places is negative, BIN2OCT returns the #NUM! error value. * If places is negative, BIN2OCT returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toOctal($value, $places = null): string public static function toOctal($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateBinary($value); $value = self::validateBinary($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -22,7 +22,7 @@ class ConvertDecimal extends ConvertBase
* Excel Function: * Excel Function:
* DEC2BIN(x[,places]) * DEC2BIN(x[,places])
* *
* @param string $value The decimal integer you want to convert. If number is negative, * @param array|string $value The decimal integer you want to convert. If number is negative,
* valid place values are ignored and DEC2BIN returns a 10-character * valid place values are ignored and DEC2BIN returns a 10-character
* (10-bit) binary number in which the most significant bit is the sign * (10-bit) binary number in which the most significant bit is the sign
* bit. The remaining 9 bits are magnitude bits. Negative numbers are * bit. The remaining 9 bits are magnitude bits. Negative numbers are
@ -32,19 +32,29 @@ class ConvertDecimal extends ConvertBase
* If number is nonnumeric, DEC2BIN returns the #VALUE! error value. * If number is nonnumeric, DEC2BIN returns the #VALUE! error value.
* If DEC2BIN requires more than places characters, it returns the #NUM! * If DEC2BIN requires more than places characters, it returns the #NUM!
* error value. * error value.
* @param int $places The number of characters to use. If places is omitted, DEC2BIN uses * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted, DEC2BIN uses
* the minimum number of characters necessary. Places is useful for * the minimum number of characters necessary. Places is useful for
* padding the return value with leading 0s (zeros). * padding the return value with leading 0s (zeros).
* If places is not an integer, it is truncated. * If places is not an integer, it is truncated.
* If places is nonnumeric, DEC2BIN returns the #VALUE! error value. * If places is nonnumeric, DEC2BIN returns the #VALUE! error value.
* If places is zero or negative, DEC2BIN returns the #NUM! error value. * If places is zero or negative, DEC2BIN returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toBinary($value, $places = null): string public static function toBinary($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateDecimal($value); $value = self::validateDecimal($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -69,7 +79,7 @@ class ConvertDecimal extends ConvertBase
* Excel Function: * Excel Function:
* DEC2HEX(x[,places]) * DEC2HEX(x[,places])
* *
* @param string $value The decimal integer you want to convert. If number is negative, * @param array|string $value The decimal integer you want to convert. If number is negative,
* places is ignored and DEC2HEX returns a 10-character (40-bit) * places is ignored and DEC2HEX returns a 10-character (40-bit)
* hexadecimal number in which the most significant bit is the sign * hexadecimal number in which the most significant bit is the sign
* bit. The remaining 39 bits are magnitude bits. Negative numbers * bit. The remaining 39 bits are magnitude bits. Negative numbers
@ -79,19 +89,29 @@ class ConvertDecimal extends ConvertBase
* If number is nonnumeric, DEC2HEX returns the #VALUE! error value. * If number is nonnumeric, DEC2HEX returns the #VALUE! error value.
* If DEC2HEX requires more than places characters, it returns the * If DEC2HEX requires more than places characters, it returns the
* #NUM! error value. * #NUM! error value.
* @param int $places The number of characters to use. If places is omitted, DEC2HEX uses * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted, DEC2HEX uses
* the minimum number of characters necessary. Places is useful for * the minimum number of characters necessary. Places is useful for
* padding the return value with leading 0s (zeros). * padding the return value with leading 0s (zeros).
* If places is not an integer, it is truncated. * If places is not an integer, it is truncated.
* If places is nonnumeric, DEC2HEX returns the #VALUE! error value. * If places is nonnumeric, DEC2HEX returns the #VALUE! error value.
* If places is zero or negative, DEC2HEX returns the #NUM! error value. * If places is zero or negative, DEC2HEX returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toHex($value, $places = null): string public static function toHex($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateDecimal($value); $value = self::validateDecimal($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -135,7 +155,7 @@ class ConvertDecimal extends ConvertBase
* Excel Function: * Excel Function:
* DEC2OCT(x[,places]) * DEC2OCT(x[,places])
* *
* @param string $value The decimal integer you want to convert. If number is negative, * @param array|string $value The decimal integer you want to convert. If number is negative,
* places is ignored and DEC2OCT returns a 10-character (30-bit) * places is ignored and DEC2OCT returns a 10-character (30-bit)
* octal number in which the most significant bit is the sign bit. * octal number in which the most significant bit is the sign bit.
* The remaining 29 bits are magnitude bits. Negative numbers are * The remaining 29 bits are magnitude bits. Negative numbers are
@ -145,19 +165,29 @@ class ConvertDecimal extends ConvertBase
* If number is nonnumeric, DEC2OCT returns the #VALUE! error value. * If number is nonnumeric, DEC2OCT returns the #VALUE! error value.
* If DEC2OCT requires more than places characters, it returns the * If DEC2OCT requires more than places characters, it returns the
* #NUM! error value. * #NUM! error value.
* @param int $places The number of characters to use. If places is omitted, DEC2OCT uses * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted, DEC2OCT uses
* the minimum number of characters necessary. Places is useful for * the minimum number of characters necessary. Places is useful for
* padding the return value with leading 0s (zeros). * padding the return value with leading 0s (zeros).
* If places is not an integer, it is truncated. * If places is not an integer, it is truncated.
* If places is nonnumeric, DEC2OCT returns the #VALUE! error value. * If places is nonnumeric, DEC2OCT returns the #VALUE! error value.
* If places is zero or negative, DEC2OCT returns the #NUM! error value. * If places is zero or negative, DEC2OCT returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toOctal($value, $places = null): string public static function toOctal($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateDecimal($value); $value = self::validateDecimal($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -15,7 +15,7 @@ class ConvertHex extends ConvertBase
* Excel Function: * Excel Function:
* HEX2BIN(x[,places]) * HEX2BIN(x[,places])
* *
* @param string $value The hexadecimal number you want to convert. * @param array|string $value The hexadecimal number you want to convert.
* Number cannot contain more than 10 characters. * Number cannot contain more than 10 characters.
* The most significant bit of number is the sign bit (40th bit from the right). * The most significant bit of number is the sign bit (40th bit from the right).
* The remaining 9 bits are magnitude bits. * The remaining 9 bits are magnitude bits.
@ -25,19 +25,29 @@ class ConvertHex extends ConvertBase
* and if number is positive, it cannot be greater than 1FF. * and if number is positive, it cannot be greater than 1FF.
* If number is not a valid hexadecimal number, HEX2BIN returns the #NUM! error value. * If number is not a valid hexadecimal number, HEX2BIN returns the #NUM! error value.
* If HEX2BIN requires more than places characters, it returns the #NUM! error value. * If HEX2BIN requires more than places characters, it returns the #NUM! error value.
* @param int $places The number of characters to use. If places is omitted, * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted,
* HEX2BIN uses the minimum number of characters necessary. Places * HEX2BIN uses the minimum number of characters necessary. Places
* is useful for padding the return value with leading 0s (zeros). * is useful for padding the return value with leading 0s (zeros).
* If places is not an integer, it is truncated. * If places is not an integer, it is truncated.
* If places is nonnumeric, HEX2BIN returns the #VALUE! error value. * If places is nonnumeric, HEX2BIN returns the #VALUE! error value.
* If places is negative, HEX2BIN returns the #NUM! error value. * If places is negative, HEX2BIN returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toBinary($value, $places = null): string public static function toBinary($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateHex($value); $value = self::validateHex($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -55,18 +65,27 @@ class ConvertHex extends ConvertBase
* Excel Function: * Excel Function:
* HEX2DEC(x) * HEX2DEC(x)
* *
* @param string $value The hexadecimal number you want to convert. This number cannot * @param array|string $value The hexadecimal number you want to convert. This number cannot
* contain more than 10 characters (40 bits). The most significant * contain more than 10 characters (40 bits). The most significant
* bit of number is the sign bit. The remaining 39 bits are magnitude * bit of number is the sign bit. The remaining 39 bits are magnitude
* bits. Negative numbers are represented using two's-complement * bits. Negative numbers are represented using two's-complement
* notation. * notation.
* If number is not a valid hexadecimal number, HEX2DEC returns the * If number is not a valid hexadecimal number, HEX2DEC returns the
* #NUM! error value. * #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toDecimal($value): string public static function toDecimal($value)
{ {
if (is_array($value)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateHex($value); $value = self::validateHex($value);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
@ -99,7 +118,7 @@ class ConvertHex extends ConvertBase
* Excel Function: * Excel Function:
* HEX2OCT(x[,places]) * HEX2OCT(x[,places])
* *
* @param string $value The hexadecimal number you want to convert. Number cannot * @param array|string $value The hexadecimal number you want to convert. Number cannot
* contain more than 10 characters. The most significant bit of * contain more than 10 characters. The most significant bit of
* number is the sign bit. The remaining 39 bits are magnitude * number is the sign bit. The remaining 39 bits are magnitude
* bits. Negative numbers are represented using two's-complement * bits. Negative numbers are represented using two's-complement
@ -112,20 +131,30 @@ class ConvertHex extends ConvertBase
* the #NUM! error value. * the #NUM! error value.
* If HEX2OCT requires more than places characters, it returns * If HEX2OCT requires more than places characters, it returns
* the #NUM! error value. * the #NUM! error value.
* @param int $places The number of characters to use. If places is omitted, HEX2OCT * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted, HEX2OCT
* uses the minimum number of characters necessary. Places is * uses the minimum number of characters necessary. Places is
* useful for padding the return value with leading 0s (zeros). * useful for padding the return value with leading 0s (zeros).
* If places is not an integer, it is truncated. * If places is not an integer, it is truncated.
* If places is nonnumeric, HEX2OCT returns the #VALUE! error * If places is nonnumeric, HEX2OCT returns the #VALUE! error
* value. * value.
* If places is negative, HEX2OCT returns the #NUM! error value. * If places is negative, HEX2OCT returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toOctal($value, $places = null): string public static function toOctal($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateHex($value); $value = self::validateHex($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -15,7 +15,7 @@ class ConvertOctal extends ConvertBase
* Excel Function: * Excel Function:
* OCT2BIN(x[,places]) * OCT2BIN(x[,places])
* *
* @param string $value The octal number you want to convert. Number may not * @param array|string $value The octal number you want to convert. Number may not
* contain more than 10 characters. The most significant * contain more than 10 characters. The most significant
* bit of number is the sign bit. The remaining 29 bits * bit of number is the sign bit. The remaining 29 bits
* are magnitude bits. Negative numbers are represented * are magnitude bits. Negative numbers are represented
@ -28,7 +28,8 @@ class ConvertOctal extends ConvertBase
* the #NUM! error value. * the #NUM! error value.
* If OCT2BIN requires more than places characters, it * If OCT2BIN requires more than places characters, it
* returns the #NUM! error value. * returns the #NUM! error value.
* @param int $places The number of characters to use. If places is omitted, * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted,
* OCT2BIN uses the minimum number of characters necessary. * OCT2BIN uses the minimum number of characters necessary.
* Places is useful for padding the return value with * Places is useful for padding the return value with
* leading 0s (zeros). * leading 0s (zeros).
@ -37,13 +38,22 @@ class ConvertOctal extends ConvertBase
* error value. * error value.
* If places is negative, OCT2BIN returns the #NUM! error * If places is negative, OCT2BIN returns the #NUM! error
* value. * value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toBinary($value, $places = null): string public static function toBinary($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateOctal($value); $value = self::validateOctal($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -59,18 +69,27 @@ class ConvertOctal extends ConvertBase
* Excel Function: * Excel Function:
* OCT2DEC(x) * OCT2DEC(x)
* *
* @param string $value The octal number you want to convert. Number may not contain * @param array|string $value The octal number you want to convert. Number may not contain
* more than 10 octal characters (30 bits). The most significant * more than 10 octal characters (30 bits). The most significant
* bit of number is the sign bit. The remaining 29 bits are * bit of number is the sign bit. The remaining 29 bits are
* magnitude bits. Negative numbers are represented using * magnitude bits. Negative numbers are represented using
* two's-complement notation. * two's-complement notation.
* If number is not a valid octal number, OCT2DEC returns the * If number is not a valid octal number, OCT2DEC returns the
* #NUM! error value. * #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toDecimal($value): string public static function toDecimal($value)
{ {
if (is_array($value)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateOctal($value); $value = self::validateOctal($value);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
@ -99,7 +118,7 @@ class ConvertOctal extends ConvertBase
* Excel Function: * Excel Function:
* OCT2HEX(x[,places]) * OCT2HEX(x[,places])
* *
* @param string $value The octal number you want to convert. Number may not contain * @param array|string $value The octal number you want to convert. Number may not contain
* more than 10 octal characters (30 bits). The most significant * more than 10 octal characters (30 bits). The most significant
* bit of number is the sign bit. The remaining 29 bits are * bit of number is the sign bit. The remaining 29 bits are
* magnitude bits. Negative numbers are represented using * magnitude bits. Negative numbers are represented using
@ -110,25 +129,35 @@ class ConvertOctal extends ConvertBase
* #NUM! error value. * #NUM! error value.
* If OCT2HEX requires more than places characters, it returns * If OCT2HEX requires more than places characters, it returns
* the #NUM! error value. * the #NUM! error value.
* @param int $places The number of characters to use. If places is omitted, OCT2HEX * Or can be an array of values
* @param array|int $places The number of characters to use. If places is omitted, OCT2HEX
* uses the minimum number of characters necessary. Places is useful * uses the minimum number of characters necessary. Places is useful
* for padding the return value with leading 0s (zeros). * for padding the return value with leading 0s (zeros).
* If places is not an integer, it is truncated. * If places is not an integer, it is truncated.
* If places is nonnumeric, OCT2HEX returns the #VALUE! error value. * If places is nonnumeric, OCT2HEX returns the #VALUE! error value.
* If places is negative, OCT2HEX returns the #NUM! error value. * If places is negative, OCT2HEX returns the #NUM! error value.
* Or can be an array of values
*
* @return array|string Result, or an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function toHex($value, $places = null): string public static function toHex($value, $places = null)
{ {
if (is_array($value) || is_array($places)) {
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places);
}
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value)); $value = self::validateValue($value);
$value = self::validateOctal($value); $value = self::validateOctal($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces($places);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
$hexVal = strtoupper(dechex((int) self::toDecimal($value))); $hexVal = strtoupper(dechex((int) self::toDecimal($value)));
$hexVal = (PHP_INT_SIZE === 4 && strlen($value) === 10 && $value[0] >= '4') ? "FF$hexVal" : $hexVal; $hexVal = (PHP_INT_SIZE === 4 && strlen($value) === 10 && $value[0] >= '4') ? "FF{$hexVal}" : $hexVal;
return self::nbrConversionFormat($hexVal, $places); return self::nbrConversionFormat($hexVal, $places);
} }

View File

@ -2,11 +2,14 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class ConvertUOM class ConvertUOM
{ {
use ArrayEnabled;
public const CATEGORY_WEIGHT_AND_MASS = 'Weight and Mass'; public const CATEGORY_WEIGHT_AND_MASS = 'Weight and Mass';
public const CATEGORY_DISTANCE = 'Distance'; public const CATEGORY_DISTANCE = 'Distance';
public const CATEGORY_TIME = 'Time'; public const CATEGORY_TIME = 'Time';
@ -518,17 +521,22 @@ class ConvertUOM
* Excel Function: * Excel Function:
* CONVERT(value,fromUOM,toUOM) * CONVERT(value,fromUOM,toUOM)
* *
* @param float|int $value the value in fromUOM to convert * @param array|float|int|string $value the value in fromUOM to convert
* @param string $fromUOM the units for value * Or can be an array of values
* @param string $toUOM the units for the result * @param array|string $fromUOM the units for value
* Or can be an array of values
* @param array|string $toUOM the units for the result
* Or can be an array of values
* *
* @return float|string * @return array|float|string Result, or a string containing an error
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function CONVERT($value, $fromUOM, $toUOM) public static function CONVERT($value, $fromUOM, $toUOM)
{ {
$value = Functions::flattenSingleValue($value); if (is_array($value) || is_array($fromUOM) || is_array($toUOM)) {
$fromUOM = Functions::flattenSingleValue($fromUOM); return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $fromUOM, $toUOM);
$toUOM = Functions::flattenSingleValue($toUOM); }
if (!is_numeric($value)) { if (!is_numeric($value)) {
return Functions::VALUE(); return Functions::VALUE();

View File

@ -2,10 +2,13 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Erf class Erf
{ {
use ArrayEnabled;
private static $twoSqrtPi = 1.128379167095512574; private static $twoSqrtPi = 1.128379167095512574;
/** /**
@ -22,15 +25,20 @@ class Erf
* ERF(lower[,upper]) * ERF(lower[,upper])
* *
* @param mixed $lower Lower bound float for integrating ERF * @param mixed $lower Lower bound float for integrating ERF
* Or can be an array of values
* @param mixed $upper Upper bound float for integrating ERF. * @param mixed $upper Upper bound float for integrating ERF.
* If omitted, ERF integrates between zero and lower_limit * If omitted, ERF integrates between zero and lower_limit
* Or can be an array of values
* *
* @return float|string * @return array|float|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function ERF($lower, $upper = null) public static function ERF($lower, $upper = null)
{ {
$lower = Functions::flattenSingleValue($lower); if (is_array($lower) || is_array($upper)) {
$upper = Functions::flattenSingleValue($upper); return self::evaluateArrayArguments([self::class, __FUNCTION__], $lower, $upper);
}
if (is_numeric($lower)) { if (is_numeric($lower)) {
if ($upper === null) { if ($upper === null) {
@ -53,12 +61,17 @@ class Erf
* ERF.PRECISE(limit) * ERF.PRECISE(limit)
* *
* @param mixed $limit Float bound for integrating ERF, other bound is zero * @param mixed $limit Float bound for integrating ERF, other bound is zero
* Or can be an array of values
* *
* @return float|string * @return array|float|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function ERFPRECISE($limit) public static function ERFPRECISE($limit)
{ {
$limit = Functions::flattenSingleValue($limit); if (is_array($limit)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $limit);
}
return self::ERF($limit); return self::ERF($limit);
} }

View File

@ -2,10 +2,13 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class ErfC class ErfC
{ {
use ArrayEnabled;
/** /**
* ERFC. * ERFC.
* *
@ -20,12 +23,17 @@ class ErfC
* ERFC(x) * ERFC(x)
* *
* @param mixed $value The float lower bound for integrating ERFC * @param mixed $value The float lower bound for integrating ERFC
* Or can be an array of values
* *
* @return float|string * @return array|float|string
* If an array of numbers is passed as an argument, then the returned result will also be an array
* with the same dimensions
*/ */
public static function ERFC($value) public static function ERFC($value)
{ {
$value = Functions::flattenSingleValue($value); if (is_array($value)) {
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value);
}
if (is_numeric($value)) { if (is_numeric($value)) {
return self::erfcValue($value); return self::erfcValue($value);
@ -45,7 +53,7 @@ class ErfC
return 1 - Erf::erfValue($value); return 1 - Erf::erfValue($value);
} }
if ($value < 0) { if ($value < 0) {
return 2 - self::ERFC(-$value); return 2 - self::erfcValue(-$value);
} }
$a = $n = 1; $a = $n = 1;
$b = $c = $value; $b = $c = $value;

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BesselITest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BESSELI.php'; return require 'tests/data/Calculation/Engineering/BESSELI.php';
} }
/**
* @dataProvider providerBesselIArray
*/
public function testBesselIArray(array $expectedResult, string $value, string $ord): void
{
$calculation = Calculation::getInstance();
$formula = "=BESSELI({$value}, {$ord})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerBesselIArray(): array
{
return [
'row/column vector' => [
[
[1.393725572000487, 1.0634833439946074, 1.0, 1.0156861326120836, 3.2898391723912908],
[-0.7146779363262508, -0.25789430328903556, 0.0, 0.12597910862299733, 2.516716242025361],
[0.20259567978255663, 0.031906148375295325, 0.0, 0.007853269593280343, 1.276466158815611],
],
'{-1.2, -0.5, 0.0, 0.25, 2.5}',
'{0; 1; 2}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BesselJTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BESSELJ.php'; return require 'tests/data/Calculation/Engineering/BESSELJ.php';
} }
/**
* @dataProvider providerBesselJArray
*/
public function testBesselJArray(array $expectedResult, string $value, string $ord): void
{
$calculation = Calculation::getInstance();
$formula = "=BESSELJ({$value}, {$ord})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerBesselJArray(): array
{
return [
'row/column vector' => [
[
[0.6711327417644983, 0.9384698074235406, 1.00000000283141, 0.9844359313618615, -0.04838377582675685],
[-0.4982890574931824, -0.24226845767957006, 0.0, 0.12402597733693042, 0.49709410250442176],
[0.15934901834766313, 0.03060402345868265, 0.0, 0.007771889285962677, 0.44605905783029426],
],
'{-1.2, -0.5, 0.0, 0.25, 2.5}',
'{0; 1; 2}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BesselKTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BESSELK.php'; return require 'tests/data/Calculation/Engineering/BESSELK.php';
} }
/**
* @dataProvider providerBesselKArray
*/
public function testBesselKArray(array $expectedResult, string $value, string $ord): void
{
$calculation = Calculation::getInstance();
$formula = "=BESSELK({$value}, {$ord})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerBesselKArray(): array
{
return [
'row/column vector' => [
[
[4.721244734980139, 1.5415067364690132, 0.9244190350213235, 0.2976030874538336, 0.06234755419101918],
[99.97389411857176, 3.747025980669556, 1.6564411280110791, 0.4021240820149834, 0.07389081565026694],
[19999.500068449335, 31.517714581825462, 7.5501835470656395, 0.9410016186778072, 0.12146020671123273],
],
'{0.01, 0.25, 0.5, 1.25, 2.5}',
'{0; 1; 2}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BesselYTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BESSELY.php'; return require 'tests/data/Calculation/Engineering/BESSELY.php';
} }
/**
* @dataProvider providerBesselYArray
*/
public function testBesselYArray(array $expectedResult, string $value, string $ord): void
{
$calculation = Calculation::getInstance();
$formula = "=BESSELY({$value}, {$ord})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerBesselYArray(): array
{
return [
'row/column vector' => [
[
[-3.005455650891885, -0.9315730314941618, -0.44451873376270784, 0.25821685699105446, 0.4980703584466886],
[-63.67859624529592, -2.7041052277866418, -1.4714723918672943, -0.5843640364184131, 0.14591813750831284],
[-12732.713793408293, -20.701268790798974, -5.441370833706469, -1.1931993152605154, -0.3813358484400383],
],
'{0.01, 0.25, 0.5, 1.25, 2.5}',
'{0; 1; 2}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Bin2DecTest extends TestCase
$sheet->setCellValue($cell, '=BIN2DEC(101.1)'); $sheet->setCellValue($cell, '=BIN2DEC(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
} }
/**
* @dataProvider providerBin2DecArray
*/
public function testBin2DecArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=BIN2DEC({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerBin2DecArray(): array
{
return [
'row/column vector' => [
[[4, 7, 63, 153, 204, 341]],
'{"100", "111", "111111", "10011001", "11001100", "101010101"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Bin2HexTest extends TestCase
$sheet->setCellValue($cell, '=BIN2HEX(101.1)'); $sheet->setCellValue($cell, '=BIN2HEX(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
} }
/**
* @dataProvider providerBin2HexArray
*/
public function testBin2HexArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=BIN2HEX({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerBin2HexArray(): array
{
return [
'row/column vector' => [
[['4', '7', '3F', '99', 'CC', '155']],
'{"100", "111", "111111", "10011001", "11001100", "101010101"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Bin2OctTest extends TestCase
$sheet->setCellValue($cell, '=BIN2OCT(101.1)'); $sheet->setCellValue($cell, '=BIN2OCT(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
} }
/**
* @dataProvider providerBin2OctArray
*/
public function testBin2OctArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=BIN2OCT({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerBin2OctArray(): array
{
return [
'row/column vector' => [
[['4', '7', '77', '231', '314', '525']],
'{"100", "111", "111111", "10011001", "11001100", "101010101"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BitAndTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BITAND.php'; return require 'tests/data/Calculation/Engineering/BITAND.php';
} }
/**
* @dataProvider providerBitAndArray
*/
public function testBitAndArray(array $expectedResult, string $number1, string $number2): void
{
$calculation = Calculation::getInstance();
$formula = "=BITAND({$number1}, {$number2})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerBitAndArray(): array
{
return [
'row/column vector' => [
[
[3, 0, 1],
[4, 0, 0],
[5, 0, 1],
],
'{7, 8, 9}',
'{3; 4; 5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BitLShiftTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BITLSHIFT.php'; return require 'tests/data/Calculation/Engineering/BITLSHIFT.php';
} }
/**
* @dataProvider providerBitLShiftArray
*/
public function testBitLShiftArray(array $expectedResult, string $number, string $bits): void
{
$calculation = Calculation::getInstance();
$formula = "=BITLSHIFT({$number}, {$bits})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerBitLShiftArray(): array
{
return [
'row/column vector' => [
[
[14, 28, 56, 112, 224],
[16, 32, 64, 128, 256],
[18, 36, 72, 144, 288],
],
'{7; 8; 9}',
'{1, 2, 3, 4, 5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BitOrTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BITOR.php'; return require 'tests/data/Calculation/Engineering/BITOR.php';
} }
/**
* @dataProvider providerBitOrArray
*/
public function testBitOrArray(array $expectedResult, string $number1, string $number2): void
{
$calculation = Calculation::getInstance();
$formula = "=BITOR({$number1}, {$number2})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerBitOrArray(): array
{
return [
'row/column vector' => [
[
[7, 11, 11],
[7, 12, 13],
[7, 13, 13],
],
'{7, 8, 9}',
'{3; 4; 5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BitRShiftTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BITRSHIFT.php'; return require 'tests/data/Calculation/Engineering/BITRSHIFT.php';
} }
/**
* @dataProvider providerBitRShiftArray
*/
public function testBitRShiftArray(array $expectedResult, string $number, string $bits): void
{
$calculation = Calculation::getInstance();
$formula = "=BITRSHIFT({$number}, {$bits})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerBitRShiftArray(): array
{
return [
'row/column vector' => [
[
[31, 15, 7, 3, 1],
[32, 16, 8, 4, 2],
[37, 18, 9, 4, 2],
],
'{63; 64; 75}',
'{1, 2, 3, 4, 5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -30,4 +31,31 @@ class BitXorTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BITXOR.php'; return require 'tests/data/Calculation/Engineering/BITXOR.php';
} }
/**
* @dataProvider providerBitXorArray
*/
public function testBitXorArray(array $expectedResult, string $number1, string $number2): void
{
$calculation = Calculation::getInstance();
$formula = "=BITXOR({$number1}, {$number2})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerBitXorArray(): array
{
return [
'row/column vector' => [
[
[4, 11, 10],
[3, 12, 13],
[2, 13, 12],
],
'{7, 8, 9}',
'{3; 4; 5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -58,4 +59,58 @@ class ConvertUoMTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/CONVERTUOM.php'; return require 'tests/data/Calculation/Engineering/CONVERTUOM.php';
} }
/**
* @dataProvider providerConvertUoMArray
*/
public function testConvertUoMArray(array $expectedResult, string $value, string $fromUoM, string $toUoM): void
{
$calculation = Calculation::getInstance();
$formula = "=CONVERT({$value}, {$fromUoM}, {$toUoM})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerConvertUoMArray(): array
{
return [
'Weight/Mass' => [
[
[71.42857142857142, 0.15747304441777],
[453.5923699999991, 1.0],
],
'1000',
'{"lbm", "g"}',
'{"stone"; "kg"}',
],
'Distance' => [
[
[2025371.8285214372, 1093.6132983377101],
[1851.9999999999984, 1.0],
],
'1000',
'{"Nmi", "m"}',
'{"yd"; "km"}',
],
'Volume' => [
[
[2.976190476190475, 0.00628981077043211],
[473.1764729999994, 1.0],
],
'1000',
'{"pt", "ml"}',
'{"barrel"; "l"}',
],
'Area' => [
[
[999.9960000040016, 0.247104393046628],
[404.6856422400005, 0.1],
],
'1000',
'{"uk_acre", "m2"}',
'{"us_acre"; "ha"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Dec2BinTest extends TestCase
$sheet->setCellValue($cell, '=DEC2BIN(5.1)'); $sheet->setCellValue($cell, '=DEC2BIN(5.1)');
self::assertEquals(101, $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); self::assertEquals(101, $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
} }
/**
* @dataProvider providerDec2BinArray
*/
public function testDec2BinArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=DEC2BIN({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerDec2BinArray(): array
{
return [
'row/column vector' => [
[['100', '111', '111111', '10011001', '11001100', '101010101']],
'{4, 7, 63, 153, 204, 341}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
@ -98,4 +99,26 @@ class Dec2HexTest extends TestCase
self::assertEquals('7FFFFFFFFF', Engineering\ConvertDecimal::hex32bit(549755813887, 'FFFFFFFF', true)); self::assertEquals('7FFFFFFFFF', Engineering\ConvertDecimal::hex32bit(549755813887, 'FFFFFFFF', true));
self::assertEquals('FFFFFFFFFF', Engineering\ConvertDecimal::hex32bit(-1, 'FFFFFFFF', true)); self::assertEquals('FFFFFFFFFF', Engineering\ConvertDecimal::hex32bit(-1, 'FFFFFFFF', true));
} }
/**
* @dataProvider providerDec2HexArray
*/
public function testDec2HexArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=DEC2HEX({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerDec2HexArray(): array
{
return [
'row/column vector' => [
[['4', '7', '3F', '99', 'CC', '155']],
'{4, 7, 63, 153, 204, 341}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Dec2OctTest extends TestCase
$sheet->setCellValue($cell, '=DEC2OCT(17.1)'); $sheet->setCellValue($cell, '=DEC2OCT(17.1)');
self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
} }
/**
* @dataProvider providerDec2OctArray
*/
public function testDec2OctArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=DEC2OCT({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerDec2OctArray(): array
{
return [
'row/column vector' => [
[['4', '7', '77', '231', '314', '525']],
'{4, 7, 63, 153, 204, 341}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -16,11 +17,13 @@ class DeltaTest extends TestCase
/** /**
* @dataProvider providerDELTA * @dataProvider providerDELTA
* *
* @param mixed $a
* @param mixed $b
* @param mixed $expectedResult * @param mixed $expectedResult
*/ */
public function testDELTA($expectedResult, ...$args): void public function testDELTA($expectedResult, $a, $b): void
{ {
$result = Engineering::DELTA(...$args); $result = Engineering::DELTA($a, $b);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +31,33 @@ class DeltaTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/DELTA.php'; return require 'tests/data/Calculation/Engineering/DELTA.php';
} }
/**
* @dataProvider providerDeltaArray
*/
public function testDeltaArray(array $expectedResult, string $a, string $b): void
{
$calculation = Calculation::getInstance();
$formula = "=DELTA({$a}, {$b})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerDeltaArray(): array
{
return [
'row/column vector' => [
[
[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0],
[0, 0, 0, 0, 1],
],
'{-1.2, -0.5, 0.0, 0.25, 2.5}',
'{-1.2; -0.5; 0.0; 0.25; 2.5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -18,11 +19,12 @@ class ErfCTest extends TestCase
/** /**
* @dataProvider providerERFC * @dataProvider providerERFC
* *
* @param mixed $lower
* @param mixed $expectedResult * @param mixed $expectedResult
*/ */
public function testERFC($expectedResult, ...$args): void public function testERFC($expectedResult, $lower): void
{ {
$result = Engineering::ERFC(...$args); $result = Engineering::ERFC($lower);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
} }
@ -31,4 +33,28 @@ class ErfCTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/ERFC.php'; return require 'tests/data/Calculation/Engineering/ERFC.php';
} }
/**
* @dataProvider providerErfCArray
*/
public function testErfCArray(array $expectedResult, string $lower): void
{
$calculation = Calculation::getInstance();
$formula = "=ERFC({$lower})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerErfCArray(): array
{
return [
'row vector' => [
[
[1.9103139782296354, 1.5204998778130465, 1.0, 0.7236736098317631, 0.0004069520174449588],
],
'{-1.2, -0.5, 0.0, 0.25, 2.5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -18,11 +19,12 @@ class ErfPreciseTest extends TestCase
/** /**
* @dataProvider providerERFPRECISE * @dataProvider providerERFPRECISE
* *
* @param mixed $limit
* @param mixed $expectedResult * @param mixed $expectedResult
*/ */
public function testERFPRECISE($expectedResult, ...$args): void public function testERFPRECISE($expectedResult, $limit): void
{ {
$result = Engineering::ERFPRECISE(...$args); $result = Engineering::ERFPRECISE($limit);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
} }
@ -31,4 +33,28 @@ class ErfPreciseTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/ERFPRECISE.php'; return require 'tests/data/Calculation/Engineering/ERFPRECISE.php';
} }
/**
* @dataProvider providerErfPreciseArray
*/
public function testErfPreciseArray(array $expectedResult, string $limit): void
{
$calculation = Calculation::getInstance();
$formula = "=ERF.PRECISE({$limit})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerErfPreciseArray(): array
{
return [
'row vector' => [
[
[-0.9103139782296353, -0.5204998778130465, 0.0, 0.2763263901682369, 0.999593047982555],
],
'{-1.2, -0.5, 0.0, 0.25, 2.5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -18,11 +19,13 @@ class ErfTest extends TestCase
/** /**
* @dataProvider providerERF * @dataProvider providerERF
* *
* @param mixed $lower
* @param null|mixed $upper
* @param mixed $expectedResult * @param mixed $expectedResult
*/ */
public function testERF($expectedResult, ...$args): void public function testERF($expectedResult, $lower, $upper = null): void
{ {
$result = Engineering::ERF(...$args); $result = Engineering::ERF($lower, $upper);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
} }
@ -31,4 +34,28 @@ class ErfTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/ERF.php'; return require 'tests/data/Calculation/Engineering/ERF.php';
} }
/**
* @dataProvider providerErfArray
*/
public function testErfArray(array $expectedResult, string $lower, string $upper = 'NULL'): void
{
$calculation = Calculation::getInstance();
$formula = "=ERF({$lower}, {$upper})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerErfArray(): array
{
return [
'row vector' => [
[
[-0.9103139782296353, -0.5204998778130465, 0.0, 0.2763263901682369, 0.999593047982555],
],
'{-1.2, -0.5, 0.0, 0.25, 2.5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -16,11 +17,13 @@ class GeStepTest extends TestCase
/** /**
* @dataProvider providerGESTEP * @dataProvider providerGESTEP
* *
* @param mixed $a
* @param mixed $b
* @param mixed $expectedResult * @param mixed $expectedResult
*/ */
public function testGESTEP($expectedResult, ...$args): void public function testGESTEP($expectedResult, $a, $b): void
{ {
$result = Engineering::GESTEP(...$args); $result = Engineering::GESTEP($a, $b);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +31,33 @@ class GeStepTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/GESTEP.php'; return require 'tests/data/Calculation/Engineering/GESTEP.php';
} }
/**
* @dataProvider providerGeStepArray
*/
public function testGeStepArray(array $expectedResult, string $a, string $b): void
{
$calculation = Calculation::getInstance();
$formula = "=GESTEP({$a}, {$b})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerGeStepArray(): array
{
return [
'row/column vector' => [
[
[1, 1, 1, 1, 1],
[0, 1, 1, 1, 1],
[0, 1, 1, 1, 0],
[0, 1, 0, 1, 0],
[0, 1, 0, 0, 0],
],
'{-1.2, 2.5, 0.0, 0.25, -0.5}',
'{-1.2; -0.5; 0.0; 0.25; 2.5}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -93,4 +94,26 @@ class Hex2BinTest extends TestCase
$sheet->setCellValue($cell, '=HEX2BIN(10.1)'); $sheet->setCellValue($cell, '=HEX2BIN(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
} }
/**
* @dataProvider providerHex2BinArray
*/
public function testHex2BinArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=HEX2BIN({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerHex2BinArray(): array
{
return [
'row/column vector' => [
[['100', '111', '111111', '10011001', '11001100', '101010101']],
'{"4", "7", "3F", "99", "CC", "155"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -93,4 +94,26 @@ class Hex2DecTest extends TestCase
$sheet->setCellValue($cell, '=HEX2DEC(10.1)'); $sheet->setCellValue($cell, '=HEX2DEC(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
} }
/**
* @dataProvider providerHex2DecArray
*/
public function testHex2DecArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=HEX2DEC({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerHex2DecArray(): array
{
return [
'row/column vector' => [
[[4, 7, 63, 153, 204, 341]],
'{"4", "7", "3F", "99", "CC", "155"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Hex2OctTest extends TestCase
$sheet->setCellValue($cell, '=HEX2OCT(10.1)'); $sheet->setCellValue($cell, '=HEX2OCT(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
} }
/**
* @dataProvider providerHex2OctArray
*/
public function testHex2OctArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=HEX2OCT({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerHex2OctArray(): array
{
return [
'row/column vector' => [
[['4', '7', '77', '231', '314', '525']],
'{"4", "7", "3F", "99", "CC", "155"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Oct2BinTest extends TestCase
$sheet->setCellValue($cell, '=OCT2BIN(10.1)'); $sheet->setCellValue($cell, '=OCT2BIN(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
} }
/**
* @dataProvider providerOct2BinArray
*/
public function testOct2BinArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=OCT2BIN({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerOct2BinArray(): array
{
return [
'row/column vector' => [
[['100', '111', '111111', '10011001', '11001100', '101010101']],
'{"4", "7", "77", "231", "314", "525"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Oct2DecTest extends TestCase
$sheet->setCellValue($cell, '=OCT2DEC(10.1)'); $sheet->setCellValue($cell, '=OCT2DEC(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
} }
/**
* @dataProvider providerOct2DecArray
*/
public function testOct2DecArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=OCT2DEC({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerOct2DecArray(): array
{
return [
'row/column vector' => [
[[4, 7, 63, 153, 204, 341]],
'{"4", "7", "77", "231", "314", "525"}',
],
];
}
} }

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -90,4 +91,26 @@ class Oct2HexTest extends TestCase
$sheet->setCellValue($cell, '=OCT2HEX(20.1)'); $sheet->setCellValue($cell, '=OCT2HEX(20.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
} }
/**
* @dataProvider providerOct2HexArray
*/
public function testOct2HexArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=OCT2HEX({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerOct2HexArray(): array
{
return [
'row/column vector' => [
[['4', '7', '3F', '99', 'CC', '155']],
'{"4", "7", "77", "231", "314", "525"}',
],
];
}
} }