enmergent commit on 20230213 by nitload youmu, recovery of math functions

This commit is contained in:
Nitload
2023-02-13 19:17:33 +08:00
parent 35cf242e7a
commit d7bee7cab0
18 changed files with 176 additions and 36 deletions
+2 -2
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static unsafe partial class Calc
public static unsafe partial class Math
{
+5 -3
View File
@@ -1,4 +1,6 @@
// some of the code is rewritten from the AMD code:
//
//
// some of the code is rewritten from the AMD code:
// https://github.com/amd/aocl-libm-ose/blob/a43e092b03213eb0e129a1cc129900e6e4475778/src/ref/asinf.c
@@ -7,9 +9,9 @@ using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static unsafe partial class Calc
public static unsafe partial class Math
{
private const float
+85
View File
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
public static unsafe partial class Math
{
public static unsafe float ATan(float x)
{
float sign = 1, angle = 0;
if (x < 0)
{
sign = -1;
x = -x;
}
uint xBit = *(uint*)&x;
int xExp = (int)(xBit >> 23) - 127;
if (xExp >= 26)
{
return 1;
}
if (xExp <= -15)
{
return x;
}
if (xExp >= 0)
{
x = (x - 1) / (x + 1);
angle = 0.7853981634f;
}
float v = 0.7853981634f * x + x * (1 - x) * (0.2447f+0.0663f * x);
v += angle;
v *= sign;
return v;
}
public static unsafe float ATan(float x, float y)
{
float z = y / x;
float sign = 1, angle = 0,angle2 = 0;
if (x<0)
{
angle = -3.1415926535f ;
}
if (z < 0)
{
sign = -1;
z = -z;
}
uint zBit = *(uint*)&z;
int zExp = (int)(zBit >> 23) - 127;
if (zExp >= 26)
{
return 1;
}
if (zExp <= -15)
{
return z;
}
if (zExp >= 0)
{
z = (z - 1) / (z + 1);
angle2 = 0.7853981634f;
}
float v = 0.7853981634f * z + z * (1 - z) * (0.2447f + 0.0663f * z);
v *= 57.29577951f;
v += angle2;
v += angle;
v *= sign;
return v;
}
}
}
+2 -2
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static partial class Calc
public static partial class Math
{
public static float Cos(float x)
+2 -2
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static unsafe partial class Calc
public static unsafe partial class Math
{
public const float E = 2.718281828f;
+4 -2
View File
@@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static unsafe partial class Calc
public static unsafe partial class Math
{
/// <summary>
+5 -2
View File
@@ -4,9 +4,12 @@ using System.Net.Sockets;
using System.Text;
using static System.Net.WebRequestMethods;
namespace StgSharp.Math
namespace StgSharp
{
public static partial class Calc
public static partial class Math
{
static private readonly float[] logArray =
+3 -3
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static unsafe partial class Calc
public static unsafe partial class Math
{
/// <summary>
/// calculate the value of x^y
@@ -35,7 +35,7 @@ namespace StgSharp.Math
{
return 1.0f / 0;
}
z = StgSharp.Math.Calc.Log(x) * y;
z = StgSharp.Math.Log(x) * y;
bool sign = false;
if (z < 0)
+2 -2
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static partial class Calc
public static partial class Math
{
private static readonly float[] sinData =
{
+2 -2
View File
@@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static partial class Clac
public static partial class Math
{
/*本方法将小数部分统一提升至2^16处后进行线性近似
const uint sqmov = 0b_0100_0111_1000_0000_0000_0000_0000_0000;
+2 -2
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Math
namespace StgSharp
{
public static partial class Calc
public static partial class Math
{
public static float Tan(float x)