Skip to content

Commit

Permalink
This closes #2083, fix subexpression calculation (#2084)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Hristov <[email protected]>
  • Loading branch information
IvanHristov98 and Ivan Hristov authored Feb 8, 2025
1 parent 05ed940 commit 718417e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
9 changes: 1 addition & 8 deletions calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,13 +1008,6 @@ func (f *File) evalInfixExp(ctx *calcContext, sheet, cell string, tokens []efp.T
}
}

if isEndParenthesesToken(token) && isBeginParenthesesToken(opftStack.Peek().(efp.Token)) {
if arg := argsStack.Peek().(*list.List).Back(); arg != nil {
opfdStack.Push(arg.Value.(formulaArg))
argsStack.Peek().(*list.List).Remove(arg)
}
}

// check current token is opft
if err = f.parseToken(ctx, sheet, token, opfdStack, opftStack); err != nil {
return newEmptyFormulaArg(), err
Expand Down Expand Up @@ -1085,7 +1078,7 @@ func (f *File) evalInfixExpFunc(ctx *calcContext, sheet, cell string, token, nex
opftStack.Pop() // remove current function separator
opfStack.Pop()
if opfStack.Len() > 0 { // still in function stack
if nextToken.TType == efp.TokenTypeOperatorInfix || (opftStack.Len() > 1 && opfdStack.Len() > 0) {
if nextToken.TType == efp.TokenTypeOperatorInfix || opftStack.Len() > 1 {
// mathematics calculate in formula function
opfdStack.Push(arg)
return newEmptyFormulaArg()
Expand Down
3 changes: 3 additions & 0 deletions calc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,9 @@ func TestCalcCellValue(t *testing.T) {
"=1+SUM(SUM(1,2*3),4)*4/3+5+(4+2)*3": "38.6666666666667",
"=SUM(1+ROW())": "2",
"=SUM((SUM(2))+1)": "3",
"=IF(2<0, 1, (4))": "4",
"=IF(2>0, (1), 4)": "1",
"=IF(2>0, (A1)*2.5, 4)": "2.5",
"=SUM({1,2,3,4,\"\"})": "10",
// SUMIF
"=SUMIF(F1:F5, \"\")": "0",
Expand Down

0 comments on commit 718417e

Please sign in to comment.