Feature: Modified ERF and ERFC Engineering functions to accept Excel 2010's modified acceptance of negative arguments

This commit is contained in:
Mark Baker 2012-07-14 14:20:17 +01:00
parent 5925bc8a65
commit 1535b4d9e7
5 changed files with 202 additions and 237 deletions

View File

@ -788,7 +788,8 @@ class PHPExcel_Calculation_Engineering {
* If $ord < 0, BESSELI returns the #NUM! error value. * If $ord < 0, BESSELI returns the #NUM! error value.
* @return float * @return float
* *
* @TODO Better handling of the approximation method to support the differences between Excel/Gnumeric and Open/Libre Office * @TODO Better handling of the approximation method to support the differences between Excel/Gnumeric
* and Open/Libre Office
* *
*/ */
public static function BESSELI($x, $ord) { public static function BESSELI($x, $ord) {
@ -2261,7 +2262,12 @@ class PHPExcel_Calculation_Engineering {
/** /**
* ERF * ERF
* *
* Returns the error function integrated between lower_limit and upper_limit * Returns the error function integrated between the lower and upper bound arguments.
*
* Note: In Excel 2007 or earlier, if you input a negative value for the upper or lower bound arguments,
* the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
* improved, so that it can now calculate the function for both positive and negative ranges.
* PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
* *
* Excel Function: * Excel Function:
* ERF(lower[,upper]) * ERF(lower[,upper])
@ -2269,23 +2275,17 @@ class PHPExcel_Calculation_Engineering {
* @param float $lower lower bound for integrating ERF * @param float $lower lower bound for integrating ERF
* @param float $upper upper bound for integrating ERF. * @param float $upper upper bound for integrating ERF.
* If omitted, ERF integrates between zero and lower_limit * If omitted, ERF integrates between zero and lower_limit
* @return int * @return float
*/ */
public static function ERF($lower, $upper = null) { public static function ERF($lower, $upper = NULL) {
$lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower); $lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower);
$upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper); $upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper);
if (is_numeric($lower)) { if (is_numeric($lower)) {
if ($lower < 0) {
return PHPExcel_Calculation_Functions::NaN();
}
if (is_null($upper)) { if (is_null($upper)) {
return self::_erfVal($lower); return self::_erfVal($lower);
} }
if (is_numeric($upper)) { if (is_numeric($upper)) {
if ($upper < 0) {
return PHPExcel_Calculation_Functions::NaN();
}
return self::_erfVal($upper) - self::_erfVal($lower); return self::_erfVal($upper) - self::_erfVal($lower);
} }
} }
@ -2330,19 +2330,21 @@ class PHPExcel_Calculation_Engineering {
* *
* Returns the complementary ERF function integrated between x and infinity * Returns the complementary ERF function integrated between x and infinity
* *
* Note: In Excel 2007 or earlier, if you input a negative value for the lower bound argument,
* the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
* improved, so that it can now calculate the function for both positive and negative x values.
* PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
*
* Excel Function: * Excel Function:
* ERF(x) * ERF(x)
* *
* @param float $x The lower bound for integrating ERF * @param float $x The lower bound for integrating ERF
* @return int * @return float
*/ */
public static function ERFC($x) { public static function ERFC($x) {
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
if (is_numeric($x)) { if (is_numeric($x)) {
if ($x < 0) {
return PHPExcel_Calculation_Functions::NaN();
}
return self::_erfcVal($x); return self::_erfcVal($x);
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();

View File

@ -30,6 +30,7 @@ Fixed in develop branch:
tcPDF Library has now been removed from the deployment bundle tcPDF Library has now been removed from the deployment bundle
- Feature: (MBaker) Initial version of HTML Reader - Feature: (MBaker) Initial version of HTML Reader
- Feature: (Progi1984) & (blazzy) Work items 9605 - Implement support for AutoFilter in PHPExcel_Writer_Excel5 - Feature: (Progi1984) & (blazzy) Work items 9605 - Implement support for AutoFilter in PHPExcel_Writer_Excel5
- Feature: (MBaker) Modified ERF and ERFC Engineering functions to accept Excel 2010's modified acceptance of negative arguments
- Bugfix: (cyberconte) Patch 12318 - OOCalc cells containing <text:span> inside the <text:p> tag - Bugfix: (cyberconte) Patch 12318 - OOCalc cells containing <text:span> inside the <text:p> tag
- Bugfix: (schir1964) Fix to listWorksheetInfo() method for OOCalc Reader - Bugfix: (schir1964) Fix to listWorksheetInfo() method for OOCalc Reader
- Bugfix: (MBaker) Support for "e" (epoch) date format mask - Bugfix: (MBaker) Support for "e" (epoch) date format mask

View File

@ -405,7 +405,7 @@ class EngineeringTest extends PHPUnit_Framework_TestCase
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Calculation_Engineering','ERF'),$args); $result = call_user_func_array(array('PHPExcel_Calculation_Engineering','ERF'),$args);
$this->assertEquals($expectedResult, $result, NULL, 1E-6); $this->assertEquals($expectedResult, $result, NULL, 1E-12);
} }
public function providerERF() public function providerERF()
@ -421,7 +421,7 @@ class EngineeringTest extends PHPUnit_Framework_TestCase
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Calculation_Engineering','ERFC'),$args); $result = call_user_func_array(array('PHPExcel_Calculation_Engineering','ERFC'),$args);
$this->assertEquals($expectedResult, $result, NULL, 1E-6); $this->assertEquals($expectedResult, $result, NULL, 1E-12);
} }
public function providerERFC() public function providerERFC()

View File

@ -1,3 +1,4 @@
# lower bound upper bound Result
0, 0.0 0, 0.0
0.01, 0.0112834155558496 0.01, 0.0112834155558496
0.05, 0.0563719777970166 0.05, 0.0563719777970166
@ -36,86 +37,88 @@
-1, -0.8427007929497150 -1, -0.8427007929497150
TRUE, "#VALUE!" TRUE, "#VALUE!"
FALSE, "#VALUE!" FALSE, "#VALUE!"
2, 0.9953222650189530 "2", 0.9953222650189530
"TWO", "#VALUE!" "TWO", "#VALUE!"
-1.5, -1.5, 0 -1.5, -1.5, 0.0
-0.75, -1.5, -0.254949513 -0.75, -1.5, -0.2549495128217960
0, -1.5, -0.966105146 0, -1.5, -0.9661051464753110
0.75, -1.5, -1.67726078 0.75, -1.5, -1.6772607801288300
1.5, -1.5, -1.932210293 1.5, -1.5, -1.9322102929506200
2.25, -1.5, -1.96464243 2.25, -1.5, -1.9646424298886300
3, -1.5, -1.966083056 3, -1.5, -1.9660830559783100
3.75, -1.5, -1.966105033 3.75, -1.5, -1.9661050327480500
4.5, -1.5, -1.966105146 4.5, -1.5, -1.9661051462786900
-1.5, -0.75, 0.254949513 -1.5, -0.75, 0.2549495128217960
-0.75, -0.75, 0 -0.75, -0.75, 0.0
0, -0.75, -0.711155634 0, -0.75, -0.7111556336535150
0.75, -0.75, -1.422311267 0.75, -0.75, -1.4223112673070300
1.5, -0.75, -1.67726078 1.5, -0.75, -1.6772607801288300
2.25, -0.75, -1.709692917 2.25, -0.75, -1.7096929170668300
3, -0.75, -1.711133543 3, -0.75, -1.7111335431565200
3.75, -0.75, -1.71115552 3.75, -0.75, -1.7111555199262600
4.5, -0.75, -1.711155633 4.5, -0.75, -1.7111556334569000
-1.5, 0, 0.966105146 -1.5, 0, 0.9661051464753110
-0.75, 0, 0.711155634 -0.75, 0, 0.7111556336535150
0, 0, 0 0, 0, 0.0
0.75, 0, -0.711155634 0.75, 0, -0.7111556336535150
1.5, 0, -0.966105146 1.5, 0, -0.9661051464753110
2.25, 0, -0.998537283 2.25, 0, -0.9985372834133190
3, 0, -0.99997791 3, 0, -0.9999779095030010
3.75, 0, -0.999999886 3.75, 0, -0.9999998862727430
4.5, 0, -1 4.5, 0, -0.9999999998033840
-1.5, 0.75, 1.67726078 -1.5, 0.75, 1.6772607801288300
-0.75, 0.75, 1.422311267 -0.75, 0.75, 1.4223112673070300
0, 0.75, 0.711155634 0, 0.75, 0.7111556336535150
0.75, 0.75, 0 0.75, 0.75, 0.0
1.5, 0.75, -0.254949513 1.5, 0.75, -0.2549495128217960
2.25, 0.75, -0.28738165 2.25, 0.75, -0.2873816497598040
3, 0.75, -0.288822276 3, 0.75, -0.2888222758494860
3.75, 0.75, -0.288844253 3.75, 0.75, -0.2888442526192280
4.5, 0.75, -0.288844366 4.5, 0.75, -0.2888443661498690
-1.5, 1.5, 1.932210293 -1.5, 1.5, 1.9322102929506200
-0.75, 1.5, 1.67726078 -0.75, 1.5, 1.6772607801288300
0, 1.5, 0.966105146 0, 1.5, 0.9661051464753110
0.75, 1.5, 0.254949513 0.75, 1.5, 0.2549495128217960
1.5, 1.5, 0 1.5, 1.5, 0.0
2.25, 1.5, -0.032432137 2.25, 1.5, -0.0324321369380081
3, 1.5, -0.033872763 3, 1.5, -0.0338727630276906
3.75, 1.5, -0.03389474 3.75, 1.5, -0.0338947397974326
4.5, 1.5, -0.033894853 4.5, 1.5, -0.0338948533280732
-1.5, 2.25, 1.96464243 -1.5, 2.25, 1.9646424298886300
-0.75, 2.25, 1.709692917 -0.75, 2.25, 1.7096929170668300
0, 2.25, 0.998537283 0, 2.25, 0.9985372834133190
0.75, 2.25, 0.28738165 0.75, 2.25, 0.2873816497598040
1.5, 2.25, 0.032432137 1.5, 2.25, 0.0324321369380081
2.25, 2.25, 0 2.25, 2.25, 0.0
3, 2.25, -0.001440626 3, 2.25, -0.0014406260896825
3.75, 2.25, -0.001462603 3.75, 2.25, -0.0014626028594246
4.5, 2.25, -0.001462716 4.5, 2.25, -0.0014627163900651
-1.5, 3, 1.966083056 -1.5, 3, 1.9660830559783100
-0.75, 3, 1.711133543 -0.75, 3, 1.7111335431565200
0, 3, 0.99997791 0, 3, 0.9999779095030010
0.75, 3, 0.288822276 0.75, 3, 0.2888222758494860
1.5, 3, 0.033872763 1.5, 3, 0.0338727630276906
2.25, 3, 0.001440626 2.25, 3, 0.0014406260896825
3, 3, 0 3, 3, 0.0
3.75, 3, -2.19768E-05 3.75, 3, -0.0000219767697420
4.5, 3, -2.20903E-05 4.5, 3, -0.0000220903003826
-1.5, 3.75, 1.966105033 -1.5, 3.75, 1.9661050327480500
-0.75, 3.75, 1.71115552 -0.75, 3.75, 1.7111555199262600
0, 3.75, 0.999999886 0, 3.75, 0.9999998862727430
0.75, 3.75, 0.288844253 0.75, 3.75, 0.2888442526192280
1.5, 3.75, 0.03389474 1.5, 3.75, 0.0338947397974326
2.25, 3.75, 0.001462603 2.25, 3.75, 0.0014626028594246
3, 3.75, 2.19768E-05 3, 3.75, 0.0000219767697420
3.75, 3.75, 0 3.75, 3.75, 0.0
4.5, 3.75, -1.13531E-07 4.5, 3.75, -0.0000001135306406
-1.5, 4.5, 1.966105146 -1.5, 4.5, 1.9661051462786900
-0.75, 4.5, 1.711155633 -0.75, 4.5, 1.7111556334569000
0, 4.5, 1 0, 4.5, 0.9999999998033840
0.75, 4.5, 0.288844366 0.75, 4.5, 0.2888443661498690
1.5, 4.5, 0.033894853 1.5, 4.5, 0.0338948533280732
2.25, 4.5, 0.001462716 2.25, 4.5, 0.0014627163900651
3, 4.5, 2.20903E-05 3, 4.5, 0.0000220903003826
3.75, 4.5, 1.13531E-07 3.75, 4.5, 0.0000001135306406
4.5, 4.5, 0 4.5, 4.5, 0.0
5, -1, -1.8427007929481800
-5, 1, 1.8427007929481800

View File

@ -1,82 +1,41 @@
-2.5, 5, 0 # x value Result
-1.5, -1.5, 0 0, 1.0
-0.75, -1.5, 0 0.01, 0.9887165844441500
0, -1.5, 0 0.05, 0.9436280222029830
0.75, -1.5, 0.288844366 0.1, 0.8875370839817150
1.5, -1.5, 0.033894854 0.125, 0.8596837951986660
2.25, -1.5, 0.001462717 0.15, 0.8320040285726360
3, -1.5, 2.20905E-05 0.2, 0.7772974107895220
3.75, -1.5, 1.13727E-07 0.25, 0.7236736098317630
4.5, -1.5, 1.96616E-10 0.3, 0.6713732405408730
-1.5, -0.75, 0 0.35, 0.6206179464376900
-0.75, -0.75, 0 0.4, 0.5716076449533320
0, -0.75, 0 0.45, 0.5245182802130760
0.75, -0.75, 0.288844366 0.5, 0.4795001221869530
1.5, -0.75, 0.033894854 0.6, 0.3961439091520740
2.25, -0.75, 0.001462717 0.7, 0.3221988061625820
3, -0.75, 2.20905E-05 0.8, 0.2578990352923390
3.75, -0.75, 1.13727E-07 0.9, 0.2030917875771680
4.5, -0.75, 1.96616E-10 1, 0.1572992070502850
-1.5, 0, 0 1.1, 0.1197949304259180
-0.75, 0, 0 1.2, 0.0896860217703646
0, 0, 0 1.3, 0.0659920550593475
0.75, 0, 0.288844366 1.4, 0.0477148802373512
1.5, 0, 0.033894854 1.5, 0.0338948535246893
2.25, 0, 0.001462717 1.75, 0.0133283287808176
3, 0, 2.20905E-05 2, 0.0046777349810473
3.75, 0, 1.13727E-07 2.5, 0.0004069520174450
4.5, 0, 1.96616E-10 3, 0.0000220904969986
-1.5, 0.75, 0 3.5, 0.0000007430983723
-0.75, 0.75, 0 4, 0.0000000154172579
0, 0.75, 0 4.5, 0.0000000001966160
0.75, 0.75, 0.288844366 5, 0.0000000000015375
1.5, 0.75, 0.033894854 5.5, 0.0000000000000074
2.25, 0.75, 0.001462717 6, 0.0
3, 0.75, 2.20905E-05 32, 0.0
3.75, 0.75, 1.13727E-07 -0.1, 1.1124629160182900
4.5, 0.75, 1.96616E-10 -1, 1.8427007929497100
-1.5, 1.5, 0 TRUE, "#VALUE!"
-0.75, 1.5, 0 FALSE, "#VALUE!"
0, 1.5, 0 "2", 0.0046777349810473
0.75, 1.5, 0.288844366 "TWO", "#VALUE!"
1.5, 1.5, 0.033894854
2.25, 1.5, 0.001462717
3, 1.5, 2.20905E-05
3.75, 1.5, 1.13727E-07
4.5, 1.5, 1.96616E-10
-1.5, 2.25, 0
-0.75, 2.25, 0
0, 2.25, 0
0.75, 2.25, 0.288844366
1.5, 2.25, 0.033894854
2.25, 2.25, 0.001462717
3, 2.25, 2.20905E-05
3.75, 2.25, 1.13727E-07
4.5, 2.25, 1.96616E-10
-1.5, 3, 0
-0.75, 3, 0
0, 3, 0
0.75, 3, 0.288844366
1.5, 3, 0.033894854
2.25, 3, 0.001462717
3, 3, 2.20905E-05
3.75, 3, 1.13727E-07
4.5, 3, 1.96616E-10
-1.5, 3.75, 0
-0.75, 3.75, 0
0, 3.75, 0
0.75, 3.75, 0.288844366
1.5, 3.75, 0.033894854
2.25, 3.75, 0.001462717
3, 3.75, 2.20905E-05
3.75, 3.75, 1.13727E-07
4.5, 3.75, 1.96616E-10
-1.5, 4.5, 0
-0.75, 4.5, 0
0, 4.5, 0
0.75, 4.5, 0.288844366
1.5, 4.5, 0.033894854
2.25, 4.5, 0.001462717
3, 4.5, 2.20905E-05
3.75, 4.5, 1.13727E-07
4.5, 4.5, 1.96616E-10