1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-12 22:55:42 +00:00

feat: expose ComplexSqrt to all frameworks

This commit is contained in:
Oliver Booth 2023-04-01 18:54:04 +01:00
parent 1acee3bf72
commit e52e9096e0
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
7 changed files with 17 additions and 16 deletions

View File

@ -88,6 +88,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- X10D: Added `Vector3.Round([float])`. - X10D: Added `Vector3.Round([float])`.
- X10D: Added `Vector4.Deconstruct()`. - X10D: Added `Vector4.Deconstruct()`.
- X10D: Added `Vector4.Round([float])`. - X10D: Added `Vector4.Round([float])`.
- X10D: `ComplexSqrt` is now exposed for all frameworks.
- X10D.Unity: Added `DebugEx`, which mimics `UnityEngine.Debug` while offering more useful primitive drawing methods. - X10D.Unity: Added `DebugEx`, which mimics `UnityEngine.Debug` while offering more useful primitive drawing methods.
- X10D.Unity: Added `System.Drawing.Color.ToUnityColor()`. - X10D.Unity: Added `System.Drawing.Color.ToUnityColor()`.
- X10D.Unity: Added `System.Drawing.Color.ToUnityColor32()`. - X10D.Unity: Added `System.Drawing.Color.ToUnityColor32()`.

View File

@ -7,7 +7,6 @@ namespace X10D.Tests.Math;
[TestClass] [TestClass]
public partial class DecimalTests public partial class DecimalTests
{ {
#if NETCOREAPP3_0_OR_GREATER
[TestMethod] [TestMethod]
public void ComplexSqrt_ShouldBeCorrect_GivenReal() public void ComplexSqrt_ShouldBeCorrect_GivenReal()
{ {
@ -26,7 +25,6 @@ public partial class DecimalTests
Assert.AreEqual(new Complex(0, 3.0), (-9.0m).ComplexSqrt()); Assert.AreEqual(new Complex(0, 3.0), (-9.0m).ComplexSqrt());
Assert.AreEqual(new Complex(0, 4.0), (-16.0m).ComplexSqrt()); Assert.AreEqual(new Complex(0, 4.0), (-16.0m).ComplexSqrt());
} }
#endif
[TestMethod] [TestMethod]
public void IsEven_ShouldBeFalse_GivenOddNumber() public void IsEven_ShouldBeFalse_GivenOddNumber()

View File

@ -29,7 +29,6 @@ public partial class DoubleTests
Assert.AreEqual(12.0, 0.20943951023931953.RadiansToDegrees(), 1e-6); Assert.AreEqual(12.0, 0.20943951023931953.RadiansToDegrees(), 1e-6);
} }
#if NETCOREAPP3_0_OR_GREATER
[TestMethod] [TestMethod]
public void ComplexSqrt_ShouldBeCorrect_GivenReal() public void ComplexSqrt_ShouldBeCorrect_GivenReal()
{ {
@ -61,7 +60,6 @@ public partial class DoubleTests
{ {
Assert.AreEqual(Complex.NaN, double.NaN.ComplexSqrt()); Assert.AreEqual(Complex.NaN, double.NaN.ComplexSqrt());
} }
#endif
[TestMethod] [TestMethod]
public void IsEven_ShouldBeFalse_GivenOddNumber() public void IsEven_ShouldBeFalse_GivenOddNumber()

View File

@ -29,7 +29,6 @@ public partial class SingleTests
Assert.AreEqual(12.0f, 0.20943952f.RadiansToDegrees(), 1e-6f); Assert.AreEqual(12.0f, 0.20943952f.RadiansToDegrees(), 1e-6f);
} }
#if NETCOREAPP3_0_OR_GREATER
[TestMethod] [TestMethod]
public void ComplexSqrt_ShouldBeCorrect_GivenReal() public void ComplexSqrt_ShouldBeCorrect_GivenReal()
{ {
@ -61,7 +60,6 @@ public partial class SingleTests
{ {
Assert.AreEqual(Complex.NaN, float.NaN.ComplexSqrt()); Assert.AreEqual(Complex.NaN, float.NaN.ComplexSqrt());
} }
#endif
[TestMethod] [TestMethod]
public void IsEven_ShouldBeFalse_GivenOddNumber() public void IsEven_ShouldBeFalse_GivenOddNumber()

View File

@ -9,19 +9,21 @@ namespace X10D.Math;
/// </summary> /// </summary>
public static class DecimalExtensions public static class DecimalExtensions
{ {
#if NETCOREAPP3_0_OR_GREATER
/// <summary> /// <summary>
/// Returns the complex square root of this decimal number. /// Returns the complex square root of this decimal number.
/// </summary> /// </summary>
/// <param name="value">The number whose square root is to be found.</param> /// <param name="value">The number whose square root is to be found.</param>
/// <returns>The square root of <paramref name="value" />.</returns> /// <returns>The square root of <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Complex ComplexSqrt(this decimal value) public static Complex ComplexSqrt(this decimal value)
{ {
return Complex.Sqrt((double)value); return Complex.Sqrt((double)value);
} }
#endif
/// <summary> /// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2. /// Returns a value indicating whether the current value is evenly divisible by 2.

View File

@ -140,23 +140,26 @@ public static class DoubleExtensions
return System.Math.Atanh(value); return System.Math.Atanh(value);
} }
#if NETCOREAPP3_0_OR_GREATER
/// <summary> /// <summary>
/// Returns the complex square root of this double-precision floating-point number. /// Returns the complex square root of this double-precision floating-point number.
/// </summary> /// </summary>
/// <param name="value">The number whose square root is to be found.</param> /// <param name="value">The number whose square root is to be found.</param>
/// <returns>The square root of <paramref name="value" />.</returns> /// <returns>The square root of <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Complex ComplexSqrt(this double value) public static Complex ComplexSqrt(this double value)
{ {
switch (value) switch (value)
{ {
case double.PositiveInfinity: case double.PositiveInfinity:
case double.NegativeInfinity: case double.NegativeInfinity:
return Complex.Infinity; return new Complex(double.PositiveInfinity, double.PositiveInfinity);
case double.NaN: case double.NaN:
return Complex.NaN; return new Complex(double.NaN, double.NaN);
case 0: case 0:
return Complex.Zero; return Complex.Zero;
@ -166,7 +169,6 @@ public static class DoubleExtensions
return new Complex(0, System.Math.Sqrt(-value)); return new Complex(0, System.Math.Sqrt(-value));
} }
} }
#endif
/// <summary> /// <summary>
/// Returns the cosine of the specified angle. /// Returns the cosine of the specified angle.

View File

@ -140,23 +140,26 @@ public static class SingleExtensions
return MathF.Atanh(value); return MathF.Atanh(value);
} }
#if NETCOREAPP3_0_OR_GREATER
/// <summary> /// <summary>
/// Returns the complex square root of this single-precision floating-point number. /// Returns the complex square root of this single-precision floating-point number.
/// </summary> /// </summary>
/// <param name="value">The number whose square root is to be found.</param> /// <param name="value">The number whose square root is to be found.</param>
/// <returns>The square root of <paramref name="value" />.</returns> /// <returns>The square root of <paramref name="value" />.</returns>
[Pure] [Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Complex ComplexSqrt(this float value) public static Complex ComplexSqrt(this float value)
{ {
switch (value) switch (value)
{ {
case float.PositiveInfinity: case float.PositiveInfinity:
case float.NegativeInfinity: case float.NegativeInfinity:
return Complex.Infinity; return new Complex(double.PositiveInfinity, double.PositiveInfinity);
case float.NaN: case float.NaN:
return Complex.NaN; return new Complex(double.NaN, double.NaN);
case 0: case 0:
return Complex.Zero; return Complex.Zero;
@ -166,7 +169,6 @@ public static class SingleExtensions
return new Complex(0, MathF.Sqrt(-value)); return new Complex(0, MathF.Sqrt(-value));
} }
} }
#endif
/// <summary> /// <summary>
/// Returns the cosine of the specified angle. /// Returns the cosine of the specified angle.