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
10 changes: 10 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ Both are real, `im(3 + 4i)` being `4`, real-linear, and turned by the conjugate
| `"im(3 + 4i)".ToEntity().Simplify()` | `(3 + 4i) * im` | `4` |
| `"re * x".ToEntity()` | `re * x` | `re * x` |

### A number's conjugate is made under the setting in force

**Silent: `Complex.Conjugate` is made under the downcasting setting of the caller, where the first caller's setting was
kept on the number for every caller after it.** A division by `i` with the downcasting off conjugates `i`, and left its
conjugate as `0 - 1i`, in decimals, on the one instance that every `i` is, in every thread from then on.

| Input | Was (2.6.0) | Now |
|---|---|---|
| `Complex.ImaginaryOne.Conjugate`, after `(1 / Complex.ImaginaryOne).Evaled` with `DowncastingEnabled` off | `0 - 1i` | `-i` |

### `conjugate`, `conj` and `arg` are functions

**Not silent: these names followed by a bracket are now the complex conjugate and the principal argument, where they
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ private protected Complex(Real? real, Real? imaginary) =>
/// <summary>
/// Conjugate of a complex number. Given this = a + ib, Conjugate = a - ib
/// </summary>
public Complex Conjugate => conjugate.GetValue(static @this => Create(@this.RealPart, -@this.ImaginaryPart), this);
private LazyPropertyA<Complex> conjugate;
/// <remarks>
/// Made under the downcasting setting in force, as any other number is, and so not kept
/// on the instance: the first to ask decided it for everyone. A division by <c>i</c> with
/// the downcasting off left <c>0 - 1i</c>, in decimals, on <see cref="ImaginaryOne"/>, and
/// <c>conj(i)</c> was that from then on, in every thread.
/// </remarks>
public Complex Conjugate => Create(RealPart, -ImaginaryPart);

internal override Priority Priority =>
(RealPart, ImaginaryPart) switch
Expand Down
15 changes: 15 additions & 0 deletions Sources/Tests/UnitTests/Core/Numeric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,20 @@ public void AModulusIsMadeUnderTheDowncastingInForce()
Assert.Equal(Integer.Create(325), Complex.Create(EDecimal.FromInt32(75), rootOf100000).Abs());
}
}

/// <summary>
/// A conjugate is made under the setting in force, as every other number is. It was kept on
/// the instance, so a division by <c>i</c> with the downcasting off left <c>0 - 1i</c>, in
/// decimals, as the conjugate of <see cref="Complex.ImaginaryOne"/>, and <c>conj(i)</c> was
/// that for every caller after it: two tests failed or passed by the order the suite ran in.
/// </summary>
[Fact]
public void AConjugateIsMadeUnderTheSettingInForce()
{
using (MathS.Settings.DowncastingEnabled.Set(false))
Assert.IsType<Complex>((1 / Complex.ImaginaryOne).Evaled);
Assert.Equal(Complex.MinusImaginaryOne, Complex.ImaginaryOne.Conjugate);
Assert.Equal(Complex.MinusImaginaryOne, "conj(i)".ToEntity().InnerSimplified);
}
}
}
Loading