Some small things. Was working on complex numbers but got bored.
This commit is contained in:
parent
48890c236e
commit
2762dab872
@ -1,9 +1,32 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Nerd_STF.Helpers
|
namespace Nerd_STF.Helpers
|
||||||
{
|
{
|
||||||
internal static class TargetHelper
|
internal static class TargetHelper
|
||||||
{
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool IsFinite(double d)
|
||||||
|
{
|
||||||
|
#if CS11_OR_GREATER
|
||||||
|
return double.IsFinite(d);
|
||||||
|
#else
|
||||||
|
long bits = BitConverter.DoubleToInt64Bits(d);
|
||||||
|
return (bits & 0x7FFFFFFFFFFFFFFF) < 0x7FF0000000000000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool IsInfinity(double d)
|
||||||
|
{
|
||||||
|
#if CS11_OR_GREATER
|
||||||
|
return double.IsInfinity(d);
|
||||||
|
#else
|
||||||
|
long bits = BitConverter.DoubleToInt64Bits(d);
|
||||||
|
return (bits & 0x7FFFFFFFFFFFFFFF) == 0x7FF0000000000000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void WriteLine(string content)
|
public static void WriteLine(string content)
|
||||||
{
|
{
|
||||||
#if NETSTANDARD1_1
|
#if NETSTANDARD1_1
|
||||||
@ -12,6 +35,7 @@ namespace Nerd_STF.Helpers
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static T[] EmptyArray<T>()
|
public static T[] EmptyArray<T>()
|
||||||
{
|
{
|
||||||
#if NETSTANDARD1_1
|
#if NETSTANDARD1_1
|
||||||
|
|||||||
@ -9,7 +9,6 @@ namespace Nerd_STF.Mathematics.Algebra
|
|||||||
double Magnitude { get; }
|
double Magnitude { get; }
|
||||||
|
|
||||||
static abstract TSelf ClampMagnitude(TSelf val, double minMag, double maxMag);
|
static abstract TSelf ClampMagnitude(TSelf val, double minMag, double maxMag);
|
||||||
static abstract void ClampMagnitude(ref TSelf val, double minMag, double maxMag);
|
|
||||||
static abstract double Dot(TSelf a, TSelf b);
|
static abstract double Dot(TSelf a, TSelf b);
|
||||||
static abstract double Dot(IEnumerable<TSelf> vals);
|
static abstract double Dot(IEnumerable<TSelf> vals);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -680,26 +680,38 @@ namespace Nerd_STF.Mathematics
|
|||||||
|
|
||||||
return flip ? result : -result;
|
return flip ? result : -result;
|
||||||
}
|
}
|
||||||
|
public static double Sin(Angle angle, int terms = 8) =>
|
||||||
|
Sin(angle.Radians, terms);
|
||||||
public static IEquation Sin(IEquation inputRad, int terms = 8) =>
|
public static IEquation Sin(IEquation inputRad, int terms = 8) =>
|
||||||
new Equation((double x) => Sin(inputRad[x], terms));
|
new Equation((double x) => Sin(inputRad[x], terms));
|
||||||
public static double Cos(double rad, int terms = 8) =>
|
public static double Cos(double rad, int terms = 8) =>
|
||||||
Sin(rad + Constants.HalfPi, terms);
|
Sin(rad + Constants.HalfPi, terms);
|
||||||
|
public static double Cos(Angle angle, int terms = 8) =>
|
||||||
|
Cos(angle.Radians, terms);
|
||||||
public static IEquation Cos(IEquation inputRad, int terms = 8) =>
|
public static IEquation Cos(IEquation inputRad, int terms = 8) =>
|
||||||
new Equation((double x) => Cos(inputRad[x], terms));
|
new Equation((double x) => Cos(inputRad[x], terms));
|
||||||
public static double Tan(double rad, int terms = 8) =>
|
public static double Tan(double rad, int terms = 8) =>
|
||||||
Sin(rad + Constants.HalfPi, terms) / Sin(rad, terms);
|
Sin(rad + Constants.HalfPi, terms) / Sin(rad, terms);
|
||||||
|
public static double Tan(Angle angle, int terms = 8) =>
|
||||||
|
Tan(angle.Radians, terms);
|
||||||
public static IEquation Tan(IEquation inputRad, int terms = 8) =>
|
public static IEquation Tan(IEquation inputRad, int terms = 8) =>
|
||||||
new Equation((double x) => Tan(inputRad[x], terms));
|
new Equation((double x) => Tan(inputRad[x], terms));
|
||||||
public static double Csc(double rad, int terms = 8) =>
|
public static double Csc(double rad, int terms = 8) =>
|
||||||
1 / Sin(rad, terms);
|
1 / Sin(rad, terms);
|
||||||
|
public static double Csc(Angle angle, int terms = 8) =>
|
||||||
|
Csc(angle.Radians, terms);
|
||||||
public static IEquation Csc(IEquation inputRad, int terms = 8) =>
|
public static IEquation Csc(IEquation inputRad, int terms = 8) =>
|
||||||
new Equation((double x) => Csc(inputRad[x], terms));
|
new Equation((double x) => Csc(inputRad[x], terms));
|
||||||
public static double Sec(double rad, int terms = 8) =>
|
public static double Sec(double rad, int terms = 8) =>
|
||||||
1 / Sin(rad + Constants.HalfPi, terms);
|
1 / Sin(rad + Constants.HalfPi, terms);
|
||||||
|
public static double Sec(Angle angle, int terms = 8) =>
|
||||||
|
Sec(angle.Radians, terms);
|
||||||
public static IEquation Sec(IEquation inputRad, int terms = 8) =>
|
public static IEquation Sec(IEquation inputRad, int terms = 8) =>
|
||||||
new Equation((double x) => Sec(inputRad[x], terms));
|
new Equation((double x) => Sec(inputRad[x], terms));
|
||||||
public static double Cot(double rad, int terms = 8) =>
|
public static double Cot(double rad, int terms = 8) =>
|
||||||
Sin(rad, terms) / Sin(rad + Constants.HalfPi, terms);
|
Sin(rad, terms) / Sin(rad + Constants.HalfPi, terms);
|
||||||
|
public static double Cot(Angle angle, int terms = 8) =>
|
||||||
|
Cot(angle.Radians, terms);
|
||||||
public static IEquation Cot(IEquation inputRad, int terms = 8) =>
|
public static IEquation Cot(IEquation inputRad, int terms = 8) =>
|
||||||
new Equation((double x) => Cot(inputRad[x], terms));
|
new Equation((double x) => Cot(inputRad[x], terms));
|
||||||
|
|
||||||
|
|||||||
@ -361,7 +361,7 @@ namespace Nerd_STF.Mathematics.Numbers
|
|||||||
}
|
}
|
||||||
public static bool IsEvenInteger(Fraction val) =>
|
public static bool IsEvenInteger(Fraction val) =>
|
||||||
val.num % val.den == 0 && val.num / val.den % 2 == 0;
|
val.num % val.den == 0 && val.num / val.den % 2 == 0;
|
||||||
public static bool IsFinite(Fraction val) => val.den != 0 || val.num != 0;
|
public static bool IsFinite(Fraction val) => val.den != 0;
|
||||||
public static bool IsInfinity(Fraction val) => val.den == 0 && val.num != 0;
|
public static bool IsInfinity(Fraction val) => val.den == 0 && val.num != 0;
|
||||||
public static bool IsInteger(Fraction val) => val.num % val.den == 0;
|
public static bool IsInteger(Fraction val) => val.num % val.den == 0;
|
||||||
public static bool IsNaN(Fraction val) => val.num == 0 && val.den == 0;
|
public static bool IsNaN(Fraction val) => val.num == 0 && val.den == 0;
|
||||||
@ -375,9 +375,7 @@ namespace Nerd_STF.Mathematics.Numbers
|
|||||||
public static bool IsRealNumber(Fraction val) => val.den != 0;
|
public static bool IsRealNumber(Fraction val) => val.den != 0;
|
||||||
public static bool IsZero(Fraction val) => val.num == 0 && val.den != 0;
|
public static bool IsZero(Fraction val) => val.num == 0 && val.den != 0;
|
||||||
public static Fraction MaxMagnitude(Fraction a, Fraction b) => a > b ? a : b;
|
public static Fraction MaxMagnitude(Fraction a, Fraction b) => a > b ? a : b;
|
||||||
public static Fraction MaxMagnitudeNumber(Fraction a, Fraction b) => a > b ? a : b;
|
|
||||||
public static Fraction MinMagnitude(Fraction a, Fraction b) => a < b ? a : b;
|
public static Fraction MinMagnitude(Fraction a, Fraction b) => a < b ? a : b;
|
||||||
public static Fraction MinMagnitudeNumber(Fraction a, Fraction b) => a < b ? a : b;
|
|
||||||
#if CS11_OR_GREATER
|
#if CS11_OR_GREATER
|
||||||
static bool INumberBase<Fraction>.IsComplexNumber(Fraction val) => false;
|
static bool INumberBase<Fraction>.IsComplexNumber(Fraction val) => false;
|
||||||
static bool INumberBase<Fraction>.IsImaginaryNumber(Fraction val) => false;
|
static bool INumberBase<Fraction>.IsImaginaryNumber(Fraction val) => false;
|
||||||
@ -394,6 +392,9 @@ namespace Nerd_STF.Mathematics.Numbers
|
|||||||
static Fraction IMultiplicativeIdentity<Fraction, Fraction>.MultiplicativeIdentity => One;
|
static Fraction IMultiplicativeIdentity<Fraction, Fraction>.MultiplicativeIdentity => One;
|
||||||
static int INumberBase<Fraction>.Radix => 2; // Not super sure what to put here.
|
static int INumberBase<Fraction>.Radix => 2; // Not super sure what to put here.
|
||||||
|
|
||||||
|
static Fraction INumberBase<Fraction>.MaxMagnitudeNumber(Fraction a, Fraction b) => a > b ? a : b;
|
||||||
|
static Fraction INumberBase<Fraction>.MinMagnitudeNumber(Fraction a, Fraction b) => a < b ? a : b;
|
||||||
|
|
||||||
private static bool TryConvertTo<T>(Fraction frac, out T value)
|
private static bool TryConvertTo<T>(Fraction frac, out T value)
|
||||||
{
|
{
|
||||||
object? tempValue;
|
object? tempValue;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user