Envelope case validation and fix return values

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@91574 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2012-06-10 22:06:14 +00:00
parent 92461ae067
commit 5193c6c35d
1 changed files with 111 additions and 25 deletions

View File

@ -97,40 +97,58 @@ class PHPExcel_Calculation_MathTrig {
* @param float $yCoordinate The y-coordinate of the point. * @param float $yCoordinate The y-coordinate of the point.
* @return float The inverse tangent of the specified x- and y-coordinates. * @return float The inverse tangent of the specified x- and y-coordinates.
*/ */
public static function ATAN2($xCoordinate, $yCoordinate) { public static function ATAN2($xCoordinate = NULL, $yCoordinate = NULL) {
$xCoordinate = (float) PHPExcel_Calculation_Functions::flattenSingleValue($xCoordinate); $xCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($xCoordinate);
$yCoordinate = (float) PHPExcel_Calculation_Functions::flattenSingleValue($yCoordinate); $yCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($yCoordinate);
$xCoordinate = ($xCoordinate !== NULL) ? $xCoordinate : 0.0;
$yCoordinate = ($yCoordinate !== NULL) ? $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)) { if (($xCoordinate == 0) && ($yCoordinate == 0)) {
return PHPExcel_Calculation_Functions::DIV0(); return PHPExcel_Calculation_Functions::DIV0();
} }
return atan2($yCoordinate, $xCoordinate); return atan2($yCoordinate, $xCoordinate);
} // function REVERSE_ATAN2() }
return PHPExcel_Calculation_Functions::VALUE();
} // function ATAN2()
/** /**
* CEILING * CEILING
* *
* Returns number rounded up, away from zero, to the nearest multiple of significance. * Returns number rounded up, away from zero, to the nearest multiple of significance.
* For example, if you want to avoid using pennies in your prices and your product is
* priced at $4.42, use the formula =CEILING(4.42,0.05) to round prices up to the
* nearest nickel.
* *
* @param float $number Number to round * Excel Function:
* @param float $significance Significance * CEILING(number[,significance])
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param float $number The number you want to round.
* @param float $significance The multiple to which you want to round.
* @return float Rounded Number * @return float Rounded Number
*/ */
public static function CEILING($number,$significance=null) { public static function CEILING($number, $significance = NULL) {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance); $significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance);
if ((is_null($significance)) && (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) { if ((is_null($significance)) &&
(PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) {
$significance = $number/abs($number); $significance = $number/abs($number);
} }
if ((is_numeric($number)) && (is_numeric($significance))) { if ((is_numeric($number)) && (is_numeric($significance))) {
if (self::SIGN($number) == self::SIGN($significance)) {
if ($significance == 0.0) { if ($significance == 0.0) {
return 0; return 0.0;
} } elseif (self::SIGN($number) == self::SIGN($significance)) {
return ceil($number / $significance) * $significance; return ceil($number / $significance) * $significance;
} else { } else {
return PHPExcel_Calculation_Functions::NaN(); return PHPExcel_Calculation_Functions::NaN();
@ -146,11 +164,16 @@ class PHPExcel_Calculation_MathTrig {
* Returns the number of combinations for a given number of items. Use COMBIN to * Returns the number of combinations for a given number of items. Use COMBIN to
* determine the total possible number of groups for a given number of items. * determine the total possible number of groups for a given number of items.
* *
* Excel Function:
* COMBIN(numObjs,numInSet)
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param int $numObjs Number of different objects * @param int $numObjs Number of different objects
* @param int $numInSet Number of objects in each combination * @param int $numInSet Number of objects in each combination
* @return int Number of combinations * @return int Number of combinations
*/ */
public static function COMBIN($numObjs,$numInSet) { public static function COMBIN($numObjs, $numInSet) {
$numObjs = PHPExcel_Calculation_Functions::flattenSingleValue($numObjs); $numObjs = PHPExcel_Calculation_Functions::flattenSingleValue($numObjs);
$numInSet = PHPExcel_Calculation_Functions::flattenSingleValue($numInSet); $numInSet = PHPExcel_Calculation_Functions::flattenSingleValue($numInSet);
@ -170,7 +193,16 @@ class PHPExcel_Calculation_MathTrig {
* EVEN * EVEN
* *
* 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,
* 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)
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param float $number Number to round * @param float $number Number to round
* @return int Rounded Number * @return int Rounded Number
*/ */
@ -195,7 +227,13 @@ class PHPExcel_Calculation_MathTrig {
* FACT * FACT
* *
* Returns the factorial of a number. * Returns the factorial of a number.
* The factorial of a number is equal to 1*2*3*...* number.
* *
* Excel Function:
* FACT(factVal)
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param float $factVal Factorial Value * @param float $factVal Factorial Value
* @return int Factorial * @return int Factorial
*/ */
@ -228,6 +266,11 @@ class PHPExcel_Calculation_MathTrig {
* *
* Returns the double factorial of a number. * Returns the double factorial of a number.
* *
* Excel Function:
* FACTDOUBLE(factVal)
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param float $factVal Factorial Value * @param float $factVal Factorial Value
* @return int Double Factorial * @return int Double Factorial
*/ */
@ -255,11 +298,16 @@ class PHPExcel_Calculation_MathTrig {
* *
* Rounds number down, toward zero, to the nearest multiple of significance. * Rounds number down, toward zero, to the nearest multiple of significance.
* *
* Excel Function:
* FLOOR(number[,significance])
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param float $number Number to round * @param float $number Number to round
* @param float $significance Significance * @param float $significance Significance
* @return float Rounded Number * @return float Rounded Number
*/ */
public static function FLOOR($number,$significance=null) { public static function FLOOR($number, $significance = NULL) {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance); $significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance);
@ -284,20 +332,27 @@ class PHPExcel_Calculation_MathTrig {
/** /**
* GCD * GCD
* *
* Returns the greatest common divisor of a series of numbers * Returns the greatest common divisor of a series of numbers.
* The greatest common divisor is the largest integer that divides both
* number1 and number2 without a remainder.
* *
* @param $array Values to calculate the Greatest Common Divisor * Excel Function:
* @return int Greatest Common Divisor * GCD(number1[,number2[, ...]])
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param mixed $arg,... Data values
* @return integer Greatest Common Divisor
*/ */
public static function GCD() { public static function GCD() {
$returnValue = 1; $returnValue = 1;
$allPoweredFactors = array(); $allValuesFactors = array();
// Loop through arguments // Loop through arguments
foreach(PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $value) { foreach(PHPExcel_Calculation_Functions::flattenArray(func_get_args()) as $value) {
if (!is_numeric($value)) { if (!is_numeric($value)) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} elseif ($value == 0) { } elseif ($value == 0) {
break; continue;
} elseif($value < 0) { } elseif($value < 0) {
return PHPExcel_Calculation_Functions::NaN(); return PHPExcel_Calculation_Functions::NaN();
} }
@ -306,6 +361,10 @@ class PHPExcel_Calculation_MathTrig {
$allValuesFactors[] = $myCountedFactors; $allValuesFactors[] = $myCountedFactors;
} }
$allValuesCount = count($allValuesFactors); $allValuesCount = count($allValuesFactors);
if ($allValuesCount == 0) {
return 0;
}
$mergedArray = $allValuesFactors[0]; $mergedArray = $allValuesFactors[0];
for ($i=1;$i < $allValuesCount; ++$i) { for ($i=1;$i < $allValuesCount; ++$i) {
$mergedArray = array_intersect_key($mergedArray,$allValuesFactors[$i]); $mergedArray = array_intersect_key($mergedArray,$allValuesFactors[$i]);
@ -351,6 +410,11 @@ class PHPExcel_Calculation_MathTrig {
* *
* Casts a floating point value to an integer * Casts a floating point value to an integer
* *
* Excel Function:
* INT(number)
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param float $number Number to cast to an integer * @param float $number Number to cast to an integer
* @return integer Integer value * @return integer Integer value
*/ */
@ -373,8 +437,16 @@ class PHPExcel_Calculation_MathTrig {
* LCM * LCM
* *
* Returns the lowest common multiplier of a series of numbers * Returns the lowest common multiplier of a series of numbers
* The least common multiple is the smallest positive integer that is a multiple
* of all integer arguments number1, number2, and so on. Use LCM to add fractions
* with different denominators.
* *
* @param $array Values to calculate the Lowest Common Multiplier * Excel Function:
* LCM(number1[,number2[, ...]])
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param mixed $arg,... Data values
* @return int Lowest Common Multiplier * @return int Lowest Common Multiplier
*/ */
public static function LCM() { public static function LCM() {
@ -427,7 +499,7 @@ class PHPExcel_Calculation_MathTrig {
* @param float $base The base of the logarithm. If base is omitted, it is assumed to be 10. * @param float $base The base of the logarithm. If base is omitted, it is assumed to be 10.
* @return float * @return float
*/ */
public static function LOG_BASE($number = NULL, $base=10) { public static function LOG_BASE($number = NULL, $base = 10) {
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$base = (is_null($base)) ? 10 : (float) PHPExcel_Calculation_Functions::flattenSingleValue($base); $base = (is_null($base)) ? 10 : (float) PHPExcel_Calculation_Functions::flattenSingleValue($base);
@ -442,6 +514,13 @@ class PHPExcel_Calculation_MathTrig {
/** /**
* MDETERM * MDETERM
* *
* Returns the matrix determinant of an array.
*
* Excel Function:
* MDETERM(array)
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param array $matrixValues A matrix of values * @param array $matrixValues A matrix of values
* @return float * @return float
*/ */
@ -476,6 +555,13 @@ class PHPExcel_Calculation_MathTrig {
/** /**
* MINVERSE * MINVERSE
* *
* Returns the inverse matrix for the matrix stored in an array.
*
* Excel Function:
* MINVERSE(array)
*
* @access public
* @category Mathematical and Trigonometric Functions
* @param array $matrixValues A matrix of values * @param array $matrixValues A matrix of values
* @return array * @return array
*/ */