mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 16:35:42 +00:00
feat: expose ComplexSqrt to all frameworks
This commit is contained in:
parent
1acee3bf72
commit
e52e9096e0
@ -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 `Vector4.Deconstruct()`.
|
||||
- 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 `System.Drawing.Color.ToUnityColor()`.
|
||||
- X10D.Unity: Added `System.Drawing.Color.ToUnityColor32()`.
|
||||
|
@ -7,7 +7,6 @@ namespace X10D.Tests.Math;
|
||||
[TestClass]
|
||||
public partial class DecimalTests
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
[TestMethod]
|
||||
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, 4.0), (-16.0m).ComplexSqrt());
|
||||
}
|
||||
#endif
|
||||
|
||||
[TestMethod]
|
||||
public void IsEven_ShouldBeFalse_GivenOddNumber()
|
||||
|
@ -29,7 +29,6 @@ public partial class DoubleTests
|
||||
Assert.AreEqual(12.0, 0.20943951023931953.RadiansToDegrees(), 1e-6);
|
||||
}
|
||||
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
[TestMethod]
|
||||
public void ComplexSqrt_ShouldBeCorrect_GivenReal()
|
||||
{
|
||||
@ -61,7 +60,6 @@ public partial class DoubleTests
|
||||
{
|
||||
Assert.AreEqual(Complex.NaN, double.NaN.ComplexSqrt());
|
||||
}
|
||||
#endif
|
||||
|
||||
[TestMethod]
|
||||
public void IsEven_ShouldBeFalse_GivenOddNumber()
|
||||
|
@ -29,7 +29,6 @@ public partial class SingleTests
|
||||
Assert.AreEqual(12.0f, 0.20943952f.RadiansToDegrees(), 1e-6f);
|
||||
}
|
||||
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
[TestMethod]
|
||||
public void ComplexSqrt_ShouldBeCorrect_GivenReal()
|
||||
{
|
||||
@ -61,7 +60,6 @@ public partial class SingleTests
|
||||
{
|
||||
Assert.AreEqual(Complex.NaN, float.NaN.ComplexSqrt());
|
||||
}
|
||||
#endif
|
||||
|
||||
[TestMethod]
|
||||
public void IsEven_ShouldBeFalse_GivenOddNumber()
|
||||
|
@ -9,19 +9,21 @@ namespace X10D.Math;
|
||||
/// </summary>
|
||||
public static class DecimalExtensions
|
||||
{
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Returns the complex square root of this decimal number.
|
||||
/// </summary>
|
||||
/// <param name="value">The number whose square root is to be found.</param>
|
||||
/// <returns>The square root of <paramref name="value" />.</returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static Complex ComplexSqrt(this decimal value)
|
||||
{
|
||||
return Complex.Sqrt((double)value);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is evenly divisible by 2.
|
||||
|
@ -140,23 +140,26 @@ public static class DoubleExtensions
|
||||
return System.Math.Atanh(value);
|
||||
}
|
||||
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Returns the complex square root of this double-precision floating-point number.
|
||||
/// </summary>
|
||||
/// <param name="value">The number whose square root is to be found.</param>
|
||||
/// <returns>The square root of <paramref name="value" />.</returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static Complex ComplexSqrt(this double value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case double.PositiveInfinity:
|
||||
case double.NegativeInfinity:
|
||||
return Complex.Infinity;
|
||||
return new Complex(double.PositiveInfinity, double.PositiveInfinity);
|
||||
case double.NaN:
|
||||
return Complex.NaN;
|
||||
return new Complex(double.NaN, double.NaN);
|
||||
|
||||
case 0:
|
||||
return Complex.Zero;
|
||||
@ -166,7 +169,6 @@ public static class DoubleExtensions
|
||||
return new Complex(0, System.Math.Sqrt(-value));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cosine of the specified angle.
|
||||
|
@ -140,23 +140,26 @@ public static class SingleExtensions
|
||||
return MathF.Atanh(value);
|
||||
}
|
||||
|
||||
#if NETCOREAPP3_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Returns the complex square root of this single-precision floating-point number.
|
||||
/// </summary>
|
||||
/// <param name="value">The number whose square root is to be found.</param>
|
||||
/// <returns>The square root of <paramref name="value" />.</returns>
|
||||
[Pure]
|
||||
#if NETSTANDARD2_1
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
#else
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
#endif
|
||||
public static Complex ComplexSqrt(this float value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case float.PositiveInfinity:
|
||||
case float.NegativeInfinity:
|
||||
return Complex.Infinity;
|
||||
return new Complex(double.PositiveInfinity, double.PositiveInfinity);
|
||||
case float.NaN:
|
||||
return Complex.NaN;
|
||||
return new Complex(double.NaN, double.NaN);
|
||||
|
||||
case 0:
|
||||
return Complex.Zero;
|
||||
@ -166,7 +169,6 @@ public static class SingleExtensions
|
||||
return new Complex(0, MathF.Sqrt(-value));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cosine of the specified angle.
|
||||
|
Loading…
Reference in New Issue
Block a user