Skip to content

Commit

Permalink
Fixes #44 calculation with complex when Im is negative
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Mar 25, 2024
1 parent 724fdc0 commit b38a84e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions site/doc/api/math.generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ A complex number.
>>> 1 + 2i
# 1 + 2 * i
out = 1 + 2i
>>> i ^ 3
# i ^ 3
out = i
```

## imag
Expand Down
5 changes: 4 additions & 1 deletion src/Kalk.Core/KalkEngine.generated.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
Expand Down Expand Up @@ -26953,6 +26953,9 @@ private void RegisterDocumentationAuto()
descriptor.Example = @" >>> 1 + 2i
# 1 + 2 * i
out = 1 + 2i
>>> i ^ 3
# i ^ 3
out = i
";
}
{
Expand Down
2 changes: 1 addition & 1 deletion src/Kalk.Core/Model/KalkComplex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/Kalk.Core/Modules/MathModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public MathModule()
/// >>> 1 + 2i
/// # 1 + 2 * i
/// out = 1 + 2i
/// >>> i ^ 3
/// # i ^ 3
/// out = i
/// ```
/// </example>
[KalkExport("i", CategoryMathFunctions)]
Expand Down
9 changes: 6 additions & 3 deletions src/Kalk.Tests/KalkTests.generated.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
Expand Down Expand Up @@ -904,8 +904,11 @@ public partial class MathModuleTests : KalkTestBase
/// <summary>
/// Test for <see cref="M:Kalk.Core.MathModule.ComplexNumber"/> or `i`.
/// </summary>
[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);

/// <summary>
Expand Down

0 comments on commit b38a84e

Please sign in to comment.