Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1213,9 +1213,22 @@ func prepareEvalInfixExp(opfStack, opftStack, opfdStack, argsStack *Stack) {
argument := true
if opftStack.Len() > 2 && opfdStack.Len() == 1 {
topOpt := opftStack.Pop()
if opftStack.Peek().(efp.Token).TType == efp.TokenTypeOperatorInfix {
// Look past any subexpression start, function start, and prefix operator tokens
var savedTokens []efp.Token
for opftStack.Len() > 0 {
token := opftStack.Peek().(efp.Token)
if !isBeginParenthesesToken(token) && !isFunctionStartToken(token) && token.TType != efp.TokenTypeOperatorPrefix {
break
}
savedTokens = append(savedTokens, opftStack.Pop().(efp.Token))
}
if opftStack.Len() > 0 && opftStack.Peek().(efp.Token).TType == efp.TokenTypeOperatorInfix {
argument = false
}
// Restore saved tokens
for i := len(savedTokens) - 1; i >= 0; i-- {
opftStack.Push(savedTokens[i])
}
opftStack.Push(topOpt)
}
// push opfd to args
Expand Down
3 changes: 3 additions & 0 deletions calc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ 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",
"SUM(1+(ABS(A1)+A1)/2)": "2",
"SUM(1+(-ABS(A1)))": "0",
"IF(2<0, 1, (4))": "4",
"IF(2>0, (1), 4)": "1",
"IF(2>0, (A1)*2.5, 4)": "2.5",
Expand Down Expand Up @@ -1998,6 +2000,7 @@ func TestCalcCellValue(t *testing.T) {
"IF(FALSE,0,ROUND(4/2,0))": "2",
"IF(TRUE,ROUND(4/2,0),0)": "2",
"IF(A4>0.4,\"TRUE\",\"FALSE\")": "FALSE",
"IF(A1=0,0,1+(SUM(ABS(A1))))": "2",
// Excel Lookup and Reference Functions
// ADDRESS
"ADDRESS(1,1,1,TRUE)": "$A$1",
Expand Down