#65 fn: QUARTILE and QUARTILE.INC

This commit is contained in:
xuri 2021-03-31 22:01:02 +08:00
parent 2af96c0714
commit 9d4bf88b47
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 47 additions and 0 deletions

36
calc.go
View File

@ -350,6 +350,8 @@ var tokenPriority = map[string]int{
// POWER
// PRODUCT
// PROPER
// QUARTILE
// QUARTILE.INC
// QUOTIENT
// RADIANS
// RAND
@ -4625,6 +4627,40 @@ func (fn *formulaFuncs) PERMUTATIONA(argsList *list.List) formulaArg {
return newNumberFormulaArg(math.Pow(num, numChosen))
}
// QUARTILE function returns a requested quartile of a supplied range of
// values. The syntax of the function is:
//
// QUARTILE(array,quart)
//
func (fn *formulaFuncs) QUARTILE(argsList *list.List) formulaArg {
if argsList.Len() != 2 {
return newErrorFormulaArg(formulaErrorVALUE, "QUARTILE requires 2 arguments")
}
quart := argsList.Back().Value.(formulaArg).ToNumber()
if quart.Type != ArgNumber {
return quart
}
if quart.Number < 0 || quart.Number > 4 {
return newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM)
}
args := list.New().Init()
args.PushBack(argsList.Front().Value.(formulaArg))
args.PushBack(newNumberFormulaArg(quart.Number / 4))
return fn.PERCENTILE(args)
}
// QUARTILEdotINC function returns a requested quartile of a supplied range of
// values. The syntax of the function is:
//
// QUARTILE.INC(array,quart)
//
func (fn *formulaFuncs) QUARTILEdotINC(argsList *list.List) formulaArg {
if argsList.Len() != 2 {
return newErrorFormulaArg(formulaErrorVALUE, "QUARTILE.INC requires 2 arguments")
}
return fn.QUARTILE(argsList)
}
// SKEW function calculates the skewness of the distribution of a supplied set
// of values. The syntax of the function is:
//

View File

@ -692,6 +692,10 @@ func TestCalcCellValue(t *testing.T) {
// PERMUTATIONA
"=PERMUTATIONA(6,6)": "46656",
"=PERMUTATIONA(7,6)": "117649",
// QUARTILE
"=QUARTILE(A1:A4,2)": "1.5",
// QUARTILE.INC
"=QUARTILE.INC(A1:A4,0)": "0",
// SKEW
"=SKEW(1,2,3,4,3)": "-0.404796008910937",
"=SKEW(A1:B2)": "0",
@ -1508,6 +1512,13 @@ func TestCalcCellValue(t *testing.T) {
"=PERMUTATIONA(0,\"\")": "strconv.ParseFloat: parsing \"\": invalid syntax",
"=PERMUTATIONA(-1,0)": "#N/A",
"=PERMUTATIONA(0,-1)": "#N/A",
// QUARTILE
"=QUARTILE()": "QUARTILE requires 2 arguments",
"=QUARTILE(A1:A4,\"\")": "strconv.ParseFloat: parsing \"\": invalid syntax",
"=QUARTILE(A1:A4,-1)": "#NUM!",
"=QUARTILE(A1:A4,5)": "#NUM!",
// QUARTILE.INC
"=QUARTILE.INC()": "QUARTILE.INC requires 2 arguments",
// SKEW
"=SKEW()": "SKEW requires at least 1 argument",
"=SKEW(\"\")": "strconv.ParseFloat: parsing \"\": invalid syntax",