summaryrefslogtreecommitdiff
path: root/calc.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2022-04-11 00:04:00 +0800
committerxuri <xuri.me@gmail.com>2022-04-11 00:04:00 +0800
commitc1940c2a1ebd66519bb85abaa2fd7985f0430985 (patch)
treec19d436c320ba46d8f42e7cbb960654e8cfe6b40 /calc.go
parent9b8f1a15e1b75f56d9305b49212ee34ec085943f (diff)
This includes new formula functions support, dependencies upgrade, and bug fix
- Fix page setup fields parsing issue - Go Modules dependencies upgrade - Ref #65, CONFIDENCE.T and PHI - Ref #1198, Fix the issue that the chart axis maximum and minimum didn't work when the value is 0
Diffstat (limited to 'calc.go')
-rw-r--r--calc.go60
1 files changed, 57 insertions, 3 deletions
diff --git a/calc.go b/calc.go
index 20d5b5e..57b2cda 100644
--- a/calc.go
+++ b/calc.go
@@ -374,6 +374,7 @@ type formulaFuncs struct {
// CONCATENATE
// CONFIDENCE
// CONFIDENCE.NORM
+// CONFIDENCE.T
// CORREL
// COS
// COSH
@@ -588,6 +589,7 @@ type formulaFuncs struct {
// PERCENTRANK
// PERMUT
// PERMUTATIONA
+// PHI
// PI
// PMT
// POISSON.DIST
@@ -6805,7 +6807,7 @@ func (fn *formulaFuncs) CONFIDENCE(argsList *list.List) formulaArg {
// confidence value that can be used to construct the confidence interval for
// a population mean, for a supplied probability and sample size. It is
// assumed that the standard deviation of the population is known. The syntax
-// of the Confidence.Norm function is:
+// of the function is:
//
// CONFIDENCE.NORM(alpha,standard_dev,size)
//
@@ -6813,6 +6815,42 @@ func (fn *formulaFuncs) CONFIDENCEdotNORM(argsList *list.List) formulaArg {
return fn.confidence("CONFIDENCE.NORM", argsList)
}
+// CONFIDENCEdotT function uses a Student's T-Distribution to calculate a
+// confidence value that can be used to construct the confidence interval for
+// a population mean, for a supplied probablity and supplied sample size. It
+// is assumed that the standard deviation of the population is known. The
+// syntax of the function is:
+//
+// CONFIDENCE.T(alpha,standard_dev,size)
+//
+func (fn *formulaFuncs) CONFIDENCEdotT(argsList *list.List) formulaArg {
+ if argsList.Len() != 3 {
+ return newErrorFormulaArg(formulaErrorVALUE, "CONFIDENCE.T requires 3 arguments")
+ }
+ var alpha, standardDev, size formulaArg
+ if alpha = argsList.Front().Value.(formulaArg).ToNumber(); alpha.Type != ArgNumber {
+ return alpha
+ }
+ if standardDev = argsList.Front().Next().Value.(formulaArg).ToNumber(); standardDev.Type != ArgNumber {
+ return standardDev
+ }
+ if size = argsList.Back().Value.(formulaArg).ToNumber(); size.Type != ArgNumber {
+ return size
+ }
+ if alpha.Number <= 0 || alpha.Number >= 1 || standardDev.Number <= 0 || size.Number < 1 {
+ return newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM)
+ }
+ if size.Number == 1 {
+ return newErrorFormulaArg(formulaErrorDIV, formulaErrorDIV)
+ }
+ return newNumberFormulaArg(standardDev.Number * calcIterateInverse(calcInverseIterator{
+ name: "CONFIDENCE.T",
+ fp: alpha.Number,
+ fDF: size.Number - 1,
+ nT: 2,
+ }, size.Number/2, size.Number) / math.Sqrt(size.Number))
+}
+
// COVAR function calculates the covariance of two supplied sets of values. The
// syntax of the function is:
//
@@ -8891,6 +8929,22 @@ func (fn *formulaFuncs) PERMUTATIONA(argsList *list.List) formulaArg {
return newNumberFormulaArg(math.Pow(num, numChosen))
}
+// PHI function returns the value of the density function for a standard normal
+// distribution for a supplied number. The syntax of the function is:
+//
+// PHI(x)
+//
+func (fn *formulaFuncs) PHI(argsList *list.List) formulaArg {
+ if argsList.Len() != 1 {
+ return newErrorFormulaArg(formulaErrorVALUE, "PHI requires 1 argument")
+ }
+ x := argsList.Front().Value.(formulaArg).ToNumber()
+ if x.Type != ArgNumber {
+ return x
+ }
+ return newNumberFormulaArg(0.39894228040143268 * math.Exp(-(x.Number*x.Number)/2))
+}
+
// QUARTILE function returns a requested quartile of a supplied range of
// values. The syntax of the function is:
//
@@ -13122,7 +13176,7 @@ func validateFrequency(freq float64) bool {
return freq == 1 || freq == 2 || freq == 4
}
-// ACCRINT function returns the accrued interest for a security that pays
+// ACCRINT function returns the accrued interest in a security that pays
// periodic interest. The syntax of the function is:
//
// ACCRINT(issue,first_interest,settlement,rate,par,frequency,[basis],[calc_method])
@@ -13166,7 +13220,7 @@ func (fn *formulaFuncs) ACCRINT(argsList *list.List) formulaArg {
return newNumberFormulaArg(par.Number * rate.Number * frac1.Number)
}
-// ACCRINTM function returns the accrued interest for a security that pays
+// ACCRINTM function returns the accrued interest in a security that pays
// interest at maturity. The syntax of the function is:
//
// ACCRINTM(issue,settlement,rate,[par],[basis])