Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sdkjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
sdkjs
Commits
ed0f67e4
Commit
ed0f67e4
authored
Jun 08, 2017
by
GoshaZotov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add GAMMA formula
parent
57190408
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
3 deletions
+66
-3
cell/.unit-tests/FormulaTests.js
cell/.unit-tests/FormulaTests.js
+20
-1
cell/model/FormulaObjects/statisticalFunctions.js
cell/model/FormulaObjects/statisticalFunctions.js
+46
-2
No files found.
cell/.unit-tests/FormulaTests.js
View file @
ed0f67e4
...
...
@@ -1009,7 +1009,26 @@ $( function () {
strictEqual
(
oParser
.
calculate
().
getValue
().
toFixed
(
7
)
-
0
,
0.01
,
"
F.DIST.RT(A2,A3,A4)
"
);
}
);
test
(
"
Test:
\"
SUM(1,2,3)
\"
"
,
function
()
{
test
(
"
Test:
\"
GAMMA
\"
"
,
function
()
{
oParser
=
new
parserFormula
(
"
GAMMA(2.5)
"
,
"
A1
"
,
ws
);
ok
(
oParser
.
parse
(),
"
GAMMA(2.5)
"
);
strictEqual
(
oParser
.
calculate
().
getValue
().
toFixed
(
3
)
-
0
,
1.329
,
"
GAMMA(2.5)
"
);
oParser
=
new
parserFormula
(
"
GAMMA(-3.75)
"
,
"
A1
"
,
ws
);
ok
(
oParser
.
parse
(),
"
GAMMA(-3.75)
"
);
strictEqual
(
oParser
.
calculate
().
getValue
().
toFixed
(
3
)
-
0
,
0.268
,
"
GAMMA(0.268)
"
);
oParser
=
new
parserFormula
(
"
GAMMA(0)
"
,
"
A1
"
,
ws
);
ok
(
oParser
.
parse
(),
"
GAMMA(0)
"
);
strictEqual
(
oParser
.
calculate
().
getValue
(),
"
#NUM!
"
,
"
GAMMA(0)
"
);
oParser
=
new
parserFormula
(
"
GAMMA(-2)
"
,
"
A1
"
,
ws
);
ok
(
oParser
.
parse
(),
"
GAMMA(-2)
"
);
strictEqual
(
oParser
.
calculate
().
getValue
(),
"
#NUM!
"
,
"
GAMMA(-2)
"
);
}
);
test
(
"
Test:
\"
SUM(1,2,3)
\"
"
,
function
()
{
oParser
=
new
parserFormula
(
'
SUM(1,2,3)
'
,
"
A1
"
,
ws
);
ok
(
oParser
.
parse
()
);
strictEqual
(
oParser
.
calculate
().
getValue
(),
1
+
2
+
3
);
...
...
cell/model/FormulaObjects/statisticalFunctions.js
View file @
ed0f67e4
...
...
@@ -63,12 +63,16 @@
cFormulaFunctionGroup
[
'
Statistical
'
].
push
(
cAVEDEV
,
cAVERAGE
,
cAVERAGEA
,
cAVERAGEIF
,
cAVERAGEIFS
,
cBETADIST
,
cBETAINV
,
cBINOMDIST
,
cCHIDIST
,
cCHIINV
,
cCHITEST
,
cCONFIDENCE
,
cCORREL
,
cCOUNT
,
cCOUNTA
,
cCOUNTBLANK
,
cCOUNTIF
,
cCOUNTIFS
,
cCOVAR
,
cCRITBINOM
,
cDEVSQ
,
cEXPONDIST
,
cFDIST
,
cF_DIST
,
cF_DIST_RT
,
cFINV
,
cFISHER
,
cFISHERINV
,
cFORECAST
,
cFREQUENCY
,
cFTEST
,
cGAMMADIST
,
cGAMMAINV
,
cGAMMALN
,
cGEOMEAN
,
cGROWTH
,
cHARMEAN
,
cHYPGEOMDIST
,
cINTERCEPT
,
cKURT
,
cLARGE
,
cFTEST
,
cGAMMA
,
cGAMMA
DIST
,
cGAMMAINV
,
cGAMMALN
,
cGEOMEAN
,
cGROWTH
,
cHARMEAN
,
cHYPGEOMDIST
,
cINTERCEPT
,
cKURT
,
cLARGE
,
cLINEST
,
cLOGEST
,
cLOGINV
,
cLOGNORMDIST
,
cMAX
,
cMAXA
,
cMEDIAN
,
cMIN
,
cMINA
,
cMODE
,
cNEGBINOMDIST
,
cNORMDIST
,
cNORMINV
,
cNORMSDIST
,
cNORMSINV
,
cPEARSON
,
cPERCENTILE
,
cPERCENTRANK
,
cPERMUT
,
cPOISSON
,
cPROB
,
cQUARTILE
,
cRANK
,
cRSQ
,
cSKEW
,
cSLOPE
,
cSMALL
,
cSTANDARDIZE
,
cSTDEV
,
cSTDEVA
,
cSTDEVP
,
cSTDEVPA
,
cSTEYX
,
cTDIST
,
cT_DIST
,
cT_DIST_2T
,
cT_DIST_RT
,
cTINV
,
cTREND
,
cTRIMMEAN
,
cTTEST
,
cVAR
,
cVARA
,
cVARP
,
cVARPA
,
cWEIBULL
,
cZTEST
);
function
isInteger
(
value
)
{
return
typeof
value
===
'
number
'
&&
isFinite
(
value
)
&&
Math
.
floor
(
value
)
===
value
;
}
function
integralPhi
(
x
)
{
// Using gauss(x)+0.5 has severe cancellation errors for x<-4
return
0.5
*
AscCommonExcel
.
rtl_math_erfc
(
-
x
*
0.7071067811865475
);
// * 1/sqrt(2)
}
...
...
@@ -350,7 +354,7 @@
return
getGammaHelper
(
fZ
+
2
)
/
(
fZ
+
1
)
/
fZ
;
}
var
fLogDivisor
=
getLogGammaHelper
(
1
-
fZ
)
+
Math
.
log
(
Math
.
abs
(
Math
.
sin
(
Math
.
PI
()
*
fZ
)));
var
fLogDivisor
=
getLogGammaHelper
(
1
-
fZ
)
+
Math
.
log
(
Math
.
abs
(
Math
.
sin
(
Math
.
PI
*
fZ
)));
if
(
fLogDivisor
-
fLogPi
>=
fLogDblMax
){
return
0
;
}
...
...
@@ -2300,6 +2304,46 @@
cFTEST
.
prototype
=
Object
.
create
(
cBaseFunction
.
prototype
);
cFTEST
.
prototype
.
constructor
=
cFTEST
;
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
*/
function
cGAMMA
()
{
this
.
name
=
"
GAMMA
"
;
this
.
value
=
null
;
this
.
argumentsCurrent
=
0
;
}
cGAMMA
.
prototype
=
Object
.
create
(
cBaseFunction
.
prototype
);
cGAMMA
.
prototype
.
constructor
=
cGAMMA
;
cGAMMA
.
prototype
.
argumentsMin
=
1
;
cGAMMA
.
prototype
.
argumentsMax
=
1
;
cGAMMA
.
prototype
.
isXLFN
=
true
;
cGAMMA
.
prototype
.
Calculate
=
function
(
arg
)
{
var
oArguments
=
this
.
_prepareArguments
(
arg
,
arguments
[
1
],
true
);
var
argClone
=
oArguments
.
args
;
argClone
[
0
]
=
argClone
[
0
].
tocNumber
();
var
argError
;
if
(
argError
=
this
.
_checkErrorArg
(
argClone
))
{
return
this
.
value
=
argError
;
}
var
calcGamma
=
function
(
argArray
){
if
(
argArray
[
0
]
<=
0
&&
isInteger
(
argArray
[
0
])){
return
new
cError
(
cErrorType
.
not_numeric
);
}
var
res
=
getGamma
(
argArray
[
0
]);
return
null
!==
res
&&
!
isNaN
(
res
)
?
new
cNumber
(
res
)
:
new
cError
(
cErrorType
.
wrong_value_type
);
};
return
this
.
value
=
this
.
_findArrayInNumberArguments
(
oArguments
,
calcGamma
);
};
cGAMMA
.
prototype
.
getInfo
=
function
()
{
return
{
name
:
this
.
name
,
args
:
"
(number)
"
}
};
/**
* @constructor
* @extends {AscCommonExcel.cBaseFunction}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment