Skip to content

Commit 0509e60

Browse files
authored
#2179 - array as denominator when first value is 0 returns a single #DIV0! error. (#2180)
1 parent db4c0e8 commit 0509e60

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/EPPlus/FormulaParsing/Excel/Operators/Operator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static IOperator Divide
246246
}
247247
var left = l.ResultNumeric;
248248
var right = r.ResultNumeric;
249-
if (Math.Abs(right - 0d) < double.Epsilon)
249+
if (r.DataType != DataType.ExcelRange && Math.Abs(right - 0d) < double.Epsilon)
250250
{
251251
var eVal = ExcelErrorValue.Create(eErrorType.Div0);
252252
return CreateCompileResult(l.ResultType, r.ResultType, eVal, DataType.ExcelError);

src/EPPlusTest/FormulaParsing/Excel/OperatorsTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,20 @@ public void ChangePrecisionTest()
273273
var ExcelResult = Operator.Divide.Apply(a, b, ctx);
274274
Assert.AreEqual(0.99329223647228326d, ExcelResult.Result);
275275
}
276+
277+
[TestMethod]
278+
public void ShouldDivideNumberByArray()
279+
{
280+
using var p = new ExcelPackage();
281+
var ws = p.Workbook.Worksheets.Add("Sheet1");
282+
ws.Cells["B1"].Value = -2;
283+
ws.Cells["B2"].Value = -1;
284+
ws.Cells["B3"].Value = 2;
285+
ws.Cells["A1"].Formula = "=1/(B1:B3 + 2)";
286+
p.Workbook.Calculate();
287+
Assert.AreEqual(ExcelErrorValue.Create(eErrorType.Div0), ws.Cells["A1"].Value);
288+
Assert.AreEqual(1d, ws.Cells["A2"].Value);
289+
Assert.AreEqual(0.25d, ws.Cells["A3"].Value);
290+
}
276291
}
277292
}

0 commit comments

Comments
 (0)