diff --git a/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs b/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs index 72401fd..b1d4d68 100644 --- a/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs +++ b/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs @@ -104,7 +104,11 @@ private static object Asin(List p) { - return Math.Asin(p[0]); + double input = p[0]; + if (Math.Abs(input) > 1) + throw new NumberException(); + + return Math.Asin(input); } private static object Atan(List p) diff --git a/ClosedXML_Tests/Excel/CalcEngine/MathTrigTests.cs b/ClosedXML_Tests/Excel/CalcEngine/MathTrigTests.cs index 0165213..92099cd 100644 --- a/ClosedXML_Tests/Excel/CalcEngine/MathTrigTests.cs +++ b/ClosedXML_Tests/Excel/CalcEngine/MathTrigTests.cs @@ -173,6 +173,40 @@ Assert.Throws(() => XLWorkbook.EvaluateExpr($"ARABIC(\"{invalidRoman}\")")); } + [Theory] + public void Asin_ThrowsNumberExceptionWhenAbsOfInputGreaterThan1([Range(-3, -1.1, 0.1)] double input) + { + Assert.Throws(() => XLWorkbook.EvaluateExpr(string.Format(@"ASIN({0})", input.ToString(CultureInfo.InvariantCulture)))); + Assert.Throws(() => XLWorkbook.EvaluateExpr(string.Format(@"ASIN({0})", (-input).ToString(CultureInfo.InvariantCulture)))); + } + + [TestCase(-1, -1.570796327)] + [TestCase(-0.9, -1.119769515)] + [TestCase(-0.8, -0.927295218)] + [TestCase(-0.7, -0.775397497)] + [TestCase(-0.6, -0.643501109)] + [TestCase(-0.5, -0.523598776)] + [TestCase(-0.4, -0.411516846)] + [TestCase(-0.3, -0.304692654)] + [TestCase(-0.2, -0.201357921)] + [TestCase(-0.1, -0.100167421)] + [TestCase(0, 0)] + [TestCase(0.1, 0.100167421)] + [TestCase(0.2, 0.201357921)] + [TestCase(0.3, 0.304692654)] + [TestCase(0.4, 0.411516846)] + [TestCase(0.5, 0.523598776)] + [TestCase(0.6, 0.643501109)] + [TestCase(0.7, 0.775397497)] + [TestCase(0.8, 0.927295218)] + [TestCase(0.9, 1.119769515)] + [TestCase(1, 1.570796327)] + public void Asin_ReturnsCorrectResult(double input, double expectedResult) + { + var actual = (double)XLWorkbook.EvaluateExpr(string.Format(@"ASIN({0})", input.ToString(CultureInfo.InvariantCulture))); + Assert.AreEqual(expectedResult, actual, tolerance * 10); + } + [TestCase(4, 3, 20)] [TestCase(10, 3, 220)] [TestCase(0, 0, 1)]