Skip to content

Commit d1e76fc

Browse files
authored
This closes #1319, fix calculate error for formula with negative symbol
- Update unit test and comment for the functions
1 parent 551fb8a commit d1e76fc

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

calc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ func calculate(opdStack *Stack, opt efp.Token) error {
12341234
return ErrInvalidFormula
12351235
}
12361236
opd := opdStack.Pop().(formulaArg)
1237-
opdStack.Push(newNumberFormulaArg(0 - opd.Number))
1237+
opdStack.Push(newNumberFormulaArg(0 - opd.ToNumber().Number))
12381238
}
12391239
if opt.TValue == "-" && opt.TType == efp.TokenTypeOperatorInfix {
12401240
if opdStack.Len() < 2 {
@@ -1647,18 +1647,18 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er
16471647
var value, expected float64
16481648
var e error
16491649
prepareValue := func(val, cond string) (value float64, expected float64, err error) {
1650-
percential := 1.0
1650+
percentile := 1.0
16511651
if strings.HasSuffix(cond, "%") {
16521652
cond = strings.TrimSuffix(cond, "%")
1653-
percential /= 100
1653+
percentile /= 100
16541654
}
16551655
if value, err = strconv.ParseFloat(val, 64); err != nil {
16561656
return
16571657
}
16581658
if expected, err = strconv.ParseFloat(cond, 64); err != nil {
16591659
return
16601660
}
1661-
expected *= percential
1661+
expected *= percentile
16621662
return
16631663
}
16641664
switch criteria.Type {

calc_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ func TestCalcCellValue(t *testing.T) {
491491
// COS
492492
"=COS(0.785398163)": "0.707106781467586",
493493
"=COS(0)": "1",
494+
"=-COS(0)": "-1",
494495
"=COS(COS(0))": "0.54030230586814",
495496
// COSH
496497
"=COSH(0)": "1",

comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
177177
},
178178
},
179179
}
180-
// load exist comment shapes from xl/drawings/vmlDrawing%d.vml (only once)
180+
// load exist comment shapes from xl/drawings/vmlDrawing%d.vml
181181
d := f.decodeVMLDrawingReader(drawingVML)
182182
if d != nil {
183183
for _, v := range d.Shape {

rows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ func (rows *Rows) Columns(opts ...Options) ([]string, error) {
179179
return rowIterator.columns, rowIterator.err
180180
}
181181

182+
// extractRowOpts extract row element attributes.
182183
func extractRowOpts(attrs []xml.Attr) RowOpts {
183184
rowOpts := RowOpts{Height: defaultRowHeight}
184185
if styleID, err := attrValToInt("s", attrs); err == nil && styleID > 0 && styleID < MaxCellStyles {

0 commit comments

Comments
 (0)