Refactor `define()` as class constants
This will improve interoperability with other projects and simplify our code. Closes #157
This commit is contained in:
parent
07455d24f6
commit
44e2461b7b
|
@ -14,21 +14,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\TextData;
|
use PhpOffice\PhpSpreadsheet\Calculation\TextData;
|
||||||
|
|
||||||
if (!defined('CALCULATION_REGEXP_CELLREF')) {
|
|
||||||
// Test for support of \P (multibyte options) in PCRE
|
|
||||||
if (defined('PREG_BAD_UTF8_ERROR')) {
|
|
||||||
// Cell reference (cell or range of cells, with or without a sheet reference)
|
|
||||||
define('CALCULATION_REGEXP_CELLREF', '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})');
|
|
||||||
// Named Range of cells
|
|
||||||
define('CALCULATION_REGEXP_NAMEDRANGE', '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)');
|
|
||||||
} else {
|
|
||||||
// Cell reference (cell or range of cells, with or without a sheet reference)
|
|
||||||
define('CALCULATION_REGEXP_CELLREF', '(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)');
|
|
||||||
// Named Range of cells
|
|
||||||
define('CALCULATION_REGEXP_NAMEDRANGE', '(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9\.]*)');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
||||||
*
|
*
|
||||||
|
@ -64,9 +49,9 @@ class Calculation
|
||||||
// Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it)
|
// Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it)
|
||||||
const CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\.]*)[\s]*\(';
|
const CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\.]*)[\s]*\(';
|
||||||
// Cell reference (cell or range of cells, with or without a sheet reference)
|
// Cell reference (cell or range of cells, with or without a sheet reference)
|
||||||
const CALCULATION_REGEXP_CELLREF = CALCULATION_REGEXP_CELLREF;
|
const CALCULATION_REGEXP_CELLREF = '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})';
|
||||||
// Named Range of cells
|
// Named Range of cells
|
||||||
const CALCULATION_REGEXP_NAMEDRANGE = CALCULATION_REGEXP_NAMEDRANGE;
|
const CALCULATION_REGEXP_NAMEDRANGE = '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)';
|
||||||
// Error
|
// Error
|
||||||
const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?';
|
const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?';
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation;
|
namespace PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
|
||||||
/* EULER */
|
|
||||||
define('EULER', 2.71828182845904523536);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
||||||
*
|
*
|
||||||
|
@ -29,6 +26,11 @@ define('EULER', 2.71828182845904523536);
|
||||||
*/
|
*/
|
||||||
class Engineering
|
class Engineering
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* EULER.
|
||||||
|
*/
|
||||||
|
const EULER = 2.71828182845904523536;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Details of the Units of measure that can be used in CONVERTUOM().
|
* Details of the Units of measure that can be used in CONVERTUOM().
|
||||||
*
|
*
|
||||||
|
@ -944,7 +946,7 @@ class Engineering
|
||||||
$f_PI_DIV_4 = M_PI / 4;
|
$f_PI_DIV_4 = M_PI / 4;
|
||||||
|
|
||||||
$fXAbs = abs($x);
|
$fXAbs = abs($x);
|
||||||
$fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4);
|
$fResult = sqrt(Functions::M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4);
|
||||||
if (($ord & 1) && ($x < 0)) {
|
if (($ord & 1) && ($x < 0)) {
|
||||||
$fResult = -$fResult;
|
$fResult = -$fResult;
|
||||||
}
|
}
|
||||||
|
@ -2103,7 +2105,7 @@ class Engineering
|
||||||
return log10($parsedComplex['real']);
|
return log10($parsedComplex['real']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::IMPRODUCT(log10(EULER), self::IMLN($complexNumber));
|
return self::IMPRODUCT(log10(self::EULER), self::IMLN($complexNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2130,7 +2132,7 @@ class Engineering
|
||||||
return log($parsedComplex['real'], 2);
|
return log($parsedComplex['real'], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::IMPRODUCT(log(EULER, 2), self::IMLN($complexNumber));
|
return self::IMPRODUCT(log(self::EULER, 2), self::IMLN($complexNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2434,7 +2436,7 @@ class Engineering
|
||||||
if ($sum == 0.0) {
|
if ($sum == 0.0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (abs($term / $sum) > PRECISION);
|
} while (abs($term / $sum) > Functions::PRECISION);
|
||||||
|
|
||||||
return self::$twoSqrtPi * $sum;
|
return self::$twoSqrtPi * $sum;
|
||||||
}
|
}
|
||||||
|
@ -2503,7 +2505,7 @@ class Engineering
|
||||||
$n += 0.5;
|
$n += 0.5;
|
||||||
$q1 = $q2;
|
$q1 = $q2;
|
||||||
$q2 = $b / $d;
|
$q2 = $b / $d;
|
||||||
} while ((abs($q1 - $q2) / $q2) > PRECISION);
|
} while ((abs($q1 - $q2) / $q2) > Functions::PRECISION);
|
||||||
|
|
||||||
return self::$oneSqrtPi * exp(-$x * $x) * $q2;
|
return self::$oneSqrtPi * exp(-$x * $x) * $q2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation;
|
namespace PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
|
||||||
/* FINANCIAL_MAX_ITERATIONS */
|
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
|
||||||
define('FINANCIAL_MAX_ITERATIONS', 128);
|
|
||||||
|
|
||||||
/* FINANCIAL_PRECISION */
|
|
||||||
define('FINANCIAL_PRECISION', 1.0e-08);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
||||||
*
|
*
|
||||||
|
@ -34,6 +28,10 @@ define('FINANCIAL_PRECISION', 1.0e-08);
|
||||||
*/
|
*/
|
||||||
class Financial
|
class Financial
|
||||||
{
|
{
|
||||||
|
const FINANCIAL_MAX_ITERATIONS = 128;
|
||||||
|
|
||||||
|
const FINANCIAL_PRECISION = 1.0e-08;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* isLastDayOfMonth.
|
* isLastDayOfMonth.
|
||||||
*
|
*
|
||||||
|
@ -1428,7 +1426,7 @@ class Financial
|
||||||
$x2 = $guess;
|
$x2 = $guess;
|
||||||
$f1 = self::NPV($x1, $values);
|
$f1 = self::NPV($x1, $values);
|
||||||
$f2 = self::NPV($x2, $values);
|
$f2 = self::NPV($x2, $values);
|
||||||
for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) {
|
for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) {
|
||||||
if (($f1 * $f2) < 0.0) {
|
if (($f1 * $f2) < 0.0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1451,14 +1449,14 @@ class Financial
|
||||||
$dx = $x1 - $x2;
|
$dx = $x1 - $x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) {
|
for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) {
|
||||||
$dx *= 0.5;
|
$dx *= 0.5;
|
||||||
$x_mid = $rtb + $dx;
|
$x_mid = $rtb + $dx;
|
||||||
$f_mid = self::NPV($x_mid, $values);
|
$f_mid = self::NPV($x_mid, $values);
|
||||||
if ($f_mid <= 0.0) {
|
if ($f_mid <= 0.0) {
|
||||||
$rtb = $x_mid;
|
$rtb = $x_mid;
|
||||||
}
|
}
|
||||||
if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) {
|
if ((abs($f_mid) < self::FINANCIAL_PRECISION) || (abs($dx) < self::FINANCIAL_PRECISION)) {
|
||||||
return $x_mid;
|
return $x_mid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1965,7 +1963,7 @@ class Financial
|
||||||
$guess = (is_null($guess)) ? 0.1 : Functions::flattenSingleValue($guess);
|
$guess = (is_null($guess)) ? 0.1 : Functions::flattenSingleValue($guess);
|
||||||
|
|
||||||
$rate = $guess;
|
$rate = $guess;
|
||||||
if (abs($rate) < FINANCIAL_PRECISION) {
|
if (abs($rate) < self::FINANCIAL_PRECISION) {
|
||||||
$y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv;
|
$y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv;
|
||||||
} else {
|
} else {
|
||||||
$f = exp($nper * log(1 + $rate));
|
$f = exp($nper * log(1 + $rate));
|
||||||
|
@ -1977,14 +1975,14 @@ class Financial
|
||||||
// find root by secant method
|
// find root by secant method
|
||||||
$i = $x0 = 0.0;
|
$i = $x0 = 0.0;
|
||||||
$x1 = $rate;
|
$x1 = $rate;
|
||||||
while ((abs($y0 - $y1) > FINANCIAL_PRECISION) && ($i < FINANCIAL_MAX_ITERATIONS)) {
|
while ((abs($y0 - $y1) > self::FINANCIAL_PRECISION) && ($i < self::FINANCIAL_MAX_ITERATIONS)) {
|
||||||
$rate = ($y1 * $x0 - $y0 * $x1) / ($y1 - $y0);
|
$rate = ($y1 * $x0 - $y0 * $x1) / ($y1 - $y0);
|
||||||
$x0 = $x1;
|
$x0 = $x1;
|
||||||
$x1 = $rate;
|
$x1 = $rate;
|
||||||
if (($nper * abs($pmt)) > ($pv - $fv)) {
|
if (($nper * abs($pmt)) > ($pv - $fv)) {
|
||||||
$x1 = abs($x1);
|
$x1 = abs($x1);
|
||||||
}
|
}
|
||||||
if (abs($rate) < FINANCIAL_PRECISION) {
|
if (abs($rate) < self::FINANCIAL_PRECISION) {
|
||||||
$y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv;
|
$y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv;
|
||||||
} else {
|
} else {
|
||||||
$f = exp($nper * log(1 + $rate));
|
$f = exp($nper * log(1 + $rate));
|
||||||
|
@ -2282,7 +2280,7 @@ class Financial
|
||||||
$x2 = $guess;
|
$x2 = $guess;
|
||||||
$f1 = self::XNPV($x1, $values, $dates);
|
$f1 = self::XNPV($x1, $values, $dates);
|
||||||
$f2 = self::XNPV($x2, $values, $dates);
|
$f2 = self::XNPV($x2, $values, $dates);
|
||||||
for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) {
|
for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) {
|
||||||
if (($f1 * $f2) < 0.0) {
|
if (($f1 * $f2) < 0.0) {
|
||||||
break;
|
break;
|
||||||
} elseif (abs($f1) < abs($f2)) {
|
} elseif (abs($f1) < abs($f2)) {
|
||||||
|
@ -2304,14 +2302,14 @@ class Financial
|
||||||
$dx = $x1 - $x2;
|
$dx = $x1 - $x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) {
|
for ($i = 0; $i < self::FINANCIAL_MAX_ITERATIONS; ++$i) {
|
||||||
$dx *= 0.5;
|
$dx *= 0.5;
|
||||||
$x_mid = $rtb + $dx;
|
$x_mid = $rtb + $dx;
|
||||||
$f_mid = self::XNPV($x_mid, $values, $dates);
|
$f_mid = self::XNPV($x_mid, $values, $dates);
|
||||||
if ($f_mid <= 0.0) {
|
if ($f_mid <= 0.0) {
|
||||||
$rtb = $x_mid;
|
$rtb = $x_mid;
|
||||||
}
|
}
|
||||||
if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) {
|
if ((abs($f_mid) < self::FINANCIAL_PRECISION) || (abs($dx) < self::FINANCIAL_PRECISION)) {
|
||||||
return $x_mid;
|
return $x_mid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation;
|
namespace PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
|
||||||
/* MAX_VALUE */
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
|
||||||
define('MAX_VALUE', 1.2e308);
|
|
||||||
|
|
||||||
/* 2 / PI */
|
|
||||||
define('M_2DIVPI', 0.63661977236758134307553505349006);
|
|
||||||
|
|
||||||
/* MAX_ITERATIONS */
|
|
||||||
define('MAX_ITERATIONS', 256);
|
|
||||||
|
|
||||||
/* PRECISION */
|
|
||||||
define('PRECISION', 8.88E-016);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
||||||
*
|
*
|
||||||
|
@ -40,11 +28,17 @@ define('PRECISION', 8.88E-016);
|
||||||
*/
|
*/
|
||||||
class Functions
|
class Functions
|
||||||
{
|
{
|
||||||
|
const PRECISION = 8.88E-016;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2 / PI.
|
||||||
|
*/
|
||||||
|
const M_2DIVPI = 0.63661977236758134307553505349006;
|
||||||
|
|
||||||
/** constants */
|
/** constants */
|
||||||
const COMPATIBILITY_EXCEL = 'Excel';
|
const COMPATIBILITY_EXCEL = 'Excel';
|
||||||
const COMPATIBILITY_GNUMERIC = 'Gnumeric';
|
const COMPATIBILITY_GNUMERIC = 'Gnumeric';
|
||||||
const COMPATIBILITY_OPENOFFICE = 'OpenOfficeCalc';
|
const COMPATIBILITY_OPENOFFICE = 'OpenOfficeCalc';
|
||||||
|
|
||||||
const RETURNDATE_PHP_NUMERIC = 'P';
|
const RETURNDATE_PHP_NUMERIC = 'P';
|
||||||
const RETURNDATE_PHP_OBJECT = 'O';
|
const RETURNDATE_PHP_OBJECT = 'O';
|
||||||
const RETURNDATE_EXCEL = 'E';
|
const RETURNDATE_EXCEL = 'E';
|
||||||
|
|
|
@ -2,21 +2,9 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Calculation;
|
namespace PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
|
||||||
/* LOG_GAMMA_X_MAX_VALUE */
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Trend\Trend;
|
use PhpOffice\PhpSpreadsheet\Shared\Trend\Trend;
|
||||||
|
|
||||||
define('LOG_GAMMA_X_MAX_VALUE', 2.55e305);
|
|
||||||
|
|
||||||
/* XMININ */
|
|
||||||
define('XMININ', 2.23e-308);
|
|
||||||
|
|
||||||
/* EPS */
|
|
||||||
define('EPS', 2.22e-16);
|
|
||||||
|
|
||||||
/* SQRT2PI */
|
|
||||||
define('SQRT2PI', 2.5066282746310005024157652848110452530069867406099);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
||||||
*
|
*
|
||||||
|
@ -41,6 +29,13 @@ define('SQRT2PI', 2.5066282746310005024157652848110452530069867406099);
|
||||||
*/
|
*/
|
||||||
class Statistical
|
class Statistical
|
||||||
{
|
{
|
||||||
|
const LOG_GAMMA_X_MAX_VALUE = 2.55e305;
|
||||||
|
const XMININ = 2.23e-308;
|
||||||
|
const EPS = 2.22e-16;
|
||||||
|
const MAX_VALUE = 1.2e308;
|
||||||
|
const MAX_ITERATIONS = 256;
|
||||||
|
const SQRT2PI = 2.5066282746310005024157652848110452530069867406099;
|
||||||
|
|
||||||
private static function checkTrendArrays(&$array1, &$array2)
|
private static function checkTrendArrays(&$array1, &$array2)
|
||||||
{
|
{
|
||||||
if (!is_array($array1)) {
|
if (!is_array($array1)) {
|
||||||
|
@ -82,7 +77,7 @@ class Statistical
|
||||||
*/
|
*/
|
||||||
private static function beta($p, $q)
|
private static function beta($p, $q)
|
||||||
{
|
{
|
||||||
if ($p <= 0.0 || $q <= 0.0 || ($p + $q) > LOG_GAMMA_X_MAX_VALUE) {
|
if ($p <= 0.0 || $q <= 0.0 || ($p + $q) > self::LOG_GAMMA_X_MAX_VALUE) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +107,7 @@ class Statistical
|
||||||
return 0.0;
|
return 0.0;
|
||||||
} elseif ($x >= 1.0) {
|
} elseif ($x >= 1.0) {
|
||||||
return 1.0;
|
return 1.0;
|
||||||
} elseif (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > LOG_GAMMA_X_MAX_VALUE)) {
|
} elseif (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > self::LOG_GAMMA_X_MAX_VALUE)) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
$beta_gam = exp((0 - self::logBeta($p, $q)) + $p * log($x) + $q * log(1.0 - $x));
|
$beta_gam = exp((0 - self::logBeta($p, $q)) + $p * log($x) + $q * log(1.0 - $x));
|
||||||
|
@ -145,7 +140,7 @@ class Statistical
|
||||||
if ($p != self::$logBetaCacheP || $q != self::$logBetaCacheQ) {
|
if ($p != self::$logBetaCacheP || $q != self::$logBetaCacheQ) {
|
||||||
self::$logBetaCacheP = $p;
|
self::$logBetaCacheP = $p;
|
||||||
self::$logBetaCacheQ = $q;
|
self::$logBetaCacheQ = $q;
|
||||||
if (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > LOG_GAMMA_X_MAX_VALUE)) {
|
if (($p <= 0.0) || ($q <= 0.0) || (($p + $q) > self::LOG_GAMMA_X_MAX_VALUE)) {
|
||||||
self::$logBetaCacheResult = 0.0;
|
self::$logBetaCacheResult = 0.0;
|
||||||
} else {
|
} else {
|
||||||
self::$logBetaCacheResult = self::logGamma($p) + self::logGamma($q) - self::logGamma($p + $q);
|
self::$logBetaCacheResult = self::logGamma($p) + self::logGamma($q) - self::logGamma($p + $q);
|
||||||
|
@ -172,37 +167,37 @@ class Statistical
|
||||||
$p_plus = $p + 1.0;
|
$p_plus = $p + 1.0;
|
||||||
$p_minus = $p - 1.0;
|
$p_minus = $p - 1.0;
|
||||||
$h = 1.0 - $sum_pq * $x / $p_plus;
|
$h = 1.0 - $sum_pq * $x / $p_plus;
|
||||||
if (abs($h) < XMININ) {
|
if (abs($h) < self::XMININ) {
|
||||||
$h = XMININ;
|
$h = self::XMININ;
|
||||||
}
|
}
|
||||||
$h = 1.0 / $h;
|
$h = 1.0 / $h;
|
||||||
$frac = $h;
|
$frac = $h;
|
||||||
$m = 1;
|
$m = 1;
|
||||||
$delta = 0.0;
|
$delta = 0.0;
|
||||||
while ($m <= MAX_ITERATIONS && abs($delta - 1.0) > PRECISION) {
|
while ($m <= self::MAX_ITERATIONS && abs($delta - 1.0) > Functions::PRECISION) {
|
||||||
$m2 = 2 * $m;
|
$m2 = 2 * $m;
|
||||||
// even index for d
|
// even index for d
|
||||||
$d = $m * ($q - $m) * $x / (($p_minus + $m2) * ($p + $m2));
|
$d = $m * ($q - $m) * $x / (($p_minus + $m2) * ($p + $m2));
|
||||||
$h = 1.0 + $d * $h;
|
$h = 1.0 + $d * $h;
|
||||||
if (abs($h) < XMININ) {
|
if (abs($h) < self::XMININ) {
|
||||||
$h = XMININ;
|
$h = self::XMININ;
|
||||||
}
|
}
|
||||||
$h = 1.0 / $h;
|
$h = 1.0 / $h;
|
||||||
$c = 1.0 + $d / $c;
|
$c = 1.0 + $d / $c;
|
||||||
if (abs($c) < XMININ) {
|
if (abs($c) < self::XMININ) {
|
||||||
$c = XMININ;
|
$c = self::XMININ;
|
||||||
}
|
}
|
||||||
$frac *= $h * $c;
|
$frac *= $h * $c;
|
||||||
// odd index for d
|
// odd index for d
|
||||||
$d = -($p + $m) * ($sum_pq + $m) * $x / (($p + $m2) * ($p_plus + $m2));
|
$d = -($p + $m) * ($sum_pq + $m) * $x / (($p + $m2) * ($p_plus + $m2));
|
||||||
$h = 1.0 + $d * $h;
|
$h = 1.0 + $d * $h;
|
||||||
if (abs($h) < XMININ) {
|
if (abs($h) < self::XMININ) {
|
||||||
$h = XMININ;
|
$h = self::XMININ;
|
||||||
}
|
}
|
||||||
$h = 1.0 / $h;
|
$h = 1.0 / $h;
|
||||||
$c = 1.0 + $d / $c;
|
$c = 1.0 + $d / $c;
|
||||||
if (abs($c) < XMININ) {
|
if (abs($c) < self::XMININ) {
|
||||||
$c = XMININ;
|
$c = self::XMININ;
|
||||||
}
|
}
|
||||||
$delta = $h * $c;
|
$delta = $h * $c;
|
||||||
$frac *= $delta;
|
$frac *= $delta;
|
||||||
|
@ -346,8 +341,8 @@ class Statistical
|
||||||
return self::$logGammaCacheResult;
|
return self::$logGammaCacheResult;
|
||||||
}
|
}
|
||||||
$y = $x;
|
$y = $x;
|
||||||
if ($y > 0.0 && $y <= LOG_GAMMA_X_MAX_VALUE) {
|
if ($y > 0.0 && $y <= self::LOG_GAMMA_X_MAX_VALUE) {
|
||||||
if ($y <= EPS) {
|
if ($y <= self::EPS) {
|
||||||
$res = -log(y);
|
$res = -log(y);
|
||||||
} elseif ($y <= 1.5) {
|
} elseif ($y <= 1.5) {
|
||||||
// ---------------------
|
// ---------------------
|
||||||
|
@ -415,7 +410,7 @@ class Statistical
|
||||||
}
|
}
|
||||||
$res /= $y;
|
$res /= $y;
|
||||||
$corr = log($y);
|
$corr = log($y);
|
||||||
$res = $res + log(SQRT2PI) - 0.5 * $corr;
|
$res = $res + log(self::SQRT2PI) - 0.5 * $corr;
|
||||||
$res += $y * ($corr - 1.0);
|
$res += $y * ($corr - 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,7 +418,7 @@ class Statistical
|
||||||
// --------------------------
|
// --------------------------
|
||||||
// Return for bad arguments
|
// Return for bad arguments
|
||||||
// --------------------------
|
// --------------------------
|
||||||
$res = MAX_VALUE;
|
$res = self::MAX_VALUE;
|
||||||
}
|
}
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
// Final adjustments and return
|
// Final adjustments and return
|
||||||
|
@ -480,7 +475,7 @@ class Statistical
|
||||||
$summer += ($p[$j] / ++$y);
|
$summer += ($p[$j] / ++$y);
|
||||||
}
|
}
|
||||||
|
|
||||||
return exp(0 - $tmp + log(SQRT2PI * $summer / $x));
|
return exp(0 - $tmp + log(self::SQRT2PI * $summer / $x));
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
|
@ -977,7 +972,7 @@ class Statistical
|
||||||
$b = 2;
|
$b = 2;
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ((($b - $a) > PRECISION) && ($i++ < MAX_ITERATIONS)) {
|
while ((($b - $a) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) {
|
||||||
$guess = ($a + $b) / 2;
|
$guess = ($a + $b) / 2;
|
||||||
$result = self::BETADIST($guess, $alpha, $beta);
|
$result = self::BETADIST($guess, $alpha, $beta);
|
||||||
if (($result == $probability) || ($result == 0)) {
|
if (($result == $probability) || ($result == 0)) {
|
||||||
|
@ -988,7 +983,7 @@ class Statistical
|
||||||
$a = $guess;
|
$a = $guess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($i == MAX_ITERATIONS) {
|
if ($i == self::MAX_ITERATIONS) {
|
||||||
return Functions::NA();
|
return Functions::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1102,7 +1097,7 @@ class Statistical
|
||||||
$dx = 1;
|
$dx = 1;
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while ((abs($dx) > PRECISION) && ($i++ < MAX_ITERATIONS)) {
|
while ((abs($dx) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) {
|
||||||
// Apply Newton-Raphson step
|
// Apply Newton-Raphson step
|
||||||
$result = self::CHIDIST($x, $degrees);
|
$result = self::CHIDIST($x, $degrees);
|
||||||
$error = $result - $probability;
|
$error = $result - $probability;
|
||||||
|
@ -1127,7 +1122,7 @@ class Statistical
|
||||||
}
|
}
|
||||||
$x = $xNew;
|
$x = $xNew;
|
||||||
}
|
}
|
||||||
if ($i == MAX_ITERATIONS) {
|
if ($i == self::MAX_ITERATIONS) {
|
||||||
return Functions::NA();
|
return Functions::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1721,7 +1716,7 @@ class Statistical
|
||||||
$dx = 1024;
|
$dx = 1024;
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while ((abs($dx) > PRECISION) && ($i++ < MAX_ITERATIONS)) {
|
while ((abs($dx) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) {
|
||||||
// Apply Newton-Raphson step
|
// Apply Newton-Raphson step
|
||||||
$error = self::GAMMADIST($x, $alpha, $beta, true) - $probability;
|
$error = self::GAMMADIST($x, $alpha, $beta, true) - $probability;
|
||||||
if ($error < 0.0) {
|
if ($error < 0.0) {
|
||||||
|
@ -1744,7 +1739,7 @@ class Statistical
|
||||||
}
|
}
|
||||||
$x = $xNew;
|
$x = $xNew;
|
||||||
}
|
}
|
||||||
if ($i == MAX_ITERATIONS) {
|
if ($i == self::MAX_ITERATIONS) {
|
||||||
return Functions::NA();
|
return Functions::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2667,7 +2662,7 @@ class Statistical
|
||||||
return 0.5 * (1 + Engineering::erfVal(($value - $mean) / ($stdDev * sqrt(2))));
|
return 0.5 * (1 + Engineering::erfVal(($value - $mean) / ($stdDev * sqrt(2))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (1 / (SQRT2PI * $stdDev)) * exp(0 - (pow($value - $mean, 2) / (2 * ($stdDev * $stdDev))));
|
return (1 / (self::SQRT2PI * $stdDev)) * exp(0 - (pow($value - $mean, 2) / (2 * ($stdDev * $stdDev))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3439,7 +3434,7 @@ class Statistical
|
||||||
}
|
}
|
||||||
$tsum *= $ts;
|
$tsum *= $ts;
|
||||||
if (($degrees % 2) == 1) {
|
if (($degrees % 2) == 1) {
|
||||||
$tsum = M_2DIVPI * ($tsum + $ttheta);
|
$tsum = Functions::M_2DIVPI * ($tsum + $ttheta);
|
||||||
}
|
}
|
||||||
$tValue = 0.5 * (1 + $tsum);
|
$tValue = 0.5 * (1 + $tsum);
|
||||||
if ($tails == 1) {
|
if ($tails == 1) {
|
||||||
|
@ -3475,7 +3470,7 @@ class Statistical
|
||||||
$dx = 1;
|
$dx = 1;
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while ((abs($dx) > PRECISION) && ($i++ < MAX_ITERATIONS)) {
|
while ((abs($dx) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) {
|
||||||
// Apply Newton-Raphson step
|
// Apply Newton-Raphson step
|
||||||
$result = self::TDIST($x, $degrees, 2);
|
$result = self::TDIST($x, $degrees, 2);
|
||||||
$error = $result - $probability;
|
$error = $result - $probability;
|
||||||
|
@ -3500,7 +3495,7 @@ class Statistical
|
||||||
}
|
}
|
||||||
$x = $xNew;
|
$x = $xNew;
|
||||||
}
|
}
|
||||||
if ($i == MAX_ITERATIONS) {
|
if ($i == self::MAX_ITERATIONS) {
|
||||||
return Functions::NA();
|
return Functions::NA();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,8 +139,8 @@ class CholeskyDecomposition
|
||||||
|
|
||||||
return new Matrix($X, $this->m, $nx);
|
return new Matrix($X, $this->m, $nx);
|
||||||
}
|
}
|
||||||
throw new CalculationException(JAMAError(MatrixSPDException));
|
throw new CalculationException(Matrix::MATRIX_SPD_EXCEPTION);
|
||||||
}
|
}
|
||||||
throw new CalculationException(JAMAError(MATRIX_DIMENSION_EXCEPTION));
|
throw new CalculationException(Matrix::MATRIX_DIMENSION_EXCEPTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Matrix
|
||||||
const ARGUMENT_BOUNDS_EXCEPTION = 'Invalid argument range.';
|
const ARGUMENT_BOUNDS_EXCEPTION = 'Invalid argument range.';
|
||||||
const MATRIX_DIMENSION_EXCEPTION = 'Matrix dimensions are not equal.';
|
const MATRIX_DIMENSION_EXCEPTION = 'Matrix dimensions are not equal.';
|
||||||
const ARRAY_LENGTH_EXCEPTION = 'Array length must be a multiple of m.';
|
const ARRAY_LENGTH_EXCEPTION = 'Array length must be a multiple of m.';
|
||||||
|
const MATRIX_SPD_EXCEPTION = 'Can only perform operation on symmetric positive definite matrix.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matrix storage.
|
* Matrix storage.
|
||||||
|
@ -971,7 +972,7 @@ class Matrix
|
||||||
|
|
||||||
return $C;
|
return $C;
|
||||||
}
|
}
|
||||||
throw new CalculationException(JAMAError(MatrixDimensionMismatch));
|
throw new CalculationException(self::MATRIX_DIMENSION_EXCEPTION);
|
||||||
case 'array':
|
case 'array':
|
||||||
$B = new self($args[0]);
|
$B = new self($args[0]);
|
||||||
if ($this->n == $B->m) {
|
if ($this->n == $B->m) {
|
||||||
|
@ -988,7 +989,7 @@ class Matrix
|
||||||
|
|
||||||
return $C;
|
return $C;
|
||||||
}
|
}
|
||||||
throw new CalculationException(JAMAError(MatrixDimensionMismatch));
|
throw new CalculationException(self::MATRIX_DIMENSION_EXCEPTION);
|
||||||
case 'integer':
|
case 'integer':
|
||||||
$C = new self($this->A);
|
$C = new self($this->A);
|
||||||
for ($i = 0; $i < $C->m; ++$i) {
|
for ($i = 0; $i < $C->m; ++$i) {
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Error handling.
|
|
||||||
*
|
|
||||||
* @author Michael Bommarito
|
|
||||||
*
|
|
||||||
* @version 01292005
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Language constant
|
|
||||||
define('JAMALANG', 'EN');
|
|
||||||
|
|
||||||
//All errors may be defined by the following format:
|
|
||||||
//define('ExceptionName', N);
|
|
||||||
//$error['lang'][ExceptionName] = 'Error message';
|
|
||||||
$error = [];
|
|
||||||
|
|
||||||
/*
|
|
||||||
I've used Babelfish and a little poor knowledge of Romance/Germanic languages for the translations here.
|
|
||||||
Feel free to correct anything that looks amiss to you.
|
|
||||||
*/
|
|
||||||
|
|
||||||
define('POLYMORPHIC_ARGUMENT_EXCEPTION', -1);
|
|
||||||
$error['EN'][POLYMORPHIC_ARGUMENT_EXCEPTION] = 'Invalid argument pattern for polymorphic function.';
|
|
||||||
$error['FR'][POLYMORPHIC_ARGUMENT_EXCEPTION] = "Modèle inadmissible d'argument pour la fonction polymorphe." .
|
|
||||||
$error['DE'][POLYMORPHIC_ARGUMENT_EXCEPTION] = 'Unzulässiges Argumentmuster für polymorphe Funktion.';
|
|
||||||
|
|
||||||
define('ARGUMENT_TYPE_EXCEPTION', -2);
|
|
||||||
$error['EN'][ARGUMENT_TYPE_EXCEPTION] = 'Invalid argument type.';
|
|
||||||
$error['FR'][ARGUMENT_TYPE_EXCEPTION] = "Type inadmissible d'argument.";
|
|
||||||
$error['DE'][ARGUMENT_TYPE_EXCEPTION] = 'Unzulässige Argumentart.';
|
|
||||||
|
|
||||||
define('ARGUMENT_BOUNDS_EXCEPTION', -3);
|
|
||||||
$error['EN'][ARGUMENT_BOUNDS_EXCEPTION] = 'Invalid argument range.';
|
|
||||||
$error['FR'][ARGUMENT_BOUNDS_EXCEPTION] = "Gamme inadmissible d'argument.";
|
|
||||||
$error['DE'][ARGUMENT_BOUNDS_EXCEPTION] = 'Unzulässige Argumentstrecke.';
|
|
||||||
|
|
||||||
define('MATRIX_DIMENSION_EXCEPTION', -4);
|
|
||||||
$error['EN'][MATRIX_DIMENSION_EXCEPTION] = 'Matrix dimensions are not equal.';
|
|
||||||
$error['FR'][MATRIX_DIMENSION_EXCEPTION] = 'Les dimensions de Matrix ne sont pas égales.';
|
|
||||||
$error['DE'][MATRIX_DIMENSION_EXCEPTION] = 'Matrixmaße sind nicht gleich.';
|
|
||||||
|
|
||||||
define('PRECISION_LOSS_EXCEPTION', -5);
|
|
||||||
$error['EN'][PRECISION_LOSS_EXCEPTION] = 'Significant precision loss detected.';
|
|
||||||
$error['FR'][PRECISION_LOSS_EXCEPTION] = 'Perte significative de précision détectée.';
|
|
||||||
$error['DE'][PRECISION_LOSS_EXCEPTION] = 'Bedeutender Präzision Verlust ermittelte.';
|
|
||||||
|
|
||||||
define('MATRIX_SPD_EXCEPTION', -6);
|
|
||||||
$error['EN'][MATRIX_SPD_EXCEPTION] = 'Can only perform operation on symmetric positive definite matrix.';
|
|
||||||
$error['FR'][MATRIX_SPD_EXCEPTION] = 'Perte significative de précision détectée.';
|
|
||||||
$error['DE'][MATRIX_SPD_EXCEPTION] = 'Bedeutender Präzision Verlust ermittelte.';
|
|
||||||
|
|
||||||
define('MATRIX_SINGULAR_EXCEPTION', -7);
|
|
||||||
$error['EN'][MATRIX_SINGULAR_EXCEPTION] = 'Can only perform operation on singular matrix.';
|
|
||||||
|
|
||||||
define('MATRIX_RANK_EXCEPTION', -8);
|
|
||||||
$error['EN'][MATRIX_RANK_EXCEPTION] = 'Can only perform operation on full-rank matrix.';
|
|
||||||
|
|
||||||
define('ARRAY_LENGTH_EXCEPTION', -9);
|
|
||||||
$error['EN'][ARRAY_LENGTH_EXCEPTION] = 'Array length must be a multiple of m.';
|
|
||||||
|
|
||||||
define('ROW_LENGTH_EXCEPTION', -10);
|
|
||||||
$error['EN'][ROW_LENGTH_EXCEPTION] = 'All rows must have the same length.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom error handler.
|
|
||||||
*
|
|
||||||
* @param int $errorNumber Error number
|
|
||||||
*/
|
|
||||||
function JAMAError($errorNumber)
|
|
||||||
{
|
|
||||||
global $error;
|
|
||||||
|
|
||||||
if (isset($error[JAMALANG][$errorNumber])) {
|
|
||||||
return $error[JAMALANG][$errorNumber];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $error['EN'][$errorNumber];
|
|
||||||
}
|
|
|
@ -28,16 +28,10 @@ namespace PhpOffice\PhpSpreadsheet\Shared;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
|
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
|
||||||
|
|
||||||
defined('IDENTIFIER_OLE') ||
|
|
||||||
define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
|
|
||||||
|
|
||||||
class OLERead
|
class OLERead
|
||||||
{
|
{
|
||||||
private $data = '';
|
private $data = '';
|
||||||
|
|
||||||
// OLE identifier
|
|
||||||
const IDENTIFIER_OLE = IDENTIFIER_OLE;
|
|
||||||
|
|
||||||
// Size of a sector = 512 bytes
|
// Size of a sector = 512 bytes
|
||||||
const BIG_BLOCK_SIZE = 0x200;
|
const BIG_BLOCK_SIZE = 0x200;
|
||||||
|
|
||||||
|
@ -84,7 +78,8 @@ class OLERead
|
||||||
$this->data = file_get_contents($pFilename, false, null, 0, 8);
|
$this->data = file_get_contents($pFilename, false, null, 0, 8);
|
||||||
|
|
||||||
// Check OLE identifier
|
// Check OLE identifier
|
||||||
if ($this->data != self::IDENTIFIER_OLE) {
|
$identifierOle = pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1);
|
||||||
|
if ($this->data != $identifierOle) {
|
||||||
throw new ReaderException('The filename ' . $pFilename . ' is not recognised as an OLE file');
|
throw new ReaderException('The filename ' . $pFilename . ' is not recognised as an OLE file');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,6 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Shared;
|
namespace PhpOffice\PhpSpreadsheet\Shared;
|
||||||
|
|
||||||
if (!defined('DATE_W3C')) {
|
|
||||||
define('DATE_W3C', 'Y-m-d\TH:i:sP');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!defined('DEBUGMODE_ENABLED')) {
|
|
||||||
define('DEBUGMODE_ENABLED', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet.
|
||||||
*
|
*
|
||||||
|
@ -34,6 +26,8 @@ if (!defined('DEBUGMODE_ENABLED')) {
|
||||||
*/
|
*/
|
||||||
class XMLWriter extends \XMLWriter
|
class XMLWriter extends \XMLWriter
|
||||||
{
|
{
|
||||||
|
public static $debugEnabled = false;
|
||||||
|
|
||||||
/** Temporary storage method */
|
/** Temporary storage method */
|
||||||
const STORAGE_MEMORY = 1;
|
const STORAGE_MEMORY = 1;
|
||||||
const STORAGE_DISK = 2;
|
const STORAGE_DISK = 2;
|
||||||
|
@ -71,7 +65,7 @@ class XMLWriter extends \XMLWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default values
|
// Set default values
|
||||||
if (DEBUGMODE_ENABLED) {
|
if (self::$debugEnabled) {
|
||||||
$this->setIndent(true);
|
$this->setIndent(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue