diff --git a/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs b/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs index 7503e99..815da32 100644 --- a/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs +++ b/ClosedXML/Excel/CalcEngine/Functions/MathTrig.cs @@ -558,6 +558,10 @@ private static object Atanh(List p) { + double input = p[0]; + if (Math.Abs(input) >= 1) + throw new NumberException(); + return XLMath.ATanh(p[0]); } diff --git a/ClosedXML_Tests/Excel/CalcEngine/MathTrigTests.cs b/ClosedXML_Tests/Excel/CalcEngine/MathTrigTests.cs index 0ebfdda..98de92a 100644 --- a/ClosedXML_Tests/Excel/CalcEngine/MathTrigTests.cs +++ b/ClosedXML_Tests/Excel/CalcEngine/MathTrigTests.cs @@ -330,6 +330,37 @@ } } + [Theory] + public void Atanh_ThrowsNumberExceptionWhenAbsOfInput1OrGreater([Range(1, 5, 0.2)] double input) + { + Assert.Throws(() => XLWorkbook.EvaluateExpr(string.Format(@"ATANH({0})", input.ToString(CultureInfo.InvariantCulture)))); + Assert.Throws(() => XLWorkbook.EvaluateExpr(string.Format(@"ATANH({0})", (-input).ToString(CultureInfo.InvariantCulture)))); + } + + [TestCase(-0.99, -2.64665241236225)] + [TestCase(-0.9, -1.47221948958322)] + [TestCase(-0.8, -1.09861228866811)] + [TestCase(-0.6, -0.693147180559945)] + [TestCase(-0.4, -0.423648930193602)] + [TestCase(-0.2, -0.202732554054082)] + [TestCase(0, 0)] + [TestCase(0.2, 0.202732554054082)] + [TestCase(0.4, 0.423648930193602)] + [TestCase(0.6, 0.693147180559945)] + [TestCase(0.8, 1.09861228866811)] + [TestCase(-0.9, -1.47221948958322)] + [TestCase(-0.990, -2.64665241236225)] + [TestCase(-0.999, -3.8002011672502)] + public void Atanh_ReturnsCorrectResults(double input, double expectedResult) + { + var actual = (double)XLWorkbook.EvaluateExpr( + string.Format( + @"ATANH({0})", + input.ToString(CultureInfo.InvariantCulture))); + + Assert.AreEqual(expectedResult, actual, tolerance * 10); + } + [TestCase(4, 3, 20)] [TestCase(10, 3, 220)] [TestCase(0, 0, 1)]