Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
3bb2849e
excelize
项目概览
xuri
/
excelize
通知
13
Star
2
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
excelize
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
已验证
提交
3bb2849e
编写于
10月 31, 2021
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ref #65: new formula functions DEVSQ and GEOMEAN
上级
9cc66948
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
0 deletion
+65
-0
calc.go
calc.go
+53
-0
calc_test.go
calc_test.go
+12
-0
未找到文件。
calc.go
浏览文件 @
3bb2849e
...
...
@@ -365,6 +365,7 @@ type formulaFuncs struct {
// DEC2OCT
// DECIMAL
// DEGREES
// DEVSQ
// DISC
// DOLLARDE
// DOLLARFR
...
...
@@ -389,6 +390,7 @@ type formulaFuncs struct {
// GAMMA
// GAMMALN
// GCD
// GEOMEAN
// HARMEAN
// HEX2BIN
// HEX2DEC
...
...
@@ -4924,6 +4926,36 @@ func (fn *formulaFuncs) COUNTBLANK(argsList *list.List) formulaArg {
return
newNumberFormulaArg
(
float64
(
count
))
}
// DEVSQ function calculates the sum of the squared deviations from the sample
// mean. The syntax of the function is:
//
// DEVSQ(number1,[number2],...)
//
func
(
fn
*
formulaFuncs
)
DEVSQ
(
argsList
*
list
.
List
)
formulaArg
{
if
argsList
.
Len
()
<
1
{
return
newErrorFormulaArg
(
formulaErrorVALUE
,
"DEVSQ requires at least 1 numeric argument"
)
}
avg
,
count
,
result
:=
fn
.
AVERAGE
(
argsList
),
-
1
,
0.0
for
arg
:=
argsList
.
Front
();
arg
!=
nil
;
arg
=
arg
.
Next
()
{
for
_
,
number
:=
range
arg
.
Value
.
(
formulaArg
)
.
ToList
()
{
num
:=
number
.
ToNumber
()
if
num
.
Type
!=
ArgNumber
{
continue
}
count
++
if
count
==
0
{
result
=
math
.
Pow
(
num
.
Number
-
avg
.
Number
,
2
)
continue
}
result
+=
math
.
Pow
(
num
.
Number
-
avg
.
Number
,
2
)
}
}
if
count
==
-
1
{
return
newErrorFormulaArg
(
formulaErrorNA
,
formulaErrorNA
)
}
return
newNumberFormulaArg
(
result
)
}
// FISHER function calculates the Fisher Transformation for a supplied value.
// The syntax of the function is:
//
...
...
@@ -5030,6 +5062,27 @@ func (fn *formulaFuncs) GAMMALN(argsList *list.List) formulaArg {
return
newErrorFormulaArg
(
formulaErrorVALUE
,
"GAMMALN requires 1 numeric argument"
)
}
// GEOMEAN function calculates the geometric mean of a supplied set of values.
// The syntax of the function is:
//
// GEOMEAN(number1,[number2],...)
//
func
(
fn
*
formulaFuncs
)
GEOMEAN
(
argsList
*
list
.
List
)
formulaArg
{
if
argsList
.
Len
()
<
1
{
return
newErrorFormulaArg
(
formulaErrorVALUE
,
"GEOMEAN requires at least 1 numeric argument"
)
}
product
:=
fn
.
PRODUCT
(
argsList
)
if
product
.
Type
!=
ArgNumber
{
return
product
}
count
:=
fn
.
COUNT
(
argsList
)
min
:=
fn
.
MIN
(
argsList
)
if
product
.
Number
>
0
&&
min
.
Number
>
0
{
return
newNumberFormulaArg
(
math
.
Pow
(
product
.
Number
,
(
1
/
count
.
Number
)))
}
return
newErrorFormulaArg
(
formulaErrorNUM
,
formulaErrorNUM
)
}
// HARMEAN function calculates the harmonic mean of a supplied set of values.
// The syntax of the function is:
//
...
...
calc_test.go
浏览文件 @
3bb2849e
...
...
@@ -763,6 +763,9 @@ func TestCalcCellValue(t *testing.T) {
"=COUNTBLANK(1)"
:
"0"
,
"=COUNTBLANK(B1:C1)"
:
"1"
,
"=COUNTBLANK(C1)"
:
"1"
,
// DEVSQ
"=DEVSQ(1,3,5,2,9,7)"
:
"47.5"
,
"=DEVSQ(A1:D2)"
:
"10"
,
// FISHER
"=FISHER(-0.9)"
:
"-1.47221948958322"
,
"=FISHER(-0.25)"
:
"-0.255412811882995"
,
...
...
@@ -780,6 +783,8 @@ func TestCalcCellValue(t *testing.T) {
// GAMMALN
"=GAMMALN(4.5)"
:
"2.45373657084244"
,
"=GAMMALN(INT(1))"
:
"0"
,
// GEOMEAN
"=GEOMEAN(2.5,3,0.5,1,3)"
:
"1.6226711115996"
,
// HARMEAN
"=HARMEAN(2.5,3,0.5,1,3)"
:
"1.22950819672131"
,
"=HARMEAN(
\"
2.5
\"
,3,0.5,1,INT(3),
\"\"
)"
:
"1.22950819672131"
,
...
...
@@ -1977,6 +1982,9 @@ func TestCalcCellValue(t *testing.T) {
// COUNTBLANK
"=COUNTBLANK()"
:
"COUNTBLANK requires 1 argument"
,
"=COUNTBLANK(1,2)"
:
"COUNTBLANK requires 1 argument"
,
// DEVSQ
"=DEVSQ()"
:
"DEVSQ requires at least 1 numeric argument"
,
"=DEVSQ(D1:D2)"
:
"#N/A"
,
// FISHER
"=FISHER()"
:
"FISHER requires 1 numeric argument"
,
"=FISHER(2)"
:
"#N/A"
,
...
...
@@ -1995,6 +2003,10 @@ func TestCalcCellValue(t *testing.T) {
"=GAMMALN(F1)"
:
"GAMMALN requires 1 numeric argument"
,
"=GAMMALN(0)"
:
"#N/A"
,
"=GAMMALN(INT(0))"
:
"#N/A"
,
// GEOMEAN
"=GEOMEAN()"
:
"GEOMEAN requires at least 1 numeric argument"
,
"=GEOMEAN(0)"
:
"#NUM!"
,
"=GEOMEAN(D1:D2)"
:
"strconv.ParseFloat: parsing
\"
Month
\"
: invalid syntax"
,
// HARMEAN
"=HARMEAN()"
:
"HARMEAN requires at least 1 argument"
,
"=HARMEAN(-1)"
:
"#N/A"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录