From b38a84e9050029dd30aae69ea9f615c9bdc0c01d Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Mon, 25 Mar 2024 21:05:59 +0100 Subject: [PATCH] Fixes #44 calculation with complex when Im is negative --- site/doc/api/math.generated.md | 3 +++ src/Kalk.Core/KalkEngine.generated.cs | 5 ++++- src/Kalk.Core/Model/KalkComplex.cs | 2 +- src/Kalk.Core/Modules/MathModule.cs | 3 +++ src/Kalk.Tests/KalkTests.generated.cs | 9 ++++++--- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/site/doc/api/math.generated.md b/site/doc/api/math.generated.md index ea3a223..095f935 100644 --- a/site/doc/api/math.generated.md +++ b/site/doc/api/math.generated.md @@ -624,6 +624,9 @@ A complex number. >>> 1 + 2i # 1 + 2 * i out = 1 + 2i +>>> i ^ 3 +# i ^ 3 +out = i ``` ## imag diff --git a/src/Kalk.Core/KalkEngine.generated.cs b/src/Kalk.Core/KalkEngine.generated.cs index c52fe47..29198e3 100644 --- a/src/Kalk.Core/KalkEngine.generated.cs +++ b/src/Kalk.Core/KalkEngine.generated.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Date: 16 Sep 2023 +// Date: 25 Mar 2024 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -26953,6 +26953,9 @@ private void RegisterDocumentationAuto() descriptor.Example = @" >>> 1 + 2i # 1 + 2 * i out = 1 + 2i + >>> i ^ 3 + # i ^ 3 + out = i "; } { diff --git a/src/Kalk.Core/Model/KalkComplex.cs b/src/Kalk.Core/Model/KalkComplex.cs index 38870b8..6de699a 100644 --- a/src/Kalk.Core/Model/KalkComplex.cs +++ b/src/Kalk.Core/Model/KalkComplex.cs @@ -35,7 +35,7 @@ public KalkComplex(Complex value) public double Magnitude => _value.Magnitude; - public bool HasIm => _value.Imaginary > MaxRoundToZero; + public bool HasIm => Math.Abs(_value.Imaginary) > MaxRoundToZero; internal Complex Value => _value; diff --git a/src/Kalk.Core/Modules/MathModule.cs b/src/Kalk.Core/Modules/MathModule.cs index 4652631..e3cc2e1 100644 --- a/src/Kalk.Core/Modules/MathModule.cs +++ b/src/Kalk.Core/Modules/MathModule.cs @@ -145,6 +145,9 @@ public MathModule() /// >>> 1 + 2i /// # 1 + 2 * i /// out = 1 + 2i + /// >>> i ^ 3 + /// # i ^ 3 + /// out = i /// ``` /// [KalkExport("i", CategoryMathFunctions)] diff --git a/src/Kalk.Tests/KalkTests.generated.cs b/src/Kalk.Tests/KalkTests.generated.cs index ae26d3c..10384ef 100644 --- a/src/Kalk.Tests/KalkTests.generated.cs +++ b/src/Kalk.Tests/KalkTests.generated.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Date: 16 Sep 2023 +// Date: 25 Mar 2024 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -904,8 +904,11 @@ public partial class MathModuleTests : KalkTestBase /// /// Test for or `i`. /// - [TestCase(@"1 + 2i", @"# 1 + 2 * i -out = 1 + 2i", Category = "Math Functions")] + [TestCase(@"1 + 2i +i ^ 3", @"# 1 + 2 * i +out = 1 + 2i +# i ^ 3 +out = i", Category = "Math Functions")] public static void Test_i(string input, string output) => AssertScript(input, output); ///