diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 80b6d47b..1db4722b 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -243,22 +243,22 @@ class Calculation ], 'ACOS' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinACOS'], + 'functionCall' => [MathTrig\Acos::class, 'funcAcos'], 'argumentCount' => '1', ], 'ACOSH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinACOSH'], + 'functionCall' => [MathTrig\Acosh::class, 'funcAcosh'], 'argumentCount' => '1', ], 'ACOT' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'ACOT'], + 'functionCall' => [MathTrig\Acot::class, 'funcAcot'], 'argumentCount' => '1', ], 'ACOTH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'ACOTH'], + 'functionCall' => [MathTrig\Acoth::class, 'funcAcoth'], 'argumentCount' => '1', ], 'ADDRESS' => [ @@ -303,27 +303,27 @@ class Calculation ], 'ASIN' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinASIN'], + 'functionCall' => [MathTrig\Asin::class, 'funcAsin'], 'argumentCount' => '1', ], 'ASINH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinASINH'], + 'functionCall' => [MathTrig\Asinh::class, 'funcAsinh'], 'argumentCount' => '1', ], 'ATAN' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinATAN'], + 'functionCall' => [MathTrig\Atan::class, 'funcAtan'], 'argumentCount' => '1', ], 'ATAN2' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'ATAN2'], + 'functionCall' => [MathTrig\Atan2::class, 'funcAtan2'], 'argumentCount' => '2', ], 'ATANH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinATANH'], + 'functionCall' => [MathTrig\Atanh::class, 'funcAtanh'], 'argumentCount' => '1', ], 'AVEDEV' => [ @@ -605,22 +605,22 @@ class Calculation ], 'COS' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinCOS'], + 'functionCall' => [MathTrig\Cos::class, 'funcCos'], 'argumentCount' => '1', ], 'COSH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinCOSH'], + 'functionCall' => [MathTrig\Cosh::class, 'funcCosh'], 'argumentCount' => '1', ], 'COT' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'COT'], + 'functionCall' => [MathTrig\Cot::class, 'funcCot'], 'argumentCount' => '1', ], 'COTH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'COTH'], + 'functionCall' => [MathTrig\Coth::class, 'funcCoth'], 'argumentCount' => '1', ], 'COUNT' => [ @@ -700,12 +700,12 @@ class Calculation ], 'CSC' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'CSC'], + 'functionCall' => [MathTrig\Csc::class, 'funcCsc'], 'argumentCount' => '1', ], 'CSCH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'CSCH'], + 'functionCall' => [MathTrig\Csch::class, 'funcCsch'], 'argumentCount' => '1', ], 'CUBEKPIMEMBER' => [ @@ -965,7 +965,7 @@ class Calculation ], 'EVEN' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'EVEN'], + 'functionCall' => [MathTrig\Even::class, 'funcEven'], 'argumentCount' => '1', ], 'EXACT' => [ @@ -1856,7 +1856,7 @@ class Calculation ], 'ODD' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'ODD'], + 'functionCall' => [MathTrig\Odd::class, 'funcOdd'], 'argumentCount' => '1', ], 'ODDFPRICE' => [ @@ -2165,12 +2165,12 @@ class Calculation ], 'SEC' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'SEC'], + 'functionCall' => [MathTrig\Sec::class, 'funcSec'], 'argumentCount' => '1', ], 'SECH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'SECH'], + 'functionCall' => [MathTrig\Sech::class, 'funcSech'], 'argumentCount' => '1', ], 'SECOND' => [ @@ -2200,7 +2200,7 @@ class Calculation ], 'SIGN' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'SIGN'], + 'functionCall' => [MathTrig\Sign::class, 'funcSign'], 'argumentCount' => '1', ], 'SIN' => [ @@ -2210,7 +2210,7 @@ class Calculation ], 'SINH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinSINH'], + 'functionCall' => [MathTrig\Sinh::class, 'funcSinh'], 'argumentCount' => '1', ], 'SKEW' => [ @@ -2366,12 +2366,12 @@ class Calculation ], 'TAN' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinTAN'], + 'functionCall' => [MathTrig\Tan::class, 'funcTan'], 'argumentCount' => '1', ], 'TANH' => [ 'category' => Category::CATEGORY_MATH_AND_TRIG, - 'functionCall' => [MathTrig::class, 'builtinTANH'], + 'functionCall' => [MathTrig\Tanh::class, 'funcTanh'], 'argumentCount' => '1', ], 'TBILLEQ' => [ diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index e72e24cd..f3d8351d 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -133,6 +133,8 @@ class MathTrig * 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. * + * @Deprecated 2.0.0 Use the funcAtan2 method in the MathTrig\Atan2 class instead + * * Excel Function: * ATAN2(xCoordinate,yCoordinate) * @@ -143,27 +145,7 @@ class MathTrig */ public static function ATAN2($xCoordinate = null, $yCoordinate = null) { - $xCoordinate = Functions::flattenSingleValue($xCoordinate); - $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(); + return MathTrig\Atan2::funcAtan2($xCoordinate, $yCoordinate); } /** @@ -226,8 +208,6 @@ class MathTrig * @param float $significance the multiple to which you want to round * * @return float|string Rounded Number, or a string containing an error - * - * @codeCoverageIgnore */ public static function CEILING($number, $significance = null) { @@ -269,6 +249,8 @@ class MathTrig /** * EVEN. * + * @Deprecated 2.0.0 Use the funcEven method in the MathTrig\Even class instead + * * 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 @@ -284,26 +266,17 @@ class MathTrig */ public static function EVEN($number) { - $number = Functions::flattenSingleValue($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(); + return MathTrig\Even::funcEven($number); } + /** + * 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 { - $significance = 2 * self::returnSign($number); - - return (int) MathTrig\Ceiling::funcCeiling($number, $significance); + return (int) MathTrig\Helpers::getEven($number); } /** @@ -395,8 +368,6 @@ class MathTrig * @param float $significance Significance * * @return float|string Rounded Number, or a string containing an error - * - * @codeCoverageIgnore */ public static function FLOOR($number, $significance = null) { @@ -420,8 +391,6 @@ class MathTrig * @param int $mode direction to round negative numbers * * @return float|string Rounded Number, or a string containing an error - * - * @codeCoverageIgnore */ public static function FLOORMATH($number, $significance = null, $mode = 0) { @@ -444,8 +413,6 @@ class MathTrig * @param float $significance Significance * * @return float|string Rounded Number, or a string containing an error - * - * @codeCoverageIgnore */ public static function FLOORPRECISE($number, $significance = 1) { @@ -472,8 +439,6 @@ class MathTrig * @param float $number Number to cast to an integer * * @return int|string Integer value, or a string containing an error - * - * @codeCoverageIgnore */ public static function INT($number) { @@ -797,8 +762,6 @@ class MathTrig * @param int $multiple Multiple to which you want to round $number * * @return float|string Rounded Number, or a string containing an error - * - * @codeCoverageIgnore */ public static function MROUND($number, $multiple) { @@ -847,36 +810,15 @@ class MathTrig * * 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 * * @return int|string Rounded Number, or a string containing an error */ public static function ODD($number) { - $number = Functions::flattenSingleValue($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(); + return MathTrig\Odd::funcOdd($number); } /** @@ -1015,8 +957,6 @@ class MathTrig * @param mixed $style Number indicating one of five possible forms * * @return string Roman numeral, or a string containing an error - * - * @codeCoverageIgnore */ 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 * * @return float|string Rounded Number, or a string containing an error - * - * @codeCoverageIgnore */ 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 * * @return float|string Rounded Number, or a string containing an error - * - * @codeCoverageIgnore */ 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) * 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 * * @return int|string sign value, or a string containing an error */ public static function SIGN($number) { - $number = Functions::flattenSingleValue($number); - - if (is_bool($number)) { - return (int) $number; - } - if (is_numeric($number)) { - return self::returnSign($number); - } - - return Functions::VALUE(); + return MathTrig\Sign::funcSign($number); } + /** + * 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 { - return $number ? (($number > 0) ? 1 : -1) : 0; + return MathTrig\Helpers::returnSign($number); } /** @@ -1486,8 +1420,6 @@ class MathTrig * @param int $digits * * @return float|string Truncated value, or a string containing an error - * - * @codeCoverageIgnore */ public static function TRUNC($value = 0, $digits = 0) { @@ -1499,21 +1431,15 @@ class MathTrig * * Returns the secant of an angle. * + * @Deprecated 2.0.0 Use the funcSec method in the MathTrig\Sec class instead + * * @param float $angle Number * * @return float|string The secant of the angle */ public static function SEC($angle) { - $angle = Functions::flattenSingleValue($angle); - - if (!is_numeric($angle)) { - return Functions::VALUE(); - } - - $result = cos($angle); - - return self::verySmallDivisor($result) ? Functions::DIV0() : (1 / $result); + return MathTrig\Sec::funcSec($angle); } /** @@ -1521,21 +1447,15 @@ class MathTrig * * 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 * * @return float|string The hyperbolic secant of the angle */ public static function SECH($angle) { - $angle = Functions::flattenSingleValue($angle); - - if (!is_numeric($angle)) { - return Functions::VALUE(); - } - - $result = cosh($angle); - - return ($result == 0.0) ? Functions::DIV0() : 1 / $result; + return MathTrig\Sech::funcSech($angle); } /** @@ -1543,21 +1463,15 @@ class MathTrig * * Returns the cosecant of an angle. * + * @Deprecated 2.0.0 Use the funcCsc method in the MathTrig\Csc class instead + * * @param float $angle Number * * @return float|string The cosecant of the angle */ public static function CSC($angle) { - $angle = Functions::flattenSingleValue($angle); - - if (!is_numeric($angle)) { - return Functions::VALUE(); - } - - $result = sin($angle); - - return self::verySmallDivisor($result) ? Functions::DIV0() : (1 / $result); + return MathTrig\Csc::funcCsc($angle); } /** @@ -1565,21 +1479,15 @@ class MathTrig * * 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 * * @return float|string The hyperbolic cosecant of the angle */ public static function CSCH($angle) { - $angle = Functions::flattenSingleValue($angle); - - if (!is_numeric($angle)) { - return Functions::VALUE(); - } - - $result = sinh($angle); - - return ($result == 0.0) ? Functions::DIV0() : 1 / $result; + return MathTrig\Csch::funcCsch($angle); } /** @@ -1587,21 +1495,15 @@ class MathTrig * * Returns the cotangent of an angle. * + * @Deprecated 2.0.0 Use the funcCot method in the MathTrig\Cot class instead + * * @param float $angle Number * * @return float|string The cotangent of the angle */ public static function COT($angle) { - $angle = Functions::flattenSingleValue($angle); - - if (!is_numeric($angle)) { - return Functions::VALUE(); - } - - $result = sin($angle); - - return self::verySmallDivisor($result) ? Functions::DIV0() : (cos($angle) / $result); + return MathTrig\Cot::funcCot($angle); } /** @@ -1609,21 +1511,15 @@ class MathTrig * * 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 * * @return float|string The hyperbolic cotangent of the angle */ public static function COTH($angle) { - $angle = Functions::flattenSingleValue($angle); - - if (!is_numeric($angle)) { - return Functions::VALUE(); - } - - $result = tanh($angle); - - return ($result == 0.0) ? Functions::DIV0() : 1 / $result; + return MathTrig\Coth::funcCoth($angle); } /** @@ -1631,31 +1527,29 @@ class MathTrig * * Returns the arccotangent of a number. * + * @Deprecated 2.0.0 Use the funcAcot method in the MathTrig\Acot class instead + * * @param float $number Number * * @return float|string The arccotangent of the number */ public static function ACOT($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return (M_PI / 2) - atan($number); + return MathTrig\Acot::funcAcot($number); } /** * 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 * * @return float|string */ 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. * + * @Deprecated 2.0.0 Use the funcAcoth method in the MathTrig\Acoth class instead + * * @param float $number Number * * @return float|string The hyperbolic arccotangent of the number */ public static function ACOTH($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - $result = log(($number + 1) / ($number - 1)) / 2; - - return self::numberOrNan($result); + return MathTrig\Acoth::funcAcoth($number); } /** @@ -1693,8 +1581,6 @@ class MathTrig * @param mixed $precision Should be int * * @return float|string Rounded number - * - * @codeCoverageIgnore */ public static function builtinROUND($number, $precision) { @@ -1724,6 +1610,8 @@ class MathTrig /** * 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. * * @param mixed $number Should be numeric @@ -1732,13 +1620,7 @@ class MathTrig */ public static function builtinACOS($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return self::numberOrNan(acos($number)); + return MathTrig\Acos::funcAcos($number); } /** @@ -1746,19 +1628,15 @@ class MathTrig * * 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 * * @return float|string Rounded number */ public static function builtinACOSH($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return self::numberOrNan(acosh($number)); + return MathTrig\Acosh::funcAcosh($number); } /** @@ -1766,19 +1644,15 @@ class MathTrig * * 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 * * @return float|string Rounded number */ public static function builtinASIN($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return self::numberOrNan(asin($number)); + return MathTrig\Asin::funcAsin($number); } /** @@ -1786,39 +1660,31 @@ class MathTrig * * 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 * * @return float|string Rounded number */ public static function builtinASINH($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return asinh($number); + return MathTrig\Asinh::funcAsinh($number); } /** - * ASIN. + * ATAN. * * 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 * * @return float|string Rounded number */ public static function builtinATAN($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return self::numberOrNan(atan($number)); + return MathTrig\Atan::funcAtan($number); } /** @@ -1826,19 +1692,15 @@ class MathTrig * * 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 * * @return float|string Rounded number */ public static function builtinATANH($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return atanh($number); + return MathTrig\Atanh::funcAtanh($number); } /** @@ -1846,19 +1708,15 @@ class MathTrig * * 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 * * @return float|string Rounded number */ public static function builtinCOS($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return cos($number); + return MathTrig\Cos::funcCos($number); } /** @@ -1866,19 +1724,15 @@ class MathTrig * * 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 * * @return float|string Rounded number */ public static function builtinCOSH($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return cosh($number); + return MathTrig\Cosh::funcCosh($number); } /** @@ -1984,6 +1838,8 @@ class MathTrig /** * 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. * * @param mixed $number Should be numeric @@ -1992,18 +1848,14 @@ class MathTrig */ public static function builtinSIN($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return sin($number); + return MathTrig\Sin::funcSin($number); } /** * 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. * * @param mixed $number Should be numeric @@ -2012,13 +1864,7 @@ class MathTrig */ public static function builtinSINH($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return sinh($number); + return MathTrig\Sinh::funcSinh($number); } /** @@ -2046,19 +1892,15 @@ class MathTrig * * 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 * * @return float|string Rounded number */ public static function builtinTAN($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return self::verySmallDivisor(cos($number)) ? Functions::DIV0() : tan($number); + return MathTrig\Tan::funcTan($number); } /** @@ -2066,29 +1908,22 @@ class MathTrig * * 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 * * @return float|string Rounded number */ public static function builtinTANH($number) { - $number = Functions::flattenSingleValue($number); - - if (!is_numeric($number)) { - return Functions::VALUE(); - } - - return tanh($number); - } - - private static function verySmallDivisor(float $number): bool - { - return abs($number) < 1.0E-12; + return MathTrig\Tanh::funcTanh($number); } /** * 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 */ public static function nullFalseTrueToNumber(&$number): void diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acos.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acos.php new file mode 100644 index 00000000..20d645f2 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Acos.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::numberOrNan(acos($number)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acosh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acosh.php new file mode 100644 index 00000000..f77d3a09 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Acosh.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::numberOrNan(acosh($number)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php new file mode 100644 index 00000000..1024f9f6 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return (M_PI / 2) - atan($number); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php new file mode 100644 index 00000000..42bdc181 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php @@ -0,0 +1,30 @@ +getMessage(); + } + + $result = ($number === 1) ? NAN : (log(($number + 1) / ($number - 1)) / 2); + + return Helpers::numberOrNan($result); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Asin.php b/src/PhpSpreadsheet/Calculation/MathTrig/Asin.php new file mode 100644 index 00000000..e30ab04c --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Asin.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::numberOrNan(asin($number)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Asinh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Asinh.php new file mode 100644 index 00000000..35a3ae26 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Asinh.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::numberOrNan(asinh($number)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php new file mode 100644 index 00000000..3e57f048 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::numberOrNan(atan($number)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php new file mode 100644 index 00000000..2ea975a8 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php @@ -0,0 +1,46 @@ +getMessage(); + } + + if (($xCoordinate == 0) && ($yCoordinate == 0)) { + return Functions::DIV0(); + } + + return atan2($yCoordinate, $xCoordinate); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php new file mode 100644 index 00000000..a9723f16 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::numberOrNan(atanh($number)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php b/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php index 6fdd6165..1085158a 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php @@ -4,7 +4,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; class Ceiling { @@ -26,19 +25,18 @@ class Ceiling */ public static function funcCeiling($number, $significance = null) { - MathTrig::nullFalseTrueToNumber($number); - $significance = Functions::flattenSingleValue($significance); - if ($significance === null) { self::floorCheck1Arg(); - $significance = ((float) $number < 0) ? -1 : 1; } - if ((is_numeric($number)) && (is_numeric($significance))) { - return self::argumentsOk((float) $number, (float) $significance); + try { + $number = Helpers::validateNumericNullBool($number); + $significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1); + } catch (Exception $e) { + return $e->getMessage(); } - return Functions::VALUE(); + return self::argumentsOk((float) $number, (float) $significance); } /** @@ -51,7 +49,7 @@ class Ceiling if (empty($number * $significance)) { return 0.0; } - if (MathTrig::returnSign($number) == MathTrig::returnSign($significance)) { + if (Helpers::returnSign($number) == Helpers::returnSign($significance)) { return ceil($number / $significance) * $significance; } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/CeilingMath.php b/src/PhpSpreadsheet/Calculation/MathTrig/CeilingMath.php index f94d1fe0..e41e9d09 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/CeilingMath.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/CeilingMath.php @@ -2,8 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; class CeilingMath { @@ -23,26 +22,22 @@ class CeilingMath */ public static function funcCeilingMath($number, $significance = null, $mode = 0) { - MathTrig::nullFalseTrueToNumber($number); - $significance = Functions::flattenSingleValue($significance); - $mode = Functions::flattenSingleValue($mode); - - if ($significance === null) { - $significance = ((float) $number < 0) ? -1 : 1; + try { + $number = Helpers::validateNumericNullBool($number); + $significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1); + $mode = Helpers::validateNumericNullSubstitution($mode, null); + } catch (Exception $e) { + return $e->getMessage(); } - if (is_numeric($number) && is_numeric($significance) && is_numeric($mode)) { - if (empty($significance * $number)) { - return 0.0; - } - if (self::ceilingMathTest((float) $significance, (float) $number, (int) $mode)) { - return floor($number / $significance) * $significance; - } - - return ceil($number / $significance) * $significance; + if (empty($significance * $number)) { + return 0.0; + } + if (self::ceilingMathTest((float) $significance, (float) $number, (int) $mode)) { + return floor($number / $significance) * $significance; } - return Functions::VALUE(); + return ceil($number / $significance) * $significance; } /** diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/CeilingPrecise.php b/src/PhpSpreadsheet/Calculation/MathTrig/CeilingPrecise.php index d9c61c41..1bc4504b 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/CeilingPrecise.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/CeilingPrecise.php @@ -2,8 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; class CeilingPrecise { @@ -22,18 +21,18 @@ class CeilingPrecise */ public static function funcCeilingPrecise($number, $significance = 1) { - MathTrig::nullFalseTrueToNumber($number); - $significance = Functions::flattenSingleValue($significance); - - if ((is_numeric($number)) && (is_numeric($significance))) { - if ($significance == 0.0) { - return 0.0; - } - $result = $number / abs($significance); - - return ceil($result) * $significance * (($significance < 0) ? -1 : 1); + try { + $number = Helpers::validateNumericNullBool($number); + $significance = Helpers::validateNumericNullSubstitution($significance, null); + } catch (Exception $e) { + return $e->getMessage(); } - return Functions::VALUE(); + if (!$significance) { + return 0.0; + } + $result = $number / abs($significance); + + return ceil($result) * $significance * (($significance < 0) ? -1 : 1); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Cos.php b/src/PhpSpreadsheet/Calculation/MathTrig/Cos.php new file mode 100644 index 00000000..2dfed782 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Cos.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return cos($number); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Cosh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Cosh.php new file mode 100644 index 00000000..3e806cd6 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Cosh.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return cosh($number); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php b/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php new file mode 100644 index 00000000..1cf5c6b4 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::verySmallDenominator(cos($angle), sin($angle)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php b/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php new file mode 100644 index 00000000..c80ec93e --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::verySmallDenominator(1.0, tanh($angle)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php b/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php new file mode 100644 index 00000000..325637b8 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::verySmallDenominator(1.0, sin($angle)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php b/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php new file mode 100644 index 00000000..8a045203 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::verySmallDenominator(1.0, sinh($angle)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Even.php b/src/PhpSpreadsheet/Calculation/MathTrig/Even.php new file mode 100644 index 00000000..ac79a211 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Even.php @@ -0,0 +1,35 @@ +getMessage(); + } + + return Helpers::getEven($number); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php b/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php index 0c65ee7c..f178b324 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php @@ -4,7 +4,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; use Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; class Floor { @@ -31,19 +30,18 @@ class Floor */ public static function funcFloor($number, $significance = null) { - MathTrig::nullFalseTrueToNumber($number); - $significance = Functions::flattenSingleValue($significance); - if ($significance === null) { self::floorCheck1Arg(); - $significance = MathTrig::returnSign((float) $number); } - if ((is_numeric($number)) && (is_numeric($significance))) { - return self::argumentsOk((float) $number, (float) $significance); + try { + $number = Helpers::validateNumericNullBool($number); + $significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1); + } catch (Exception $e) { + return $e->getMessage(); } - return Functions::VALUE(); + return self::argumentsOk((float) $number, (float) $significance); } /** @@ -59,10 +57,10 @@ class Floor if ($number == 0.0) { return 0.0; } - if (MathTrig::returnSign($significance) == 1) { + if (Helpers::returnSign($significance) == 1) { 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; } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/FloorMath.php b/src/PhpSpreadsheet/Calculation/MathTrig/FloorMath.php index cba78a53..8b922829 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/FloorMath.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/FloorMath.php @@ -2,8 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; class FloorMath { @@ -23,19 +23,15 @@ class FloorMath */ public static function funcFloorMath($number, $significance = null, $mode = 0) { - MathTrig::nullFalseTrueToNumber($number); - $significance = Functions::flattenSingleValue($significance); - $mode = Functions::flattenSingleValue($mode); - - if ($significance === null) { - $significance = ((float) $number < 0) ? -1 : 1; + try { + $number = Helpers::validateNumericNullBool($number); + $significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1); + $mode = Helpers::validateNumericNullSubstitution($mode, null); + } catch (Exception $e) { + return $e->getMessage(); } - if (is_numeric($number) && is_numeric($significance) && is_numeric($mode)) { - return self::argsOk((float) $number, (float) $significance, (int) $mode); - } - - return Functions::VALUE(); + return self::argsOk((float) $number, (float) $significance, (int) $mode); } /** @@ -63,6 +59,6 @@ class FloorMath */ 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)); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/FloorPrecise.php b/src/PhpSpreadsheet/Calculation/MathTrig/FloorPrecise.php index 07990aa5..3ce34dc4 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/FloorPrecise.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/FloorPrecise.php @@ -2,8 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; class FloorPrecise { @@ -22,14 +22,14 @@ class FloorPrecise */ public static function funcFloorPrecise($number, $significance = 1) { - MathTrig::nullFalseTrueToNumber($number); - $significance = Functions::flattenSingleValue($significance); - - if ((is_numeric($number)) && (is_numeric($significance))) { - return self::argumentsOk((float) $number, (float) $significance); + try { + $number = Helpers::validateNumericNullBool($number); + $significance = Helpers::validateNumericNullSubstitution($significance, null); + } catch (Exception $e) { + return $e->getMessage(); } - return Functions::VALUE(); + return self::argumentsOk((float) $number, (float) $significance); } /** diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php b/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php new file mode 100644 index 00000000..63b5082c --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php @@ -0,0 +1,87 @@ + 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; + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php b/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php index 46784908..e43fe65c 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php @@ -2,8 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; class IntClass { @@ -21,11 +20,12 @@ class IntClass */ public static function funcInt($number) { - MathTrig::nullFalseTrueToNumber($number); - if (is_numeric($number)) { - return (int) floor($number); + try { + $number = Helpers::validateNumericNullBool($number); + } catch (Exception $e) { + return $e->getMessage(); } - return Functions::VALUE(); + return (int) floor($number); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Mround.php b/src/PhpSpreadsheet/Calculation/MathTrig/Mround.php index 4c040dce..d1b32aa7 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Mround.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Mround.php @@ -2,8 +2,8 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; class Mround { @@ -19,24 +19,22 @@ class Mround */ public static function funcMround($number, $multiple) { - $number = Functions::flattenSingleValue($number); - $number = $number ?? 0; - - $multiple = Functions::flattenSingleValue($multiple); - - if ((is_numeric($number)) && (is_numeric($multiple))) { - if ($number == 0 || $multiple == 0) { - return 0; - } - if ((MathTrig::SIGN($number)) == (MathTrig::SIGN($multiple))) { - $multiplier = 1 / $multiple; - - return round($number * $multiplier) / $multiplier; - } - - return Functions::NAN(); + try { + $number = Helpers::validateNumericNullSubstitution($number, 0); + $multiple = Helpers::validateNumericNullSubstitution($multiple, null); + } catch (Exception $e) { + return $e->getMessage(); } - return Functions::VALUE(); + if ($number == 0 || $multiple == 0) { + return 0; + } + if ((Helpers::returnSign($number)) == (Helpers::returnSign($multiple))) { + $multiplier = 1 / $multiple; + + return round($number * $multiplier) / $multiplier; + } + + return Functions::NAN(); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Odd.php b/src/PhpSpreadsheet/Calculation/MathTrig/Odd.php new file mode 100644 index 00000000..b8ef3dd0 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Odd.php @@ -0,0 +1,38 @@ +getMessage(); + } + + $significance = Helpers::returnSign($number); + if ($significance == 0) { + return 1; + } + + $result = ceil($number / $significance) * $significance; + if ($result == Helpers::getEven($result)) { + $result += $significance; + } + + return $result; + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php b/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php index a461001b..05ecb531 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Roman @@ -823,31 +824,16 @@ class Roman */ public static function funcRoman($aValue, $style = 0) { - $aValue = Functions::flattenSingleValue($aValue); - self::nullFalseTrueToNumber($aValue); - $style = Functions::flattenSingleValue($style); - if (is_bool($style)) { - $style = $style ? 0 : 4; - } - if (!is_numeric($aValue) || !is_numeric($style)) { - return Functions::VALUE(); + try { + $aValue = Helpers::validateNumericNullBool($aValue); + if (is_bool($style)) { + $style = $style ? 0 : 4; + } + $style = Helpers::validateNumericNullSubstitution($style, null); + } catch (Exception $e) { + return $e->getMessage(); } 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; - } - } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Round.php b/src/PhpSpreadsheet/Calculation/MathTrig/Round.php index 339f0e27..bc1c6669 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Round.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Round.php @@ -2,8 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; class Round { @@ -19,12 +18,13 @@ class Round */ public static function builtinROUND($number, $precision) { - MathTrig::nullFalseTrueToNumber($number); - - if (!is_numeric($number) || !is_numeric($precision)) { - return Functions::VALUE(); + try { + $number = Helpers::validateNumericNullBool($number); + $precision = Helpers::validateNumericNullBool($precision); + } catch (Exception $e) { + return $e->getMessage(); } - return round($number, $precision); + return round($number, (int) $precision); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php b/src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php index ff1f9bcb..bf19d5d5 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php @@ -2,8 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; class RoundDown { @@ -19,21 +18,21 @@ class RoundDown */ public static function funcRoundDown($number, $digits) { - MathTrig::nullFalseTrueToNumber($number); - $digits = Functions::flattenSingleValue($digits); - - if ((is_numeric($number)) && (is_numeric($digits))) { - if ($number == 0.0) { - return 0.0; - } - - if ($number < 0.0) { - 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); + try { + $number = Helpers::validateNumericNullBool($number); + $digits = Helpers::validateNumericNullSubstitution($digits, null); + } catch (Exception $e) { + return $e->getMessage(); } - return Functions::VALUE(); + if ($number == 0.0) { + return 0.0; + } + + if ($number < 0.0) { + 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); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php b/src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php index c9507464..a4f00cd3 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php @@ -2,8 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; class RoundUp { @@ -19,21 +18,21 @@ class RoundUp */ public static function funcRoundUp($number, $digits) { - MathTrig::nullFalseTrueToNumber($number); - $digits = Functions::flattenSingleValue($digits); - - if ((is_numeric($number)) && (is_numeric($digits))) { - if ($number == 0.0) { - return 0.0; - } - - if ($number < 0.0) { - 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); + try { + $number = Helpers::validateNumericNullBool($number); + $digits = Helpers::validateNumericNullSubstitution($digits, null); + } catch (Exception $e) { + return $e->getMessage(); } - return Functions::VALUE(); + if ($number == 0.0) { + return 0.0; + } + + if ($number < 0.0) { + 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); } } diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php new file mode 100644 index 00000000..9bb5a1b7 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::verySmallDenominator(1.0, cos($angle)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php new file mode 100644 index 00000000..191bea4d --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::verySmallDenominator(1.0, cosh($angle)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php new file mode 100644 index 00000000..84ff523f --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php @@ -0,0 +1,29 @@ +getMessage(); + } + + return Helpers::returnSign($number); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sin.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sin.php new file mode 100644 index 00000000..f718451c --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sin.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return sin($angle); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sinh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sinh.php new file mode 100644 index 00000000..ce3ef3e5 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sinh.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return sinh($angle); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php b/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php new file mode 100644 index 00000000..82612cb8 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return Helpers::verySmallDenominator(sin($angle), cos($angle)); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php new file mode 100644 index 00000000..29bf82e1 --- /dev/null +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php @@ -0,0 +1,28 @@ +getMessage(); + } + + return tanh($angle); + } +} diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php index 8cb14d2a..ba82a000 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php @@ -2,8 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use Exception; class Trunc { @@ -19,13 +18,13 @@ class Trunc */ public static function funcTrunc($value = 0, $digits = 0) { - MathTrig::nullFalseTrueToNumber($value); - $digits = Functions::flattenSingleValue($digits); - - // Validate parameters - if ((!is_numeric($value)) || (!is_numeric($digits))) { - return Functions::VALUE(); + try { + $value = Helpers::validateNumericNullBool($value); + $digits = Helpers::validateNumericNullSubstitution($digits, null); + } catch (Exception $e) { + return $e->getMessage(); } + $digits = floor($digits); // Truncate diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php index 825626da..9dd6a49d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php @@ -12,19 +12,16 @@ class AcosTest extends TestCase * @dataProvider providerAcos * * @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); - $formula = '=ACOS()'; - } else { - $formula = "=ACOS($val)"; } $spreadsheet = new Spreadsheet(); $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(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php index bda64d03..d596cc9e 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php @@ -12,19 +12,16 @@ class AcoshTest extends TestCase * @dataProvider providerAcosh * * @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); - $formula = '=ACOSH()'; - } else { - $formula = "=ACOSH($val)"; } $spreadsheet = new Spreadsheet(); $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(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php index d81c3b9d..99694215 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class AcotTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerACOT * @@ -21,8 +16,18 @@ class AcotTest extends TestCase */ public function testACOT($expectedResult, $number): void { - $result = MathTrig::ACOT($number); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php index 0a3864cc..1d565e73 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class AcothTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerACOTH * @@ -21,8 +16,18 @@ class AcothTest extends TestCase */ public function testACOTH($expectedResult, $number): void { - $result = MathTrig::ACOTH($number); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php index 1edc1c33..c1c836f3 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php @@ -12,19 +12,16 @@ class AsinTest extends TestCase * @dataProvider providerAsin * * @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); - $formula = '=ASIN()'; - } else { - $formula = "=ASIN($val)"; } $spreadsheet = new Spreadsheet(); $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(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php index 1621eb79..ebbb74f1 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php @@ -12,19 +12,16 @@ class AsinhTest extends TestCase * @dataProvider providerAsinh * * @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); - $formula = '=ASINH()'; - } else { - $formula = "=ASINH($val)"; } $spreadsheet = new Spreadsheet(); $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(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php index 4edec4cb..35a96aea 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php @@ -2,28 +2,29 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class Atan2Test extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerATAN2 * * @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); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php index 50d76967..4dec2dca 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php @@ -12,19 +12,16 @@ class AtanTest extends TestCase * @dataProvider providerAtan * * @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); - $formula = '=ATAN()'; - } else { - $formula = "=ATAN($val)"; } $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); - $sheet->getCell('A1')->setValue($formula); + $sheet->getCell('A2')->setValue(5); + $sheet->getCell('A1')->setValue("=ATAN($formula)"); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php index 2863a182..cc8a243f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php @@ -12,19 +12,16 @@ class AtanhTest extends TestCase * @dataProvider providerAtanh * * @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); - $formula = '=ATANH()'; - } else { - $formula = "=ATANH($val)"; } $spreadsheet = new Spreadsheet(); $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(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php index da7a9a15..d5ada718 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php @@ -12,19 +12,16 @@ class CosTest extends TestCase * @dataProvider providerCos * * @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); - $formula = '=COS()'; - } else { - $formula = "=COS($val)"; } $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); - $sheet->getCell('A1')->setValue($formula); + $sheet->setCellValue('A2', 2); + $sheet->getCell('A1')->setValue("=COS($formula)"); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php index 2c452bd5..81dc9c75 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php @@ -12,19 +12,16 @@ class CoshTest extends TestCase * @dataProvider providerCosh * * @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); - $formula = '=COSH()'; - } else { - $formula = "=COSH($val)"; } $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); - $sheet->getCell('A1')->setValue($formula); + $sheet->setCellValue('A2', 2); + $sheet->getCell('A1')->setValue("=COSH($formula)"); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php index 3fee6901..cb009a89 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class CotTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerCOT * @@ -21,8 +16,18 @@ class CotTest extends TestCase */ public function testCOT($expectedResult, $angle): void { - $result = MathTrig::COT($angle); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php index e3db23d5..e4b42a4d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class CothTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerCOTH * @@ -21,8 +16,18 @@ class CothTest extends TestCase */ public function testCOTH($expectedResult, $angle): void { - $result = MathTrig::COTH($angle); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php index 675ebf57..8ae48cde 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class CscTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerCSC * @@ -21,8 +16,18 @@ class CscTest extends TestCase */ public function testCSC($expectedResult, $angle): void { - $result = MathTrig::CSC($angle); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php index c630be2f..4a7dbc05 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class CschTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerCSCH * @@ -21,8 +16,18 @@ class CschTest extends TestCase */ public function testCSCH($expectedResult, $angle): void { - $result = MathTrig::CSCH($angle); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php index 96c0b046..080925b1 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class EvenTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerEVEN * @@ -21,8 +16,14 @@ class EvenTest extends TestCase */ public function testEVEN($expectedResult, $value): void { - $result = MathTrig::EVEN($value); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MovedFunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MovedFunctionsTest.php index d8b55e7c..45c558cd 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MovedFunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MovedFunctionsTest.php @@ -16,15 +16,47 @@ class MovedFunctionsTest extends TestCase { 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(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(0.23, MathTrig::FLOORMATH(0.234, 0.01)); self::assertEquals(-4, MathTrig::FLOORPRECISE(-2.5, 2)); self::assertEquals(-9, MathTrig::INT(-8.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(662, MathTrig::ROUNDDOWN(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(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); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php index 6c5758c6..ed262d9c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class OddTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerODD * @@ -21,8 +16,14 @@ class OddTest extends TestCase */ public function testODD($expectedResult, $value): void { - $result = MathTrig::ODD($value); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php index ad4b196c..a47ae7b5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class SecTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerSEC * @@ -21,8 +16,18 @@ class SecTest extends TestCase */ public function testSEC($expectedResult, $angle): void { - $result = MathTrig::SEC($angle); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php index b9488bda..65ed7b73 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class SechTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerSECH * @@ -21,8 +16,18 @@ class SechTest extends TestCase */ public function testSECH($expectedResult, $angle): void { - $result = MathTrig::SECH($angle); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php index 68f5acb9..a4311219 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php @@ -2,17 +2,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; -use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; +use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class SignTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - } - /** * @dataProvider providerSIGN * @@ -21,8 +16,17 @@ class SignTest extends TestCase */ public function testSIGN($expectedResult, $value): void { - $result = MathTrig::SIGN($value); - self::assertEqualsWithDelta($expectedResult, $result, 1E-12); + if ($expectedResult === 'exception') { + $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() diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php index 7a144e0e..e9ad6329 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php @@ -12,19 +12,16 @@ class SinTest extends TestCase * @dataProvider providerSin * * @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); - $formula = '=SIN()'; - } else { - $formula = "=SIN($val)"; } $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); - $sheet->getCell('A1')->setValue($formula); + $sheet->setCellValue('A2', 2); + $sheet->getCell('A1')->setValue("=SIN($formula)"); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php index c24bb192..38bfc7ef 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php @@ -12,19 +12,16 @@ class SinhTest extends TestCase * @dataProvider providerCosh * * @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); - $formula = '=SINH()'; - } else { - $formula = "=SINH($val)"; } $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); - $sheet->getCell('A1')->setValue($formula); + $sheet->setCellValue('A2', 2); + $sheet->getCell('A1')->setValue("=SINH($formula)"); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php index 13093f6a..5a482cd8 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php @@ -12,19 +12,16 @@ class TanTest extends TestCase * @dataProvider providerTan * * @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); - $formula = '=TAN()'; - } else { - $formula = "=TAN($val)"; } $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); - $sheet->getCell('A1')->setValue($formula); + $sheet->setCellValue('A2', 1); + $sheet->getCell('A1')->setValue("=TAN($formula)"); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php index 69f28e8a..5fe50d7c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php @@ -12,19 +12,16 @@ class TanhTest extends TestCase * @dataProvider providerTanh * * @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); - $formula = '=TANH()'; - } else { - $formula = "=TANH($val)"; } $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); - $sheet->getCell('A1')->setValue($formula); + $sheet->setCellValue('A2', 1); + $sheet->getCell('A1')->setValue("=TANH($formula)"); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1E-6); } diff --git a/tests/data/Calculation/MathTrig/ACOS.php b/tests/data/Calculation/MathTrig/ACOS.php index f592de09..487a0628 100644 --- a/tests/data/Calculation/MathTrig/ACOS.php +++ b/tests/data/Calculation/MathTrig/ACOS.php @@ -1,10 +1,14 @@