Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[Tests/UnitTests/Convenience/ArcsineOfARealPastOneTest.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

[Tests/UnitTests/Convenience/ImaginaryPartOfNaNTest.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

[AngouriMath/Functions/Compilation/RealProducts.cs]
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,9 @@ public partial record Imf
// im(prime(x)) has no value at x = -3.
private static Entity? ImaginaryPart(Entity argument, bool isExact) => argument switch
{
// A number that does not exist has no parts. NaN is a Real, whose imaginary part is 0, so
// im(1/0) was 0. https://github.com/asc-community/AngouriMath/issues/2253
Complex { IsNaN: true } => Real.NaN,
Complex number => number.ImaginaryPart,
Conjugatef(var z) => (-new Imf(z)).InnerSimplified(isExact),
Sumf(var left, var right) => (new Imf(left) + new Imf(right)).InnerSimplified(isExact),
Expand Down
44 changes: 44 additions & 0 deletions Sources/Tests/UnitTests/Convenience/ImaginaryPartOfNaNTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//

using AngouriMath;
using AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Convenience
{
/// <summary>
/// The imaginary part of a value that does not exist has none, as its real part has none, where it was 0: <c>NaN</c>
/// is a <see cref="Entity.Number.Real"/>, whose imaginary part is 0.
/// <a href="https://github.com/asc-community/AngouriMath/issues/2253">#2253</a>
/// </summary>
[Trait("Area", "Convenience")]
public sealed class ImaginaryPartOfNaNTest
{
[Theory]
[InlineData("Im(1/0)")]
[InlineData("Im(arccos(pi) provided pi < 3)")]
[InlineData("Im(1/0) + 1")]
[InlineData("Re(1/0)")]
public void ItHasNoValue(string expression)
{
Assert.True(expression.ToEntity().Evaled.IsNaN, $"{expression} evaluates to {expression.ToEntity().Evaled}");
Assert.True(expression.ToEntity().Simplify().IsNaN, $"{expression} simplifies to {expression.ToEntity().Simplify()}");
}

[Fact]
public void SubstitutedItHasNoValue()
=> Assert.True("Im(x)".ToEntity().Substitute("x", "1/0".ToEntity()).Evaled.IsNaN);

[Theory]
[InlineData("Im(2 + 3i)", "3")]
[InlineData("Im(5)", "0")]
[InlineData("Im(-oo)", "0")]
public void ANumberHasItsImaginaryPart(string expression, string part)
=> Assert.Equal(part.ToEntity().Evaled, expression.ToEntity().Evaled);
}
}
Loading