Skip to content
Merged
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
184 changes: 183 additions & 1 deletion src/Maths/Silk.NET.Maths/Scalar.MathFPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,17 @@ static T UShort(T x)
return (T) (object) (ushort) Math.Acos((ushort) (object) x); // KIPLING
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Acos((Complex) (object) x);
}

return Decimal(x);
}

Expand Down Expand Up @@ -576,7 +587,7 @@ static T UShort(T x)

return Decimal(x);
}

[MethodImpl(MaxOpt)]
static T Decimal(T x)
{
Expand Down Expand Up @@ -727,6 +738,17 @@ static T UShort(T x)
return (T) (object) (ushort) Math.Asin((ushort) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Asin((Complex) (object) x);
}

return Decimal(x);
}

Expand Down Expand Up @@ -1021,6 +1043,17 @@ static T UShort(T x)
return (T) (object) (ushort) Math.Atan((ushort) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Atan((Complex) (object) x);
}

return Decimal(x);
}

Expand Down Expand Up @@ -1314,6 +1347,17 @@ static T Long(T x)
return (T) (object) CoreCbrt((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Pow((Complex) (object) x, 1.0/3); // TODO: find a more efficient impl?
}

return ULong(x);
}

Expand Down Expand Up @@ -1609,6 +1653,17 @@ static T Long(T x)
return (T) (object) (long) Math.Cos((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Cos((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -1757,6 +1812,17 @@ static T Long(T x)
return (T) (object) (long) Math.Cosh((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Cosh((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -1897,6 +1963,17 @@ static T Long(T x)
return (T) (object) (long) Math.Exp((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Exp((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -2403,6 +2480,17 @@ static T Long(T x)
return (T) (object) (long) Math.Sin((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Sin((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -2551,6 +2639,17 @@ static T Long(T x)
return (T) (object) (long) Math.Sinh((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Sinh((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -2871,6 +2970,18 @@ static T Long(T x)
#endif
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
// TODO: vectorized implementation?
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Sqrt((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -3035,6 +3146,17 @@ static T Long(T x)
return (T) (object) (long) Math.Tan((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Tan((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -3183,6 +3305,17 @@ static T Long(T x)
return (T) (object) (long) Math.Tanh((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Tanh((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -3518,6 +3651,17 @@ static T Long(T x)
return (T) (object) (long) Math.Log((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Log((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -3694,6 +3838,17 @@ static T Long(T x)
return (T) (object) (long) Math.Log10((long) (object) x);
}

return Complex(x);
}

[MethodImpl(MaxOpt)]
static T Complex(T x)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Log10((Complex) (object) x);
}

return ULong(x);
}

Expand Down Expand Up @@ -4254,6 +4409,22 @@ static T Long(T x, T y)
return (T) (object) (long) Math.Log((long) (object) x, (long) (object) y);
}

return Complex(x, y);
}

[MethodImpl(MaxOpt)]
static T Complex(T x, T y)
{
if (typeof(T) == typeof(Complex))
{
// Complex.Log is not defined on two complex numbers
var baseValue = (Complex) (object) y;
if (baseValue.Imaginary is 0)
return (T) (object) (Complex) System.Numerics.Complex.Log((Complex) (object) x, baseValue.Real);
// log(x, y) = log(x) / log(y)
return (T) (object) (System.Numerics.Complex.Log((Complex) (object) x) / System.Numerics.Complex.Log(baseValue));
}

return ULong(x, y);
}

Expand Down Expand Up @@ -4887,6 +5058,17 @@ static T Long(T x, T y)
}
}

return Complex(x, y);
}

[MethodImpl(MaxOpt)]
static T Complex(T x, T y)
{
if (typeof(T) == typeof(Complex))
{
return (T) (object) (Complex) System.Numerics.Complex.Pow((Complex) (object) x, (Complex) (object) y);
}

return ULong(x, y);
}

Expand Down