Skip to content

Commit 701fc83

Browse files
Fix subexpression calculation
1 parent 2823bda commit 701fc83

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

calc.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,6 @@ func (f *File) evalInfixExp(ctx *calcContext, sheet, cell string, tokens []efp.T
10131013
}
10141014
}
10151015

1016-
if isEndParenthesesToken(token) && isBeginParenthesesToken(opftStack.Peek().(efp.Token)) {
1017-
if arg := argsStack.Peek().(*list.List).Back(); arg != nil {
1018-
opfdStack.Push(arg.Value.(formulaArg))
1019-
argsStack.Peek().(*list.List).Remove(arg)
1020-
}
1021-
}
1022-
10231016
// check current token is opft
10241017
if err = f.parseToken(ctx, sheet, token, opfdStack, opftStack); err != nil {
10251018
return newEmptyFormulaArg(), err
@@ -1090,7 +1083,7 @@ func (f *File) evalInfixExpFunc(ctx *calcContext, sheet, cell string, token, nex
10901083
opftStack.Pop() // remove current function separator
10911084
opfStack.Pop()
10921085
if opfStack.Len() > 0 { // still in function stack
1093-
if nextToken.TType == efp.TokenTypeOperatorInfix || (opftStack.Len() > 1 && opfdStack.Len() > 0) {
1086+
if nextToken.TType == efp.TokenTypeOperatorInfix || opftStack.Len() > 1 {
10941087
// mathematics calculate in formula function
10951088
opfdStack.Push(arg)
10961089
return newEmptyFormulaArg()

calc_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,9 @@ func TestCalcCellValue(t *testing.T) {
895895
"=1+SUM(SUM(1,2*3),4)*4/3+5+(4+2)*3": "38.6666666666667",
896896
"=SUM(1+ROW())": "2",
897897
"=SUM((SUM(2))+1)": "3",
898+
"=IF(2<0, 1, (4))": "4",
899+
"=IF(2>0, (1), 4)": "1",
900+
"=IF(2>0, (A1)*2.5, 4)": "2.5",
898901
"=SUM({1,2,3,4,\"\"})": "10",
899902
// SUMIF
900903
"=SUMIF(F1:F5, \"\")": "0",

0 commit comments

Comments
 (0)