Continue MathTrig Breakup - Trig Functions (#1905)

* Continue MathTrig Breakup - Trig Functions

Continuing the process of breaking MathTrip.php up into smaller classes.
This round takes care of the trig and hyperbolic functions, plus a few others.
- COS, COSH, ACOS, ACOSH
- COT, COTH, ACOT, ACOTH
- CSC, CSCH
- SEC, SECH
- SIN, SINH, ASIN, ASINH
- TAN, TANH, ATAN, ATANH, ATAN2
- EVEN
- ODD
- SIGN

There are no bug fixes in this PR, except that boolean arguments are now
accepted for all these functions, as they are for Excel.
Taking a cue from what has been done in Engineering, the parameter validation
now happens in a routine which issues Exceptions for invalid values;
this simplifies the code in the functions themselves.

Consistent with earlier changes of this nature, the versions in the
MathTrig class remain, with a doc block indicating deprecation,
and a stub call to the new routines.

I think several more iterations will be needed to break up MathTrig completely.
This commit is contained in:
oleibman 2021-03-13 03:06:30 -08:00 committed by GitHub
parent 0d1957ad2c
commit 0ce8509a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
89 changed files with 1619 additions and 1383 deletions

View File

@ -243,22 +243,22 @@ class Calculation
], ],
'ACOS' => [ 'ACOS' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinACOS'], 'functionCall' => [MathTrig\Acos::class, 'funcAcos'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'ACOSH' => [ 'ACOSH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinACOSH'], 'functionCall' => [MathTrig\Acosh::class, 'funcAcosh'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'ACOT' => [ 'ACOT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'ACOT'], 'functionCall' => [MathTrig\Acot::class, 'funcAcot'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'ACOTH' => [ 'ACOTH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'ACOTH'], 'functionCall' => [MathTrig\Acoth::class, 'funcAcoth'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'ADDRESS' => [ 'ADDRESS' => [
@ -303,27 +303,27 @@ class Calculation
], ],
'ASIN' => [ 'ASIN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinASIN'], 'functionCall' => [MathTrig\Asin::class, 'funcAsin'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'ASINH' => [ 'ASINH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinASINH'], 'functionCall' => [MathTrig\Asinh::class, 'funcAsinh'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'ATAN' => [ 'ATAN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinATAN'], 'functionCall' => [MathTrig\Atan::class, 'funcAtan'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'ATAN2' => [ 'ATAN2' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'ATAN2'], 'functionCall' => [MathTrig\Atan2::class, 'funcAtan2'],
'argumentCount' => '2', 'argumentCount' => '2',
], ],
'ATANH' => [ 'ATANH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinATANH'], 'functionCall' => [MathTrig\Atanh::class, 'funcAtanh'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'AVEDEV' => [ 'AVEDEV' => [
@ -605,22 +605,22 @@ class Calculation
], ],
'COS' => [ 'COS' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinCOS'], 'functionCall' => [MathTrig\Cos::class, 'funcCos'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'COSH' => [ 'COSH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinCOSH'], 'functionCall' => [MathTrig\Cosh::class, 'funcCosh'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'COT' => [ 'COT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'COT'], 'functionCall' => [MathTrig\Cot::class, 'funcCot'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'COTH' => [ 'COTH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'COTH'], 'functionCall' => [MathTrig\Coth::class, 'funcCoth'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'COUNT' => [ 'COUNT' => [
@ -700,12 +700,12 @@ class Calculation
], ],
'CSC' => [ 'CSC' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'CSC'], 'functionCall' => [MathTrig\Csc::class, 'funcCsc'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'CSCH' => [ 'CSCH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'CSCH'], 'functionCall' => [MathTrig\Csch::class, 'funcCsch'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'CUBEKPIMEMBER' => [ 'CUBEKPIMEMBER' => [
@ -965,7 +965,7 @@ class Calculation
], ],
'EVEN' => [ 'EVEN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'EVEN'], 'functionCall' => [MathTrig\Even::class, 'funcEven'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'EXACT' => [ 'EXACT' => [
@ -1856,7 +1856,7 @@ class Calculation
], ],
'ODD' => [ 'ODD' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'ODD'], 'functionCall' => [MathTrig\Odd::class, 'funcOdd'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'ODDFPRICE' => [ 'ODDFPRICE' => [
@ -2165,12 +2165,12 @@ class Calculation
], ],
'SEC' => [ 'SEC' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'SEC'], 'functionCall' => [MathTrig\Sec::class, 'funcSec'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'SECH' => [ 'SECH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'SECH'], 'functionCall' => [MathTrig\Sech::class, 'funcSech'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'SECOND' => [ 'SECOND' => [
@ -2200,7 +2200,7 @@ class Calculation
], ],
'SIGN' => [ 'SIGN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'SIGN'], 'functionCall' => [MathTrig\Sign::class, 'funcSign'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'SIN' => [ 'SIN' => [
@ -2210,7 +2210,7 @@ class Calculation
], ],
'SINH' => [ 'SINH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinSINH'], 'functionCall' => [MathTrig\Sinh::class, 'funcSinh'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'SKEW' => [ 'SKEW' => [
@ -2366,12 +2366,12 @@ class Calculation
], ],
'TAN' => [ 'TAN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinTAN'], 'functionCall' => [MathTrig\Tan::class, 'funcTan'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'TANH' => [ 'TANH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG, 'category' => Category::CATEGORY_MATH_AND_TRIG,
'functionCall' => [MathTrig::class, 'builtinTANH'], 'functionCall' => [MathTrig\Tanh::class, 'funcTanh'],
'argumentCount' => '1', 'argumentCount' => '1',
], ],
'TBILLEQ' => [ 'TBILLEQ' => [

View File

@ -133,6 +133,8 @@ class MathTrig
* Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard * Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard
* PHP atan2() function, so we need to reverse them here before calling the PHP atan() function. * PHP atan2() function, so we need to reverse them here before calling the PHP atan() function.
* *
* @Deprecated 2.0.0 Use the funcAtan2 method in the MathTrig\Atan2 class instead
*
* Excel Function: * Excel Function:
* ATAN2(xCoordinate,yCoordinate) * ATAN2(xCoordinate,yCoordinate)
* *
@ -143,27 +145,7 @@ class MathTrig
*/ */
public static function ATAN2($xCoordinate = null, $yCoordinate = null) public static function ATAN2($xCoordinate = null, $yCoordinate = null)
{ {
$xCoordinate = Functions::flattenSingleValue($xCoordinate); return MathTrig\Atan2::funcAtan2($xCoordinate, $yCoordinate);
$yCoordinate = Functions::flattenSingleValue($yCoordinate);
$xCoordinate = $xCoordinate ?? 0.0;
$yCoordinate = $yCoordinate ?? 0.0;
if (
((is_numeric($xCoordinate)) || (is_bool($xCoordinate))) &&
((is_numeric($yCoordinate))) || (is_bool($yCoordinate))
) {
$xCoordinate = (float) $xCoordinate;
$yCoordinate = (float) $yCoordinate;
if (($xCoordinate == 0) && ($yCoordinate == 0)) {
return Functions::DIV0();
}
return atan2($yCoordinate, $xCoordinate);
}
return Functions::VALUE();
} }
/** /**
@ -226,8 +208,6 @@ class MathTrig
* @param float $significance the multiple to which you want to round * @param float $significance the multiple to which you want to round
* *
* @return float|string Rounded Number, or a string containing an error * @return float|string Rounded Number, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function CEILING($number, $significance = null) public static function CEILING($number, $significance = null)
{ {
@ -269,6 +249,8 @@ class MathTrig
/** /**
* EVEN. * EVEN.
* *
* @Deprecated 2.0.0 Use the funcEven method in the MathTrig\Even class instead
*
* Returns number rounded up to the nearest even integer. * Returns number rounded up to the nearest even integer.
* You can use this function for processing items that come in twos. For example, * You can use this function for processing items that come in twos. For example,
* a packing crate accepts rows of one or two items. The crate is full when * a packing crate accepts rows of one or two items. The crate is full when
@ -284,26 +266,17 @@ class MathTrig
*/ */
public static function EVEN($number) public static function EVEN($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Even::funcEven($number);
if ($number === null) {
return 0;
} elseif (is_bool($number)) {
$number = (int) $number;
}
if (is_numeric($number)) {
return self::getEven((float) $number);
}
return Functions::VALUE();
} }
/**
* Helper function for Even.
*
* @Deprecated 2.0.0 Use the getEven method in the MathTrig\Helpers class instead
*/
public static function getEven(float $number): int public static function getEven(float $number): int
{ {
$significance = 2 * self::returnSign($number); return (int) MathTrig\Helpers::getEven($number);
return (int) MathTrig\Ceiling::funcCeiling($number, $significance);
} }
/** /**
@ -395,8 +368,6 @@ class MathTrig
* @param float $significance Significance * @param float $significance Significance
* *
* @return float|string Rounded Number, or a string containing an error * @return float|string Rounded Number, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function FLOOR($number, $significance = null) public static function FLOOR($number, $significance = null)
{ {
@ -420,8 +391,6 @@ class MathTrig
* @param int $mode direction to round negative numbers * @param int $mode direction to round negative numbers
* *
* @return float|string Rounded Number, or a string containing an error * @return float|string Rounded Number, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function FLOORMATH($number, $significance = null, $mode = 0) public static function FLOORMATH($number, $significance = null, $mode = 0)
{ {
@ -444,8 +413,6 @@ class MathTrig
* @param float $significance Significance * @param float $significance Significance
* *
* @return float|string Rounded Number, or a string containing an error * @return float|string Rounded Number, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function FLOORPRECISE($number, $significance = 1) public static function FLOORPRECISE($number, $significance = 1)
{ {
@ -472,8 +439,6 @@ class MathTrig
* @param float $number Number to cast to an integer * @param float $number Number to cast to an integer
* *
* @return int|string Integer value, or a string containing an error * @return int|string Integer value, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function INT($number) public static function INT($number)
{ {
@ -797,8 +762,6 @@ class MathTrig
* @param int $multiple Multiple to which you want to round $number * @param int $multiple Multiple to which you want to round $number
* *
* @return float|string Rounded Number, or a string containing an error * @return float|string Rounded Number, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function MROUND($number, $multiple) public static function MROUND($number, $multiple)
{ {
@ -847,36 +810,15 @@ class MathTrig
* *
* Returns number rounded up to the nearest odd integer. * Returns number rounded up to the nearest odd integer.
* *
* @Deprecated 2.0.0 Use the funcOdd method in the MathTrig\Odd class instead
*
* @param float $number Number to round * @param float $number Number to round
* *
* @return int|string Rounded Number, or a string containing an error * @return int|string Rounded Number, or a string containing an error
*/ */
public static function ODD($number) public static function ODD($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Odd::funcOdd($number);
if ($number === null) {
return 1;
} elseif (is_bool($number)) {
return 1;
} elseif (is_numeric($number)) {
$significance = self::returnSign($number);
if ($significance == 0) {
return 1;
}
$result = MathTrig\Ceiling::funcCeiling($number, $significance);
if (is_string($result)) {
return $result;
}
if ($result == self::getEven((float) $result)) {
$result += $significance;
}
return (int) $result;
}
return Functions::VALUE();
} }
/** /**
@ -1015,8 +957,6 @@ class MathTrig
* @param mixed $style Number indicating one of five possible forms * @param mixed $style Number indicating one of five possible forms
* *
* @return string Roman numeral, or a string containing an error * @return string Roman numeral, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function ROMAN($aValue, $style = 0) public static function ROMAN($aValue, $style = 0)
{ {
@ -1036,8 +976,6 @@ class MathTrig
* @param int $digits Number of digits to which you want to round $number * @param int $digits Number of digits to which you want to round $number
* *
* @return float|string Rounded Number, or a string containing an error * @return float|string Rounded Number, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function ROUNDUP($number, $digits) public static function ROUNDUP($number, $digits)
{ {
@ -1057,8 +995,6 @@ class MathTrig
* @param int $digits Number of digits to which you want to round $number * @param int $digits Number of digits to which you want to round $number
* *
* @return float|string Rounded Number, or a string containing an error * @return float|string Rounded Number, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function ROUNDDOWN($number, $digits) public static function ROUNDDOWN($number, $digits)
{ {
@ -1109,27 +1045,25 @@ class MathTrig
* Determines the sign of a number. Returns 1 if the number is positive, zero (0) * Determines the sign of a number. Returns 1 if the number is positive, zero (0)
* if the number is 0, and -1 if the number is negative. * if the number is 0, and -1 if the number is negative.
* *
* @Deprecated 2.0.0 Use the funcSign method in the MathTrig\Sign class instead
*
* @param float $number Number to round * @param float $number Number to round
* *
* @return int|string sign value, or a string containing an error * @return int|string sign value, or a string containing an error
*/ */
public static function SIGN($number) public static function SIGN($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Sign::funcSign($number);
if (is_bool($number)) {
return (int) $number;
}
if (is_numeric($number)) {
return self::returnSign($number);
}
return Functions::VALUE();
} }
/**
* returnSign = returns 0/-1/+1.
*
* @Deprecated 2.0.0 Use the returnSign method in the MathTrig\Helpers class instead
*/
public static function returnSign(float $number): int public static function returnSign(float $number): int
{ {
return $number ? (($number > 0) ? 1 : -1) : 0; return MathTrig\Helpers::returnSign($number);
} }
/** /**
@ -1486,8 +1420,6 @@ class MathTrig
* @param int $digits * @param int $digits
* *
* @return float|string Truncated value, or a string containing an error * @return float|string Truncated value, or a string containing an error
*
* @codeCoverageIgnore
*/ */
public static function TRUNC($value = 0, $digits = 0) public static function TRUNC($value = 0, $digits = 0)
{ {
@ -1499,21 +1431,15 @@ class MathTrig
* *
* Returns the secant of an angle. * Returns the secant of an angle.
* *
* @Deprecated 2.0.0 Use the funcSec method in the MathTrig\Sec class instead
*
* @param float $angle Number * @param float $angle Number
* *
* @return float|string The secant of the angle * @return float|string The secant of the angle
*/ */
public static function SEC($angle) public static function SEC($angle)
{ {
$angle = Functions::flattenSingleValue($angle); return MathTrig\Sec::funcSec($angle);
if (!is_numeric($angle)) {
return Functions::VALUE();
}
$result = cos($angle);
return self::verySmallDivisor($result) ? Functions::DIV0() : (1 / $result);
} }
/** /**
@ -1521,21 +1447,15 @@ class MathTrig
* *
* Returns the hyperbolic secant of an angle. * Returns the hyperbolic secant of an angle.
* *
* @Deprecated 2.0.0 Use the funcSech method in the MathTrig\Sech class instead
*
* @param float $angle Number * @param float $angle Number
* *
* @return float|string The hyperbolic secant of the angle * @return float|string The hyperbolic secant of the angle
*/ */
public static function SECH($angle) public static function SECH($angle)
{ {
$angle = Functions::flattenSingleValue($angle); return MathTrig\Sech::funcSech($angle);
if (!is_numeric($angle)) {
return Functions::VALUE();
}
$result = cosh($angle);
return ($result == 0.0) ? Functions::DIV0() : 1 / $result;
} }
/** /**
@ -1543,21 +1463,15 @@ class MathTrig
* *
* Returns the cosecant of an angle. * Returns the cosecant of an angle.
* *
* @Deprecated 2.0.0 Use the funcCsc method in the MathTrig\Csc class instead
*
* @param float $angle Number * @param float $angle Number
* *
* @return float|string The cosecant of the angle * @return float|string The cosecant of the angle
*/ */
public static function CSC($angle) public static function CSC($angle)
{ {
$angle = Functions::flattenSingleValue($angle); return MathTrig\Csc::funcCsc($angle);
if (!is_numeric($angle)) {
return Functions::VALUE();
}
$result = sin($angle);
return self::verySmallDivisor($result) ? Functions::DIV0() : (1 / $result);
} }
/** /**
@ -1565,21 +1479,15 @@ class MathTrig
* *
* Returns the hyperbolic cosecant of an angle. * Returns the hyperbolic cosecant of an angle.
* *
* @Deprecated 2.0.0 Use the funcCsch method in the MathTrig\Csch class instead
*
* @param float $angle Number * @param float $angle Number
* *
* @return float|string The hyperbolic cosecant of the angle * @return float|string The hyperbolic cosecant of the angle
*/ */
public static function CSCH($angle) public static function CSCH($angle)
{ {
$angle = Functions::flattenSingleValue($angle); return MathTrig\Csch::funcCsch($angle);
if (!is_numeric($angle)) {
return Functions::VALUE();
}
$result = sinh($angle);
return ($result == 0.0) ? Functions::DIV0() : 1 / $result;
} }
/** /**
@ -1587,21 +1495,15 @@ class MathTrig
* *
* Returns the cotangent of an angle. * Returns the cotangent of an angle.
* *
* @Deprecated 2.0.0 Use the funcCot method in the MathTrig\Cot class instead
*
* @param float $angle Number * @param float $angle Number
* *
* @return float|string The cotangent of the angle * @return float|string The cotangent of the angle
*/ */
public static function COT($angle) public static function COT($angle)
{ {
$angle = Functions::flattenSingleValue($angle); return MathTrig\Cot::funcCot($angle);
if (!is_numeric($angle)) {
return Functions::VALUE();
}
$result = sin($angle);
return self::verySmallDivisor($result) ? Functions::DIV0() : (cos($angle) / $result);
} }
/** /**
@ -1609,21 +1511,15 @@ class MathTrig
* *
* Returns the hyperbolic cotangent of an angle. * Returns the hyperbolic cotangent of an angle.
* *
* @Deprecated 2.0.0 Use the funcCoth method in the MathTrig\Coth class instead
*
* @param float $angle Number * @param float $angle Number
* *
* @return float|string The hyperbolic cotangent of the angle * @return float|string The hyperbolic cotangent of the angle
*/ */
public static function COTH($angle) public static function COTH($angle)
{ {
$angle = Functions::flattenSingleValue($angle); return MathTrig\Coth::funcCoth($angle);
if (!is_numeric($angle)) {
return Functions::VALUE();
}
$result = tanh($angle);
return ($result == 0.0) ? Functions::DIV0() : 1 / $result;
} }
/** /**
@ -1631,31 +1527,29 @@ class MathTrig
* *
* Returns the arccotangent of a number. * Returns the arccotangent of a number.
* *
* @Deprecated 2.0.0 Use the funcAcot method in the MathTrig\Acot class instead
*
* @param float $number Number * @param float $number Number
* *
* @return float|string The arccotangent of the number * @return float|string The arccotangent of the number
*/ */
public static function ACOT($number) public static function ACOT($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Acot::funcAcot($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return (M_PI / 2) - atan($number);
} }
/** /**
* Return NAN or value depending on argument. * Return NAN or value depending on argument.
* *
* @Deprecated 2.0.0 Use the numberOrNan method in the MathTrig\Helpers class instead
*
* @param float $result Number * @param float $result Number
* *
* @return float|string * @return float|string
*/ */
public static function numberOrNan($result) public static function numberOrNan($result)
{ {
return is_nan($result) ? Functions::NAN() : $result; return MathTrig\Helpers::numberOrNan($result);
} }
/** /**
@ -1663,21 +1557,15 @@ class MathTrig
* *
* Returns the hyperbolic arccotangent of a number. * Returns the hyperbolic arccotangent of a number.
* *
* @Deprecated 2.0.0 Use the funcAcoth method in the MathTrig\Acoth class instead
*
* @param float $number Number * @param float $number Number
* *
* @return float|string The hyperbolic arccotangent of the number * @return float|string The hyperbolic arccotangent of the number
*/ */
public static function ACOTH($number) public static function ACOTH($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Acoth::funcAcoth($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
$result = log(($number + 1) / ($number - 1)) / 2;
return self::numberOrNan($result);
} }
/** /**
@ -1693,8 +1581,6 @@ class MathTrig
* @param mixed $precision Should be int * @param mixed $precision Should be int
* *
* @return float|string Rounded number * @return float|string Rounded number
*
* @codeCoverageIgnore
*/ */
public static function builtinROUND($number, $precision) public static function builtinROUND($number, $precision)
{ {
@ -1724,6 +1610,8 @@ class MathTrig
/** /**
* ACOS. * ACOS.
* *
* @Deprecated 2.0.0 Use the funcAcos method in the MathTrig\Acos class instead
*
* Returns the result of builtin function acos after validating args. * Returns the result of builtin function acos after validating args.
* *
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
@ -1732,13 +1620,7 @@ class MathTrig
*/ */
public static function builtinACOS($number) public static function builtinACOS($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Acos::funcAcos($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return self::numberOrNan(acos($number));
} }
/** /**
@ -1746,19 +1628,15 @@ class MathTrig
* *
* Returns the result of builtin function acosh after validating args. * Returns the result of builtin function acosh after validating args.
* *
* @Deprecated 2.0.0 Use the funcAcosh method in the MathTrig\Acosh class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinACOSH($number) public static function builtinACOSH($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Acosh::funcAcosh($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return self::numberOrNan(acosh($number));
} }
/** /**
@ -1766,19 +1644,15 @@ class MathTrig
* *
* Returns the result of builtin function asin after validating args. * Returns the result of builtin function asin after validating args.
* *
* @Deprecated 2.0.0 Use the funcAsin method in the MathTrig\Asin class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinASIN($number) public static function builtinASIN($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Asin::funcAsin($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return self::numberOrNan(asin($number));
} }
/** /**
@ -1786,39 +1660,31 @@ class MathTrig
* *
* Returns the result of builtin function asinh after validating args. * Returns the result of builtin function asinh after validating args.
* *
* @Deprecated 2.0.0 Use the funcAsinh method in the MathTrig\Asinh class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinASINH($number) public static function builtinASINH($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Asinh::funcAsinh($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return asinh($number);
} }
/** /**
* ASIN. * ATAN.
* *
* Returns the result of builtin function atan after validating args. * Returns the result of builtin function atan after validating args.
* *
* @Deprecated 2.0.0 Use the funcAtan method in the MathTrig\Atan class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinATAN($number) public static function builtinATAN($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Atan::funcAtan($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return self::numberOrNan(atan($number));
} }
/** /**
@ -1826,19 +1692,15 @@ class MathTrig
* *
* Returns the result of builtin function atanh after validating args. * Returns the result of builtin function atanh after validating args.
* *
* @Deprecated 2.0.0 Use the funcAtanh method in the MathTrig\Atanh class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinATANH($number) public static function builtinATANH($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Atanh::funcAtanh($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return atanh($number);
} }
/** /**
@ -1846,19 +1708,15 @@ class MathTrig
* *
* Returns the result of builtin function cos after validating args. * Returns the result of builtin function cos after validating args.
* *
* @Deprecated 2.0.0 Use the funcCos method in the MathTrig\Cos class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinCOS($number) public static function builtinCOS($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Cos::funcCos($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return cos($number);
} }
/** /**
@ -1866,19 +1724,15 @@ class MathTrig
* *
* Returns the result of builtin function cos after validating args. * Returns the result of builtin function cos after validating args.
* *
* @Deprecated 2.0.0 Use the funcCosh method in the MathTrig\Cosh class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinCOSH($number) public static function builtinCOSH($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Cosh::funcCosh($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return cosh($number);
} }
/** /**
@ -1984,6 +1838,8 @@ class MathTrig
/** /**
* SIN. * SIN.
* *
* @Deprecated 2.0.0 Use the funcSin method in the MathTrig\Sin class instead
*
* Returns the result of builtin function sin after validating args. * Returns the result of builtin function sin after validating args.
* *
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
@ -1992,18 +1848,14 @@ class MathTrig
*/ */
public static function builtinSIN($number) public static function builtinSIN($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Sin::funcSin($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return sin($number);
} }
/** /**
* SINH. * SINH.
* *
* @Deprecated 2.0.0 Use the funcSinh method in the MathTrig\Sinh class instead
*
* Returns the result of builtin function sinh after validating args. * Returns the result of builtin function sinh after validating args.
* *
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
@ -2012,13 +1864,7 @@ class MathTrig
*/ */
public static function builtinSINH($number) public static function builtinSINH($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Sinh::funcSinh($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return sinh($number);
} }
/** /**
@ -2046,19 +1892,15 @@ class MathTrig
* *
* Returns the result of builtin function tan after validating args. * Returns the result of builtin function tan after validating args.
* *
* @Deprecated 2.0.0 Use the funcTan method in the MathTrig\Tan class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinTAN($number) public static function builtinTAN($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Tan::funcTan($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return self::verySmallDivisor(cos($number)) ? Functions::DIV0() : tan($number);
} }
/** /**
@ -2066,29 +1908,22 @@ class MathTrig
* *
* Returns the result of builtin function sinh after validating args. * Returns the result of builtin function sinh after validating args.
* *
* @Deprecated 2.0.0 Use the funcTanh method in the MathTrig\Tanh class instead
*
* @param mixed $number Should be numeric * @param mixed $number Should be numeric
* *
* @return float|string Rounded number * @return float|string Rounded number
*/ */
public static function builtinTANH($number) public static function builtinTANH($number)
{ {
$number = Functions::flattenSingleValue($number); return MathTrig\Tanh::funcTanh($number);
if (!is_numeric($number)) {
return Functions::VALUE();
}
return tanh($number);
}
private static function verySmallDivisor(float $number): bool
{
return abs($number) < 1.0E-12;
} }
/** /**
* Many functions accept null/false/true argument treated as 0/0/1. * Many functions accept null/false/true argument treated as 0/0/1.
* *
* @Deprecated 2.0.0 Use the validateNumericNullBool method in the MathTrig\Helpers class instead
*
* @param mixed $number * @param mixed $number
*/ */
public static function nullFalseTrueToNumber(&$number): void public static function nullFalseTrueToNumber(&$number): void

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Acos
{
/**
* ACOS.
*
* Returns the arccosine of a number.
*
* @param float $number Number
*
* @return float|string The arccosine of the number
*/
public static function funcAcos($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(acos($number));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Acosh
{
/**
* ACOSH.
*
* Returns the arc hyperbolic cosine of a number.
*
* @param float $number Number
*
* @return float|string The arccosine of the number
*/
public static function funcAcosh($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(acosh($number));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Acot
{
/**
* ACOT.
*
* Returns the arccotangent of a number.
*
* @param float $number Number
*
* @return float|string The arccotangent of the number
*/
public static function funcAcot($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return (M_PI / 2) - atan($number);
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Acoth
{
/**
* ACOTH.
*
* Returns the hyperbolic arccotangent of a number.
*
* @param float $number Number
*
* @return float|string The hyperbolic arccotangent of the number
*/
public static function funcAcoth($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
$result = ($number === 1) ? NAN : (log(($number + 1) / ($number - 1)) / 2);
return Helpers::numberOrNan($result);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Asin
{
/**
* ASIN.
*
* Returns the arcsine of a number.
*
* @param float $number Number
*
* @return float|string The arcsine of the number
*/
public static function funcAsin($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(asin($number));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Asinh
{
/**
* ASINH.
*
* Returns the arc hyperbolic sine of a number.
*
* @param float $number Number
*
* @return float|string The arc hyperbolic sine of the number
*/
public static function funcAsinh($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(asinh($number));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Atan
{
/**
* ATAN.
*
* Returns the arctangent of a number.
*
* @param float $number Number
*
* @return float|string The arctangent of the number
*/
public static function funcAtan($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(atan($number));
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Atan2
{
/**
* ATAN2.
*
* This function calculates the arc tangent of the two variables x and y. It is similar to
* calculating the arc tangent of y ÷ x, except that the signs of both arguments are used
* to determine the quadrant of the result.
* The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a
* point with coordinates (xCoordinate, yCoordinate). The angle is given in radians between
* -pi and pi, excluding -pi.
*
* Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard
* PHP atan2() function, so we need to reverse them here before calling the PHP atan() function.
*
* Excel Function:
* ATAN2(xCoordinate,yCoordinate)
*
* @param mixed $xCoordinate should be float, the x-coordinate of the point
* @param mixed $yCoordinate should be float, the y-coordinate of the point
*
* @return float|string the inverse tangent of the specified x- and y-coordinates, or a string containing an error
*/
public static function funcAtan2($xCoordinate, $yCoordinate)
{
try {
$xCoordinate = Helpers::validateNumericNullBool($xCoordinate);
$yCoordinate = Helpers::validateNumericNullBool($yCoordinate);
} catch (Exception $e) {
return $e->getMessage();
}
if (($xCoordinate == 0) && ($yCoordinate == 0)) {
return Functions::DIV0();
}
return atan2($yCoordinate, $xCoordinate);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Atanh
{
/**
* ATANH.
*
* Returns the arc hyperbolic tangent of a number.
*
* @param float $number Number
*
* @return float|string The arc hyperbolic tangent of the number
*/
public static function funcAtanh($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::numberOrNan(atanh($number));
}
}

View File

@ -4,7 +4,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class Ceiling class Ceiling
{ {
@ -26,21 +25,20 @@ class Ceiling
*/ */
public static function funcCeiling($number, $significance = null) public static function funcCeiling($number, $significance = null)
{ {
MathTrig::nullFalseTrueToNumber($number);
$significance = Functions::flattenSingleValue($significance);
if ($significance === null) { if ($significance === null) {
self::floorCheck1Arg(); self::floorCheck1Arg();
$significance = ((float) $number < 0) ? -1 : 1;
} }
if ((is_numeric($number)) && (is_numeric($significance))) { try {
$number = Helpers::validateNumericNullBool($number);
$significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1);
} catch (Exception $e) {
return $e->getMessage();
}
return self::argumentsOk((float) $number, (float) $significance); return self::argumentsOk((float) $number, (float) $significance);
} }
return Functions::VALUE();
}
/** /**
* Avoid Scrutinizer problems concerning complexity. * Avoid Scrutinizer problems concerning complexity.
* *
@ -51,7 +49,7 @@ class Ceiling
if (empty($number * $significance)) { if (empty($number * $significance)) {
return 0.0; return 0.0;
} }
if (MathTrig::returnSign($number) == MathTrig::returnSign($significance)) { if (Helpers::returnSign($number) == Helpers::returnSign($significance)) {
return ceil($number / $significance) * $significance; return ceil($number / $significance) * $significance;
} }

View File

@ -2,8 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class CeilingMath class CeilingMath
{ {
@ -23,15 +22,14 @@ class CeilingMath
*/ */
public static function funcCeilingMath($number, $significance = null, $mode = 0) public static function funcCeilingMath($number, $significance = null, $mode = 0)
{ {
MathTrig::nullFalseTrueToNumber($number); try {
$significance = Functions::flattenSingleValue($significance); $number = Helpers::validateNumericNullBool($number);
$mode = Functions::flattenSingleValue($mode); $significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1);
$mode = Helpers::validateNumericNullSubstitution($mode, null);
if ($significance === null) { } catch (Exception $e) {
$significance = ((float) $number < 0) ? -1 : 1; return $e->getMessage();
} }
if (is_numeric($number) && is_numeric($significance) && is_numeric($mode)) {
if (empty($significance * $number)) { if (empty($significance * $number)) {
return 0.0; return 0.0;
} }
@ -42,9 +40,6 @@ class CeilingMath
return ceil($number / $significance) * $significance; return ceil($number / $significance) * $significance;
} }
return Functions::VALUE();
}
/** /**
* Let CEILINGMATH complexity pass Scrutinizer. * Let CEILINGMATH complexity pass Scrutinizer.
*/ */

View File

@ -2,8 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class CeilingPrecise class CeilingPrecise
{ {
@ -22,18 +21,18 @@ class CeilingPrecise
*/ */
public static function funcCeilingPrecise($number, $significance = 1) public static function funcCeilingPrecise($number, $significance = 1)
{ {
MathTrig::nullFalseTrueToNumber($number); try {
$significance = Functions::flattenSingleValue($significance); $number = Helpers::validateNumericNullBool($number);
$significance = Helpers::validateNumericNullSubstitution($significance, null);
} catch (Exception $e) {
return $e->getMessage();
}
if ((is_numeric($number)) && (is_numeric($significance))) { if (!$significance) {
if ($significance == 0.0) {
return 0.0; return 0.0;
} }
$result = $number / abs($significance); $result = $number / abs($significance);
return ceil($result) * $significance * (($significance < 0) ? -1 : 1); return ceil($result) * $significance * (($significance < 0) ? -1 : 1);
} }
return Functions::VALUE();
}
} }

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Cos
{
/**
* COS.
*
* Returns the result of builtin function cos after validating args.
*
* @param mixed $number Should be numeric
*
* @return float|string cosine
*/
public static function funcCos($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return cos($number);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Cosh
{
/**
* COSH.
*
* Returns the result of builtin function cosh after validating args.
*
* @param mixed $number Should be numeric
*
* @return float|string cosine
*/
public static function funcCosh($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return cosh($number);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Cot
{
/**
* COT.
*
* Returns the cotangent of an angle.
*
* @param float $angle Number
*
* @return float|string The cotangent of the angle
*/
public static function funcCot($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(cos($angle), sin($angle));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Coth
{
/**
* COTH.
*
* Returns the hyperbolic cotangent of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic cotangent of the angle
*/
public static function funcCoth($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, tanh($angle));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Csc
{
/**
* CSC.
*
* Returns the cosecant of an angle.
*
* @param float $angle Number
*
* @return float|string The cosecant of the angle
*/
public static function funcCsc($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, sin($angle));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Csch
{
/**
* CSCH.
*
* Returns the hyperbolic cosecant of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic cosecant of the angle
*/
public static function funcCsch($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, sinh($angle));
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Even
{
/**
* EVEN.
*
* Returns number rounded up to the nearest even integer.
* You can use this function for processing items that come in twos. For example,
* a packing crate accepts rows of one or two items. The crate is full when
* the number of items, rounded up to the nearest two, matches the crate's
* capacity.
*
* Excel Function:
* EVEN(number)
*
* @param float $number Number to round
*
* @return float|string Rounded Number, or a string containing an error
*/
public static function funcEven($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::getEven($number);
}
}

View File

@ -4,7 +4,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class Floor class Floor
{ {
@ -31,21 +30,20 @@ class Floor
*/ */
public static function funcFloor($number, $significance = null) public static function funcFloor($number, $significance = null)
{ {
MathTrig::nullFalseTrueToNumber($number);
$significance = Functions::flattenSingleValue($significance);
if ($significance === null) { if ($significance === null) {
self::floorCheck1Arg(); self::floorCheck1Arg();
$significance = MathTrig::returnSign((float) $number);
} }
if ((is_numeric($number)) && (is_numeric($significance))) { try {
$number = Helpers::validateNumericNullBool($number);
$significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1);
} catch (Exception $e) {
return $e->getMessage();
}
return self::argumentsOk((float) $number, (float) $significance); return self::argumentsOk((float) $number, (float) $significance);
} }
return Functions::VALUE();
}
/** /**
* Avoid Scrutinizer problems concerning complexity. * Avoid Scrutinizer problems concerning complexity.
* *
@ -59,10 +57,10 @@ class Floor
if ($number == 0.0) { if ($number == 0.0) {
return 0.0; return 0.0;
} }
if (MathTrig::returnSign($significance) == 1) { if (Helpers::returnSign($significance) == 1) {
return floor($number / $significance) * $significance; return floor($number / $significance) * $significance;
} }
if (MathTrig::returnSign($number) == -1 && MathTrig::returnSign($significance) == -1) { if (Helpers::returnSign($number) == -1 && Helpers::returnSign($significance) == -1) {
return floor($number / $significance) * $significance; return floor($number / $significance) * $significance;
} }

View File

@ -2,8 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class FloorMath class FloorMath
{ {
@ -23,21 +23,17 @@ class FloorMath
*/ */
public static function funcFloorMath($number, $significance = null, $mode = 0) public static function funcFloorMath($number, $significance = null, $mode = 0)
{ {
MathTrig::nullFalseTrueToNumber($number); try {
$significance = Functions::flattenSingleValue($significance); $number = Helpers::validateNumericNullBool($number);
$mode = Functions::flattenSingleValue($mode); $significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1);
$mode = Helpers::validateNumericNullSubstitution($mode, null);
if ($significance === null) { } catch (Exception $e) {
$significance = ((float) $number < 0) ? -1 : 1; return $e->getMessage();
} }
if (is_numeric($number) && is_numeric($significance) && is_numeric($mode)) {
return self::argsOk((float) $number, (float) $significance, (int) $mode); return self::argsOk((float) $number, (float) $significance, (int) $mode);
} }
return Functions::VALUE();
}
/** /**
* Avoid Scrutinizer complexity problems. * Avoid Scrutinizer complexity problems.
* *
@ -63,6 +59,6 @@ class FloorMath
*/ */
private static function floorMathTest(float $number, float $significance, int $mode): bool private static function floorMathTest(float $number, float $significance, int $mode): bool
{ {
return mathTrig::returnSign($significance) == -1 || (mathTrig::returnSign($number) == -1 && !empty($mode)); return Helpers::returnSign($significance) == -1 || (Helpers::returnSign($number) == -1 && !empty($mode));
} }
} }

View File

@ -2,8 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class FloorPrecise class FloorPrecise
{ {
@ -22,14 +22,14 @@ class FloorPrecise
*/ */
public static function funcFloorPrecise($number, $significance = 1) public static function funcFloorPrecise($number, $significance = 1)
{ {
MathTrig::nullFalseTrueToNumber($number); try {
$significance = Functions::flattenSingleValue($significance); $number = Helpers::validateNumericNullBool($number);
$significance = Helpers::validateNumericNullSubstitution($significance, null);
if ((is_numeric($number)) && (is_numeric($significance))) { } catch (Exception $e) {
return self::argumentsOk((float) $number, (float) $significance); return $e->getMessage();
} }
return Functions::VALUE(); return self::argumentsOk((float) $number, (float) $significance);
} }
/** /**

View File

@ -0,0 +1,87 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Helpers
{
/**
* Many functions accept null/false/true argument treated as 0/0/1.
*
* @return float|string quotient or DIV0 if denominator is too small
*/
public static function verySmallDenominator(float $numerator, float $denominator)
{
return (abs($denominator) < 1.0E-12) ? Functions::DIV0() : ($numerator / $denominator);
}
/**
* Many functions accept null/false/true argument treated as 0/0/1.
*
* @param mixed $number
*
* @return float|int
*/
public static function validateNumericNullBool($number)
{
$number = Functions::flattenSingleValue($number);
if ($number === null) {
return 0;
}
if (is_bool($number)) {
return (int) $number;
}
if (is_numeric($number)) {
return $number;
}
throw new Exception(Functions::VALUE());
}
/**
* Validate numeric, but allow substitute for null.
*
* @param mixed $number
* @param null|float|int $substitute
*
* @return float|int
*/
public static function validateNumericNullSubstitution($number, $substitute)
{
$number = Functions::flattenSingleValue($number);
if ($number === null && $substitute !== null) {
return $substitute;
}
if (is_numeric($number)) {
return $number;
}
throw new Exception(Functions::VALUE());
}
public static function returnSign(float $number): int
{
return $number ? (($number > 0) ? 1 : -1) : 0;
}
public static function getEven(float $number): float
{
$significance = 2 * self::returnSign($number);
return $significance ? (ceil($number / $significance) * $significance) : 0;
}
/**
* Return NAN or value depending on argument.
*
* @param float $result Number
*
* @return float|string
*/
public static function numberOrNan($result)
{
return is_nan($result) ? Functions::NAN() : $result;
}
}

View File

@ -2,8 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class IntClass class IntClass
{ {
@ -21,11 +20,12 @@ class IntClass
*/ */
public static function funcInt($number) public static function funcInt($number)
{ {
MathTrig::nullFalseTrueToNumber($number); try {
if (is_numeric($number)) { $number = Helpers::validateNumericNullBool($number);
return (int) floor($number); } catch (Exception $e) {
return $e->getMessage();
} }
return Functions::VALUE(); return (int) floor($number);
} }
} }

View File

@ -2,8 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class Mround class Mround
{ {
@ -19,16 +19,17 @@ class Mround
*/ */
public static function funcMround($number, $multiple) public static function funcMround($number, $multiple)
{ {
$number = Functions::flattenSingleValue($number); try {
$number = $number ?? 0; $number = Helpers::validateNumericNullSubstitution($number, 0);
$multiple = Helpers::validateNumericNullSubstitution($multiple, null);
} catch (Exception $e) {
return $e->getMessage();
}
$multiple = Functions::flattenSingleValue($multiple);
if ((is_numeric($number)) && (is_numeric($multiple))) {
if ($number == 0 || $multiple == 0) { if ($number == 0 || $multiple == 0) {
return 0; return 0;
} }
if ((MathTrig::SIGN($number)) == (MathTrig::SIGN($multiple))) { if ((Helpers::returnSign($number)) == (Helpers::returnSign($multiple))) {
$multiplier = 1 / $multiple; $multiplier = 1 / $multiple;
return round($number * $multiplier) / $multiplier; return round($number * $multiplier) / $multiplier;
@ -36,7 +37,4 @@ class Mround
return Functions::NAN(); return Functions::NAN();
} }
return Functions::VALUE();
}
} }

View File

@ -0,0 +1,38 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Odd
{
/**
* ODD.
*
* Returns number rounded up to the nearest odd integer.
*
* @param float $number Number to round
*
* @return float|string Rounded Number, or a string containing an error
*/
public static function funcOdd($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
$significance = Helpers::returnSign($number);
if ($significance == 0) {
return 1;
}
$result = ceil($number / $significance) * $significance;
if ($result == Helpers::getEven($result)) {
$result += $significance;
}
return $result;
}
}

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Roman class Roman
@ -823,31 +824,16 @@ class Roman
*/ */
public static function funcRoman($aValue, $style = 0) public static function funcRoman($aValue, $style = 0)
{ {
$aValue = Functions::flattenSingleValue($aValue); try {
self::nullFalseTrueToNumber($aValue); $aValue = Helpers::validateNumericNullBool($aValue);
$style = Functions::flattenSingleValue($style);
if (is_bool($style)) { if (is_bool($style)) {
$style = $style ? 0 : 4; $style = $style ? 0 : 4;
} }
if (!is_numeric($aValue) || !is_numeric($style)) { $style = Helpers::validateNumericNullSubstitution($style, null);
return Functions::VALUE(); } catch (Exception $e) {
return $e->getMessage();
} }
return self::calculateRoman((int) $aValue, (int) $style); return self::calculateRoman((int) $aValue, (int) $style);
} }
/**
* Many functions accept null/false/true argument treated as 0/0/1.
*
* @param mixed $number
*/
private static function nullFalseTrueToNumber(&$number): void
{
$number = Functions::flattenSingleValue($number);
if ($number === null) {
$number = 0;
} elseif (is_bool($number)) {
$number = (int) $number;
}
}
} }

View File

@ -2,8 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class Round class Round
{ {
@ -19,12 +18,13 @@ class Round
*/ */
public static function builtinROUND($number, $precision) public static function builtinROUND($number, $precision)
{ {
MathTrig::nullFalseTrueToNumber($number); try {
$number = Helpers::validateNumericNullBool($number);
if (!is_numeric($number) || !is_numeric($precision)) { $precision = Helpers::validateNumericNullBool($precision);
return Functions::VALUE(); } catch (Exception $e) {
return $e->getMessage();
} }
return round($number, $precision); return round($number, (int) $precision);
} }
} }

View File

@ -2,8 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class RoundDown class RoundDown
{ {
@ -19,10 +18,13 @@ class RoundDown
*/ */
public static function funcRoundDown($number, $digits) public static function funcRoundDown($number, $digits)
{ {
MathTrig::nullFalseTrueToNumber($number); try {
$digits = Functions::flattenSingleValue($digits); $number = Helpers::validateNumericNullBool($number);
$digits = Helpers::validateNumericNullSubstitution($digits, null);
} catch (Exception $e) {
return $e->getMessage();
}
if ((is_numeric($number)) && (is_numeric($digits))) {
if ($number == 0.0) { if ($number == 0.0) {
return 0.0; return 0.0;
} }
@ -33,7 +35,4 @@ class RoundDown
return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP); return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
} }
return Functions::VALUE();
}
} }

View File

@ -2,8 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class RoundUp class RoundUp
{ {
@ -19,10 +18,13 @@ class RoundUp
*/ */
public static function funcRoundUp($number, $digits) public static function funcRoundUp($number, $digits)
{ {
MathTrig::nullFalseTrueToNumber($number); try {
$digits = Functions::flattenSingleValue($digits); $number = Helpers::validateNumericNullBool($number);
$digits = Helpers::validateNumericNullSubstitution($digits, null);
} catch (Exception $e) {
return $e->getMessage();
}
if ((is_numeric($number)) && (is_numeric($digits))) {
if ($number == 0.0) { if ($number == 0.0) {
return 0.0; return 0.0;
} }
@ -33,7 +35,4 @@ class RoundUp
return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN); return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
} }
return Functions::VALUE();
}
} }

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Sec
{
/**
* SEC.
*
* Returns the secant of an angle.
*
* @param float $angle Number
*
* @return float|string The secant of the angle
*/
public static function funcSec($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, cos($angle));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Sech
{
/**
* SECH.
*
* Returns the hyperbolic secant of an angle.
*
* @param float $angle Number
*
* @return float|string The hyperbolic secant of the angle
*/
public static function funcSech($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(1.0, cosh($angle));
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Sign
{
/**
* SIGN.
*
* Determines the sign of a number. Returns 1 if the number is positive, zero (0)
* if the number is 0, and -1 if the number is negative.
*
* @param float $number Number to round
*
* @return int|string sign value, or a string containing an error
*/
public static function funcSign($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::returnSign($number);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Sin
{
/**
* SIN.
*
* Returns the result of builtin function sin after validating args.
*
* @param mixed $angle Should be numeric
*
* @return float|string Rounded number
*/
public static function funcSin($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return sin($angle);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Sinh
{
/**
* SINH.
*
* Returns the result of builtin function sinh after validating args.
*
* @param mixed $angle Should be numeric
*
* @return float|string Rounded number
*/
public static function funcSinh($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return sinh($angle);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Tan
{
/**
* TAN.
*
* Returns the result of builtin function tan after validating args.
*
* @param mixed $angle Should be numeric
*
* @return float|string Rounded number
*/
public static function funcTan($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return Helpers::verySmallDenominator(sin($angle), cos($angle));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Exception;
class Tanh
{
/**
* TANH.
*
* Returns the result of builtin function sinh after validating args.
*
* @param mixed $angle Should be numeric
*
* @return float|string Rounded number
*/
public static function funcTanh($angle)
{
try {
$angle = Helpers::validateNumericNullBool($angle);
} catch (Exception $e) {
return $e->getMessage();
}
return tanh($angle);
}
}

View File

@ -2,8 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class Trunc class Trunc
{ {
@ -19,13 +18,13 @@ class Trunc
*/ */
public static function funcTrunc($value = 0, $digits = 0) public static function funcTrunc($value = 0, $digits = 0)
{ {
MathTrig::nullFalseTrueToNumber($value); try {
$digits = Functions::flattenSingleValue($digits); $value = Helpers::validateNumericNullBool($value);
$digits = Helpers::validateNumericNullSubstitution($digits, null);
// Validate parameters } catch (Exception $e) {
if ((!is_numeric($value)) || (!is_numeric($digits))) { return $e->getMessage();
return Functions::VALUE();
} }
$digits = floor($digits); $digits = floor($digits);
// Truncate // Truncate

View File

@ -12,19 +12,16 @@ class AcosTest extends TestCase
* @dataProvider providerAcos * @dataProvider providerAcos
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testAcos($expectedResult, $val = null): void public function testAcos($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=ACOS()';
} else {
$formula = "=ACOS($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ACOS($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -12,19 +12,16 @@ class AcoshTest extends TestCase
* @dataProvider providerAcosh * @dataProvider providerAcosh
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testAcosh($expectedResult, $val = null): void public function testAcosh($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=ACOSH()';
} else {
$formula = "=ACOSH($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->getCell('A2')->setValue('1.5');
$sheet->getCell('A1')->setValue("=ACOSH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class AcotTest extends TestCase class AcotTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerACOT * @dataProvider providerACOT
* *
@ -21,8 +16,18 @@ class AcotTest extends TestCase
*/ */
public function testACOT($expectedResult, $number): void public function testACOT($expectedResult, $number): void
{ {
$result = MathTrig::ACOT($number); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5);
$sheet->getCell('A1')->setValue("=ACOT($number)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerACOT() public function providerACOT()

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class AcothTest extends TestCase class AcothTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerACOTH * @dataProvider providerACOTH
* *
@ -21,8 +16,18 @@ class AcothTest extends TestCase
*/ */
public function testACOTH($expectedResult, $number): void public function testACOTH($expectedResult, $number): void
{ {
$result = MathTrig::ACOTH($number); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -10);
$sheet->getCell('A1')->setValue("=ACOTH($number)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerACOTH() public function providerACOTH()

View File

@ -12,19 +12,16 @@ class AsinTest extends TestCase
* @dataProvider providerAsin * @dataProvider providerAsin
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testAsin($expectedResult, $val = null): void public function testAsin($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=ASIN()';
} else {
$formula = "=ASIN($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ASIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -12,19 +12,16 @@ class AsinhTest extends TestCase
* @dataProvider providerAsinh * @dataProvider providerAsinh
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testAsinh($expectedResult, $val = null): void public function testAsinh($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=ASINH()';
} else {
$formula = "=ASINH($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ASINH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -2,28 +2,29 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Atan2Test extends TestCase class Atan2Test extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerATAN2 * @dataProvider providerATAN2
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $x
* @param mixed $y
*/ */
public function testATAN2($expectedResult, $x, $y): void public function testATAN2($expectedResult, string $formula): void
{ {
$result = MathTrig::ATAN2($x, $y); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A2')->setValue(5);
$sheet->getCell('A3')->setValue(6);
$sheet->getCell('A1')->setValue("=ATAN2($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerATAN2() public function providerATAN2()

View File

@ -12,19 +12,16 @@ class AtanTest extends TestCase
* @dataProvider providerAtan * @dataProvider providerAtan
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testAtan($expectedResult, $val = null): void public function testAtan($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=ATAN()';
} else {
$formula = "=ATAN($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->getCell('A2')->setValue(5);
$sheet->getCell('A1')->setValue("=ATAN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -12,19 +12,16 @@ class AtanhTest extends TestCase
* @dataProvider providerAtanh * @dataProvider providerAtanh
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testAtan($expectedResult, $val = null): void public function testAtanh($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=ATANH()';
} else {
$formula = "=ATANH($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->getCell('A2')->setValue(0.8);
$sheet->getCell('A1')->setValue("=ATANH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -12,19 +12,16 @@ class CosTest extends TestCase
* @dataProvider providerCos * @dataProvider providerCos
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testCos($expectedResult, $val = null): void public function testCos($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=COS()';
} else {
$formula = "=COS($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=COS($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -12,19 +12,16 @@ class CoshTest extends TestCase
* @dataProvider providerCosh * @dataProvider providerCosh
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testCosh($expectedResult, $val = null): void public function testCosh($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=COSH()';
} else {
$formula = "=COSH($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=COSH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CotTest extends TestCase class CotTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerCOT * @dataProvider providerCOT
* *
@ -21,8 +16,18 @@ class CotTest extends TestCase
*/ */
public function testCOT($expectedResult, $angle): void public function testCOT($expectedResult, $angle): void
{ {
$result = MathTrig::COT($angle); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=COT($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerCOT() public function providerCOT()

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CothTest extends TestCase class CothTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerCOTH * @dataProvider providerCOTH
* *
@ -21,8 +16,18 @@ class CothTest extends TestCase
*/ */
public function testCOTH($expectedResult, $angle): void public function testCOTH($expectedResult, $angle): void
{ {
$result = MathTrig::COTH($angle); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=COTH($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerCOTH() public function providerCOTH()

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CscTest extends TestCase class CscTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerCSC * @dataProvider providerCSC
* *
@ -21,8 +16,18 @@ class CscTest extends TestCase
*/ */
public function testCSC($expectedResult, $angle): void public function testCSC($expectedResult, $angle): void
{ {
$result = MathTrig::CSC($angle); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=CSC($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerCSC() public function providerCSC()

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CschTest extends TestCase class CschTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerCSCH * @dataProvider providerCSCH
* *
@ -21,8 +16,18 @@ class CschTest extends TestCase
*/ */
public function testCSCH($expectedResult, $angle): void public function testCSCH($expectedResult, $angle): void
{ {
$result = MathTrig::CSCH($angle); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=CSCH($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerCSCH() public function providerCSCH()

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class EvenTest extends TestCase class EvenTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerEVEN * @dataProvider providerEVEN
* *
@ -21,8 +16,14 @@ class EvenTest extends TestCase
*/ */
public function testEVEN($expectedResult, $value): void public function testEVEN($expectedResult, $value): void
{ {
$result = MathTrig::EVEN($value); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue("=EVEN($value)");
$sheet->getCell('A2')->setValue(3.7);
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
} }
public function providerEVEN() public function providerEVEN()

View File

@ -16,15 +16,47 @@ class MovedFunctionsTest extends TestCase
{ {
public function testMovedFunctions(): void public function testMovedFunctions(): void
{ {
self::assertEqualsWithDelta(0, MathTrig::builtinACOS(1), 1E-9);
self::assertEqualsWithDelta(0, MathTrig::builtinACOSH(1), 1E-9);
self::assertEqualsWithDelta(3.04192400109863, MathTrig::ACOT(-10), 1E-9);
self::assertEqualsWithDelta(-0.20273255405408, MathTrig::ACOTH(-5), 1E-9);
self::assertEqualsWithDelta(0, MathTrig::builtinASIN(0), 1E-9);
self::assertEqualsWithDelta(0, MathTrig::builtinASINH(0), 1E-9);
self::assertEqualsWithDelta(0, MathTrig::builtinATAN(0), 1E-9);
self::assertEqualsWithDelta(0, MathTrig::builtinATANH(0), 1E-9);
self::assertEqualsWithDelta('#DIV/0!', MathTrig::ATAN2(0, 0), 1E-9);
self::assertEquals(-6, MathTrig::CEILING(-4.5, -2)); self::assertEquals(-6, MathTrig::CEILING(-4.5, -2));
self::assertEquals(1, MathTrig::builtinCOS(0));
self::assertEquals(1, MathTrig::builtinCOSH(0));
self::assertEquals('#DIV/0!', MathTrig::COT(0));
self::assertEquals('#DIV/0!', MathTrig::COTH(0));
self::assertEquals('#DIV/0!', MathTrig::CSC(0));
self::assertEquals('#DIV/0!', MathTrig::CSCH(0));
self::assertEquals(6, MathTrig::EVEN(4.5));
self::assertEquals(-6, MathTrig::FLOOR(-4.5, 2)); self::assertEquals(-6, MathTrig::FLOOR(-4.5, 2));
self::assertEquals(0.23, MathTrig::FLOORMATH(0.234, 0.01)); self::assertEquals(0.23, MathTrig::FLOORMATH(0.234, 0.01));
self::assertEquals(-4, MathTrig::FLOORPRECISE(-2.5, 2)); self::assertEquals(-4, MathTrig::FLOORPRECISE(-2.5, 2));
self::assertEquals(-9, MathTrig::INT(-8.3)); self::assertEquals(-9, MathTrig::INT(-8.3));
self::assertEquals(6, MathTrig::MROUND(7.3, 3)); self::assertEquals(6, MathTrig::MROUND(7.3, 3));
self::assertEquals(5, MathTrig::ODD(4.5));
self::assertEquals(3.3, MathTrig::builtinROUND(3.27, 1)); self::assertEquals(3.3, MathTrig::builtinROUND(3.27, 1));
self::assertEquals(662, MathTrig::ROUNDDOWN(662.79, 0)); self::assertEquals(662, MathTrig::ROUNDDOWN(662.79, 0));
self::assertEquals(663, MathTrig::ROUNDUP(662.79, 0)); self::assertEquals(663, MathTrig::ROUNDUP(662.79, 0));
self::assertEquals(1, MathTrig::SEC(0));
self::assertEquals(1, MathTrig::SECH(0));
self::assertEquals(1, MathTrig::SIGN(79.2));
self::assertEquals(0, MathTrig::builtinSIN(0));
self::assertEquals(0, MathTrig::builtinSINH(0));
self::assertEquals(0, MathTrig::builtinTAN(0));
self::assertEquals(0, MathTrig::builtinTANH(0));
self::assertEquals(70, MathTrig::TRUNC(79.2, -1)); self::assertEquals(70, MathTrig::TRUNC(79.2, -1));
self::assertEquals(1, MathTrig::returnSign(79.2));
self::assertEquals(80, MathTrig::getEven(79.2));
$nullVal = null;
MathTrig::nullFalseTrueToNumber($nullVal);
self::assertSame(0, $nullVal);
$nullVal = true;
MathTrig::nullFalseTrueToNumber($nullVal);
self::assertSame(1, $nullVal);
} }
} }

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class OddTest extends TestCase class OddTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerODD * @dataProvider providerODD
* *
@ -21,8 +16,14 @@ class OddTest extends TestCase
*/ */
public function testODD($expectedResult, $value): void public function testODD($expectedResult, $value): void
{ {
$result = MathTrig::ODD($value); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue("=ODD($value)");
$sheet->getCell('A2')->setValue(3.7);
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
} }
public function providerODD() public function providerODD()

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SecTest extends TestCase class SecTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerSEC * @dataProvider providerSEC
* *
@ -21,8 +16,18 @@ class SecTest extends TestCase
*/ */
public function testSEC($expectedResult, $angle): void public function testSEC($expectedResult, $angle): void
{ {
$result = MathTrig::SEC($angle); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=SEC($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerSEC() public function providerSEC()

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SechTest extends TestCase class SechTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerSECH * @dataProvider providerSECH
* *
@ -21,8 +16,18 @@ class SechTest extends TestCase
*/ */
public function testSECH($expectedResult, $angle): void public function testSECH($expectedResult, $angle): void
{ {
$result = MathTrig::SECH($angle); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=SECH($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
} }
public function providerSECH() public function providerSECH()

View File

@ -2,17 +2,12 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SignTest extends TestCase class SignTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/** /**
* @dataProvider providerSIGN * @dataProvider providerSIGN
* *
@ -21,8 +16,17 @@ class SignTest extends TestCase
*/ */
public function testSIGN($expectedResult, $value): void public function testSIGN($expectedResult, $value): void
{ {
$result = MathTrig::SIGN($value); if ($expectedResult === 'exception') {
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); $this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 0);
$sheet->setCellValue('A4', -3.8);
$sheet->getCell('A1')->setValue("=SIGN($value)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
} }
public function providerSIGN() public function providerSIGN()

View File

@ -12,19 +12,16 @@ class SinTest extends TestCase
* @dataProvider providerSin * @dataProvider providerSin
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testSin($expectedResult, $val = null): void public function testSin($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=SIN()';
} else {
$formula = "=SIN($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=SIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -12,19 +12,16 @@ class SinhTest extends TestCase
* @dataProvider providerCosh * @dataProvider providerCosh
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testSinh($expectedResult, $val = null): void public function testSinh($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=SINH()';
} else {
$formula = "=SINH($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=SINH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -12,19 +12,16 @@ class TanTest extends TestCase
* @dataProvider providerTan * @dataProvider providerTan
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testTan($expectedResult, $val = null): void public function testTan($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=TAN()';
} else {
$formula = "=TAN($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->setCellValue('A2', 1);
$sheet->getCell('A1')->setValue("=TAN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -12,19 +12,16 @@ class TanhTest extends TestCase
* @dataProvider providerTanh * @dataProvider providerTanh
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $val
*/ */
public function testTanh($expectedResult, $val = null): void public function testTanh($expectedResult, string $formula): void
{ {
if ($val === null) { if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class); $this->expectException(CalcExp::class);
$formula = '=TANH()';
} else {
$formula = "=TANH($val)";
} }
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula); $sheet->setCellValue('A2', 1);
$sheet->getCell('A1')->setValue("=TANH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue(); $result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6); self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
} }

View File

@ -1,10 +1,14 @@
<?php <?php
return [ return [
['#VALUE!'], // exception - not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[1.570796, 0], [M_PI_2, '0'],
[3.141593, -1], [M_PI, '"-1"'],
[0, 1], [0, '1'],
['#NUM!', 2], ['#NUM!', '2'],
[M_PI_2, 'Q15'],
[M_PI_2, 'false'],
[0, 'true'],
[1.047197551, 'A2'],
]; ];

View File

@ -1,10 +1,14 @@
<?php <?php
return [ return [
['#VALUE!'], // exception - not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[1.316958, 2], [1.316958, '2'],
[0, 1], [0, '1'],
['#NUM!', 0], ['#NUM!', '0'],
['#NUM!', -1], ['#NUM!', '-1'],
['#NUM!', 'Q15'],
['#NUM!', 'false'],
[0, 'true'],
[0.96242365, 'A2'],
]; ];

View File

@ -1,60 +1,23 @@
<?php <?php
return [ return [
[ ['#VALUE!', '"ABC"'],
'#VALUE!', [3.04192400109863, -10],
'ABC', [2.98376146330163, '-PI() * 2'],
], [2.94419709373991, '"-5"'],
[ [2.83342358247381, '-PI()'],
3.04192400109863, [2.57468114864878, '-PI() / 2'],
-10, [1.67046497928606, -0.1],
], [1.57079632679490, 0.0],
[ [1.47112767430373, 0.1],
2.98376146330163, [0.56691150494101, 'PI() / 2'],
-M_PI * 2, [0.30816907111599, 'PI()'],
], [0.19739555984988, 5],
[ [0.15783119028816, 'PI() * 2'],
2.94419709373991, [0.09966865249116, 10],
-5, [1.57079632679490, 'Q15'],
], [1.57079632679490, 'null'],
[ [1.57079632679490, 'false'],
2.83342358247381, [0.785398163, 'true'],
-M_PI, [2.94419709373991, 'A5'],
],
[
2.57468114864878,
-M_PI / 2,
],
[
1.67046497928606,
-0.1,
],
[
1.57079632679490,
0.0,
],
[
1.47112767430373,
0.1,
],
[
0.56691150494101,
M_PI / 2,
],
[
0.30816907111599,
M_PI,
],
[
0.19739555984988,
5,
],
[
0.15783119028816,
M_PI * 2,
],
[
0.09966865249116,
10,
],
]; ];

View File

@ -1,60 +1,23 @@
<?php <?php
return [ return [
[ ['#VALUE!', '"ABC"'],
'#VALUE!', [-0.10033534773108, -10],
'ABC', [-0.16051955750789, '-PI() * 2'],
], [-0.20273255405408, '"-5"'],
[ [-0.32976531495670, '-PI()'],
-0.10033534773108, [-0.75246926714193, '-PI() / 2'],
-10, ['#NUM!', -0.1],
], ['#NUM!', 0.0],
[ ['#NUM!', 0.1],
-0.16051955750789, [0.75246926714193, 'PI() / 2'],
-M_PI * 2, [0.32976531495670, 'PI()'],
], [0.20273255405408, 5],
[ [0.16051955750789, 'PI() * 2'],
-0.20273255405408, [0.10033534773108, 10],
-5, ['#NUM!', 'Q15'],
], ['#NUM!', 'null'],
[ ['#NUM!', 'false'],
-0.32976531495670, ['#NUM!', 'true'],
-M_PI, [-0.10033534773108, 'A5'],
],
[
-0.75246926714193,
-M_PI / 2,
],
[
'#NUM!',
-0.1,
],
[
'#NUM!',
0.0,
],
[
'#NUM!',
0.1,
],
[
0.75246926714193,
M_PI / 2,
],
[
0.32976531495670,
M_PI,
],
[
0.20273255405408,
5,
],
[
0.16051955750789,
M_PI * 2,
],
[
0.10033534773108,
10,
],
]; ];

View File

@ -1,10 +1,14 @@
<?php <?php
return [ return [
['#VALUE!'], // exception - not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[1.570796, 1], [M_PI_2, '1'],
[-1.570796, -1], [-M_PI_2, '"-1"'],
[0, 0], [0, '0'],
['#NUM!', 2], ['#NUM!', '2'],
[0, 'Q15'],
[0, 'false'],
[M_PI_2, 'true'],
[0.523598776, 'A2'],
]; ];

View File

@ -1,12 +1,16 @@
<?php <?php
return [ return [
['#VALUE!'], // exception - not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[0, 0], [0, '0'],
[0.881374, 1], [0.881374, '1'],
[1.443635, 2], [1.443635, '"2"'],
[-0.881374, -1], [-0.881374, '-1'],
[14.508658, 1000000], [14.508658, '1000000'],
// ['#NUM!', 2], Don't know if NAN is possible // ['#NUM!', 2], Don't know if NAN is possible
[0, 'Q15'],
[0, 'false'],
[0.881373587, 'true'],
[0.481211825, 'A2'],
]; ];

View File

@ -1,12 +1,16 @@
<?php <?php
return [ return [
['#VALUE!'], // exception - not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[0, 0], [0, '0'],
[0.785398, 1], [M_PI / 4, '"1"'],
[1.107149, 2], [1.107149, '2'],
[-0.785398, -1], [-M_PI / 4, '-1'],
[1.570795, 1000000], [M_PI / 2, '10000000'],
// ['#NUM!', 2], Believe NAN is not possible // ['#NUM!', 2], Believe NAN is not possible
[0, 'Q15'],
[0, 'false'],
[M_PI / 4, 'true'],
[1.373400767, 'A2'],
]; ];

View File

@ -3,68 +3,24 @@
// x_num, y_num, Result // x_num, y_num, Result
return [ return [
[ ['#DIV/0!', '0, 0'],
'#DIV/0!', [M_PI_4, '1, 1'],
0, 0, [-3 * M_PI_4, '-1, -1'],
], [3 * M_PI_4, '-1, 1'],
[ [-M_PI_4, '1, -1'],
0.78539816339699997, [1.107148717, '0.5, 1'],
1, 1, [1.815774989, '-0.5, 2'],
], [0.674740942, '1, 0.8'],
[ [-0.643501109, '0.8, -0.6'],
-2.3561944901919998, [-1.460139105, '1, -9'],
-1, -1, [0.0, '0.2, 0'],
], [1.107148718, '0.1, 0.2'],
[ [M_PI_2, '0, 0.2'],
2.3561944901919998, ['#VALUE!', '"A", 0.2'],
-1, 1, ['#VALUE!', '0.2, "A"'],
], [M_PI_4, 'true, 1'],
[ [-M_PI_2, 'false, -2.5'],
-0.78539816339699997, ['exception', ''],
1, -1, ['exception', '1'],
], [0.876058051, 'A2, A3'],
[
1.107148717794,
0.5, 1,
],
[
1.8157749899219999,
-0.5, 2,
],
[
0.67474094222400005,
1, 0.80000000000000004,
],
[
-0.64350110879300004,
0.80000000000000004, -0.59999999999999998,
],
[
-1.460139105621,
1, -9,
],
[
0.0,
0.20000000000000001, 0,
],
[
1.107148717794,
0.10000000000000001, 0.20000000000000001,
],
[
1.570796326795,
0, 0.20000000000000001,
],
[
'#VALUE!',
'A', 0.20000000000000001,
],
[
0.78539816339699997,
true, 1,
],
[
-1.570796326795,
false, -2.5,
],
]; ];

View File

@ -1,11 +1,15 @@
<?php <?php
return [ return [
['#VALUE!'], // exception - not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[0, 0], [0, '0'],
[1.472219, 0.9], [1.472219, '"0.9"'],
[-1.472219, -0.9], [-1.472219, '-0.9'],
['#NUM!', 1], ['#NUM!', '1'],
['#NUM!', -1], ['#NUM!', '-1'],
[0, 'Q15'],
[0, 'false'],
['#NUM!', 'true'],
[1.098612289, 'A2'],
]; ];

View File

@ -1,12 +1,16 @@
<?php <?php
return [ return [
['#VALUE!'], // exception not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[1, 0], [1, '0'],
[0, M_PI / 2], [0, 'PI() / 2'],
[0.540302, 1.0], [0.540302306, '1.0'],
[0.540302, -1.0], [0.540302306, '-1.0'],
[-0.416147, 2.0], [-0.416146837, '2.0'],
[-0.416147, -2.0], [-0.416146837, '-2.0'],
[1, 'Q15'],
[1, 'false'],
[0.540302306, 'true'],
[-0.416146837, 'A2'],
]; ];

View File

@ -1,11 +1,11 @@
<?php <?php
return [ return [
['#VALUE!'], // exception not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[1, 0], [1, '0'],
[1.543081, 1], [1.543081, '"1"'],
[1.543081, -1.0], [1.543081, '-1.0'],
[3.762196, 2.0], [3.762196, '2.0'],
[11013.23292, 10], [11013.23292, '10'],
]; ];

View File

@ -1,52 +1,21 @@
<?php <?php
return [ return [
[ ['#VALUE!', '"ABC"'],
'#VALUE!', [-1.54235104535692, -10],
'ABC', [0.29581291553275, '"-5"'],
], [0.0, '-PI() / 2'],
[ [-9.96664442325924, -0.1],
-1.54235104535692, ['#DIV/0!', 0.0],
-10, ['#DIV/0!', 'PI()'],
], ['#DIV/0!', '-PI()'],
[ [9.96664442325924, 0.1],
0.29581291553275, [0.0, 'PI() / 2'],
-5, [-0.29581291553275, 5],
], [1.54235104535692, 10],
[ ['exception', ''],
0.0, ['#DIV/0!', 'Q15'],
-M_PI / 2, ['#DIV/0!', 'null'],
], ['#DIV/0!', 'false'],
[ [0.642092616, 'true'],
-9.96664442325924,
-0.1,
],
[
'#DIV/0!',
0.0,
],
[
'#DIV/0!',
M_PI,
],
[
'#DIV/0!',
-M_PI,
],
[
9.96664442325924,
0.1,
],
[
0.0,
M_PI / 2,
],
[
-0.29581291553275,
5,
],
[
1.54235104535692,
10,
],
]; ];

View File

@ -1,60 +1,24 @@
<?php <?php
return [ return [
[ ['#VALUE!', '"ABC"'],
'#VALUE!', [-1.00000000412231, -10],
'ABC', [-1.00000697470904, '-PI() * 2'],
], [-1.00009080398202, '"-5"'],
[ [-1.00374187319732, '-PI()'],
-1.00000000412231, [-1.09033141072737, '-PI() / 2'],
-10, [-10.03331113225400, -0.1],
], ['#DIV/0!', 0.0],
[ [10.03331113225400, 0.1],
-1.00000697470904, [1.09033141072737, 'PI() / 2'],
-M_PI * 2, [1.00374187319732, 'PI()'],
], [1.00009080398202, 5],
[ [1.00000697470904, 'PI() * 2'],
-1.00009080398202, [1.00000000412231, 10],
-5, ['exception', ''],
], ['#DIV/0!', 'Q15'],
[ ['#DIV/0!', 'null'],
-1.00374187319732, ['#DIV/0!', 'false'],
-M_PI, [1.313035285, 'true'],
], [-1.000060867, 'A5'],
[
-1.09033141072737,
-M_PI / 2,
],
[
-10.03331113225400,
-0.1,
],
[
'#DIV/0!',
0.0,
],
[
10.03331113225400,
0.1,
],
[
1.09033141072737,
M_PI / 2,
],
[
1.00374187319732,
M_PI,
],
[
1.00009080398202,
5,
],
[
1.00000697470904,
M_PI * 2,
],
[
1.00000000412231,
10,
],
]; ];

View File

@ -1,52 +1,21 @@
<?php <?php
return [ return [
[ ['#VALUE!', '"ABC"'],
'#VALUE!', [1.83816396088967, -10],
'ABC', [1.04283521277141, '"-5"'],
], [-1.0, '-PI() / 2'],
[ [-10.01668613163480, -0.1],
1.83816396088967, ['#DIV/0!', 0.0],
-10, ['#DIV/0!', 'PI()'],
], ['#DIV/0!', '-PI()'],
[ [10.01668613163480, 0.1],
1.04283521277141, [1.0, 'PI() / 2'],
-5, [-1.04283521277141, 5],
], [-1.83816396088967, 10],
[ [1.188395106, 'true'],
-1.0, ['#DIV/0!', 'false'],
-M_PI / 2, ['#DIV/0!', 'null'],
], ['#DIV/0!', 'Q15'],
[ [1.634366435, 'A4'],
-10.01668613163480,
-0.1,
],
[
'#DIV/0!',
0.0,
],
[
'#DIV/0!',
M_PI,
],
[
'#DIV/0!',
-M_PI,
],
[
10.01668613163480,
0.1,
],
[
1.0,
M_PI / 2,
],
[
-1.04283521277141,
5,
],
[
-1.83816396088967,
10,
],
]; ];

View File

@ -1,60 +1,23 @@
<?php <?php
return [ return [
[ ['#VALUE!', '"ABC"'],
'#VALUE!', [-0.00009079985971, -10],
'ABC', [-0.00373489848829, '-PI() * 2'],
], [-0.01347650583059, '"-5"'],
[ [-0.08658953753005, '-PI()'],
-0.00009079985971, [-0.43453720809470, '-PI() / 2'],
-10, [-9.98335275729611, -0.1],
], ['#DIV/0!', 0.0],
[ [9.98335275729611, 0.1],
-0.00373489848829, [0.43453720809470, 'PI() / 2'],
-M_PI * 2, [0.08658953753005, 'PI()'],
], [0.01347650583059, 5],
[ [0.00373489848829, 'PI() * 2'],
-0.01347650583059, [0.00009079985971, 10],
-5, [0.850918128, 'true'],
], ['#DIV/0!', 'false'],
[ ['#DIV/0!', 'null'],
-0.08658953753005, ['#DIV/0!', 'Q15'],
-M_PI, [-0.044763946, 'A4'],
],
[
-0.43453720809470,
-M_PI / 2,
],
[
-9.98335275729611,
-0.1,
],
[
'#DIV/0!',
0.0,
],
[
9.98335275729611,
0.1,
],
[
0.43453720809470,
M_PI / 2,
],
[
0.08658953753005,
M_PI,
],
[
0.01347650583059,
5,
],
[
0.00373489848829,
M_PI * 2,
],
[
0.00009079985971,
10,
],
]; ];

View File

@ -1,72 +1,24 @@
<?php <?php
return [ return [
[ [0, 'null'],
0, [6, 5.4],
null, [-6, -5.4],
], [2, 1.5],
[ [2, 0.1],
6, [4, '"3"'],
5.4000000000000004, [2, 2],
], [-2, -2],
[ [-2, -1],
-6, ['#VALUE!', '"ABC"'],
-5.4000000000000004, [2, 'true'],
], [0, 'false'],
[ [0, 0],
2, [212, 210.6],
1.5, [4, 2.98],
], [-4, -2.98],
[ [6, 6],
2, ['exception', ''],
0.10000000000000001, ['4', 'A2'],
], ['0', 'Q15'],
[
4,
3,
],
[
2,
2,
],
[
-2,
-2,
],
[
-2,
-1,
],
[
'#VALUE!',
'ABC',
],
[
2,
true,
],
[
0,
false,
],
[
0,
0,
],
[
212,
210.61000000000001,
],
[
4,
2.98,
],
[
-4,
-2.98,
],
[
6,
6,
],
]; ];

View File

@ -1,56 +1,20 @@
<?php <?php
return [ return [
[ [1, 'null'],
1, [7, 5.4],
null, [-7, -5.4],
], [3, 1.5],
[ [1, 0.1],
7, [3, 3],
5.4000000000000004, [3, 2],
], [-3, -2],
[ [-1, -1],
-7, ['#VALUE!', '"ABC"'],
-5.4000000000000004, [1, 'true'],
], [1, 'false'],
[ [1, 0],
3, ['exception', ''],
1.5, ['5', 'A2'],
], ['1', 'Q15'],
[
1,
0.10000000000000001,
],
[
3,
3,
],
[
3,
2,
],
[
-3,
-2,
],
[
-1,
-1,
],
[
'#VALUE!',
'ABC',
],
[
1,
true,
],
[
1,
false,
],
[
1,
0,
],
]; ];

View File

@ -1,68 +1,25 @@
<?php <?php
return [ return [
[ ['#VALUE!', '"ABC"'],
'#VALUE!', [-1.1917935066879, -10],
'ABC', [1.0, '-PI() * 2'],
], [3.52532008581609, '"-5"'],
[ [-1.0, '-PI()'],
-1.1917935066879, ['#DIV/0!', 'PI() / 2'],
-10, ['#DIV/0!', '-PI() / 2'],
], [14.13683290296990, -1.5],
[ [1.00502091840046, -0.1],
1.0, [1.0, 0.0],
-M_PI * 2, [1.00502091840046, 0.1],
], [14.13683290296990, 1.5],
[ [-1.0, 'PI()'],
3.52532008581609, [3.52532008581609, 5],
-5, [1.0, 'PI() * 2'],
], [-1.19179350668790, 10],
[ ['exception', ''],
-1.0, [1, 'Q15'],
-M_PI, [1.850815718, 'true'],
], [1, 'false'],
[ [3.738334127, 'A2'],
'#DIV/0!',
M_PI_2,
],
[
'#DIV/0!',
-M_PI_2,
],
[
14.13683290296990,
-1.5,
],
[
1.00502091840046,
-0.1,
],
[
1.0,
0.0,
],
[
1.00502091840046,
0.1,
],
[
14.13683290296990,
1.5,
],
[
-1.0,
M_PI,
],
[
3.52532008581609,
5,
],
[
1.0,
M_PI * 2,
],
[
-1.19179350668790,
10,
],
]; ];

View File

@ -1,60 +1,23 @@
<?php <?php
return [ return [
[ ['#VALUE!', '"ABC"'],
'#VALUE!', [0.00009079985934, -10],
'ABC', [0.00373487243864, '-PI() * 2'],
], [0.01347528222130, '"-5"'],
[ [0.08626673833405, '-PI()'],
0.00009079985934, [0.39853681533839, '-PI() / 2'],
-10, [0.99502074895323, -0.1],
], [1.0, 0.0],
[ [0.99502074895323, 0.1],
0.00373487243864, [0.39853681533839, 'PI() / 2'],
-M_PI * 2, [0.08626673833405, 'PI()'],
], [0.01347528222130, 5],
[ [0.00373487243864, 'PI() * 2'],
0.01347528222130, [0.00009079985934, 10],
-5, ['exception', ''],
], [1, 'Q15'],
[ [0.648054274, 'true'],
0.08626673833405, [1, 'false'],
-M_PI, [0.507378751, 'A2'],
],
[
0.39853681533839,
-M_PI / 2,
],
[
0.99502074895323,
-0.1,
],
[
1.0,
0.0,
],
[
0.99502074895323,
0.1,
],
[
0.39853681533839,
M_PI / 2,
],
[
0.08626673833405,
M_PI,
],
[
0.01347528222130,
5,
],
[
0.00373487243864,
M_PI * 2,
],
[
0.00009079985934,
10,
],
]; ];

View File

@ -1,56 +1,23 @@
<?php <?php
return [ return [
[ [-1, -1.5],
-1, [-1, -1],
-1.5, [-1, '"-0.5"'],
], [0, 0],
[ [1, 0.5],
-1, [1, 1],
-1, [1, 1.5],
], [1, 2],
[ [1, 2.5],
-1, ['#VALUE!', '"ABC"'],
-0.5, [1, 'true'],
], [0, 'false'],
[ [0, 'null'],
0, [-1, '-3.5'],
0, [0, 'Q15'],
], [1, 'A2'],
[ [0, 'A3'],
1, [-1, 'A4'],
0.5, ['exception', ''],
],
[
1,
1,
],
[
1,
1.5,
],
[
1,
2,
],
[
1,
2.5,
],
[
'#VALUE!',
'ABC',
],
[
1,
true,
],
[
0,
false,
],
[
-1,
'-3.5',
],
]; ];

View File

@ -1,11 +1,15 @@
<?php <?php
return [ return [
['#VALUE!'], // exception not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[0, 0], [0, '0'],
[1, M_PI / 2], [1, 'PI() / 2'],
[0.891207, 1.1], [0.89120736, '"1.1"'],
[-0.891207, -1.1], [-0.89120736, '-1.1'],
[0.909297, 2.0], [0.909297427, '2.0'],
[0, 'Q15'],
[0, 'false'],
[0.841470985, 'true'],
[0.909297427, 'A2'],
]; ];

View File

@ -1,10 +1,14 @@
<?php <?php
return [ return [
['#VALUE!'], // exception not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[0, 0], [0, '0'],
[1.175201, 1], [1.175201194, '1'],
[-1.175201, -1.0], [-1.175201194, '-1.0'],
[3.626860, 2.0], [3.626860, '"2.0"'],
[0, 'Q15'],
[0, 'false'],
[1.175201194, 'true'],
[3.626860408, 'A2'],
]; ];

View File

@ -1,13 +1,17 @@
<?php <?php
return [ return [
['#VALUE!'], // exception not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[0, 0], [0, '0'],
[1.557408, 1], [1.557407725, '1'],
[-2.185040, 2], [-2.185039863, '"2"'],
[1, M_PI / 4], [1, 'PI() / 4'],
['#DIV/0!', M_PI_2], ['#DIV/0!', 'PI() / 2'],
['#DIV/0!', -M_PI_2], ['#DIV/0!', '-PI() / 2'],
['#DIV/0!', 3 * M_PI_2], ['#DIV/0!', '3 * PI() / 2'],
[0, 'Q15'],
[0, 'false'],
[1.557407725, 'true'],
[1.557407725, 'A2'],
]; ];

View File

@ -1,10 +1,14 @@
<?php <?php
return [ return [
['#VALUE!'], // exception not enough args ['exception', ''],
['#VALUE!', '"ABC"'], ['#VALUE!', '"ABC"'],
[0, 0], [0, '0'],
[0.761594, 1], [0.761594156, '1'],
[-0.761594, -1], [-0.761594, '-1'],
[0.970452, 2.1], [0.970452, '2.1'],
[0, 'Q15'],
[0, 'false'],
[0.761594156, 'true'],
[0.761594156, 'A2'],
]; ];