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.Collections.Generic;
using System.Text; 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 // https://github.com/amd/aocl-libm-ose/blob/a43e092b03213eb0e129a1cc129900e6e4475778/src/ref/asinf.c
@@ -7,9 +9,9 @@ using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Math namespace StgSharp
{ {
public static unsafe partial class Calc public static unsafe partial class Math
{ {
private const float 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.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Math namespace StgSharp
{ {
public static partial class Calc public static partial class Math
{ {
public static float Cos(float x) public static float Cos(float x)
+2 -2
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; 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; public const float E = 2.718281828f;
+4 -2
View File
@@ -2,9 +2,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Math namespace StgSharp
{ {
public static unsafe partial class Calc
public static unsafe partial class Math
{ {
/// <summary> /// <summary>
+5 -2
View File
@@ -4,9 +4,12 @@ using System.Net.Sockets;
using System.Text; using System.Text;
using static System.Net.WebRequestMethods; 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 = static private readonly float[] logArray =
+3 -3
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Math namespace StgSharp
{ {
public static unsafe partial class Calc public static unsafe partial class Math
{ {
/// <summary> /// <summary>
/// calculate the value of x^y /// calculate the value of x^y
@@ -35,7 +35,7 @@ namespace StgSharp.Math
{ {
return 1.0f / 0; return 1.0f / 0;
} }
z = StgSharp.Math.Calc.Log(x) * y; z = StgSharp.Math.Log(x) * y;
bool sign = false; bool sign = false;
if (z < 0) if (z < 0)
+2 -2
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Math namespace StgSharp
{ {
public static partial class Calc public static partial class Math
{ {
private static readonly float[] sinData = private static readonly float[] sinData =
{ {
+2 -2
View File
@@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Text; using System.Text;
namespace StgSharp.Math namespace StgSharp
{ {
public static partial class Clac public static partial class Math
{ {
/*本方法将小数部分统一提升至2^16处后进行线性近似 /*本方法将小数部分统一提升至2^16处后进行线性近似
const uint sqmov = 0b_0100_0111_1000_0000_0000_0000_0000_0000; 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.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Math namespace StgSharp
{ {
public static partial class Calc public static partial class Math
{ {
public static float Tan(float x) public static float Tan(float x)
+62 -14
View File
@@ -1,34 +1,82 @@
using System; using StgSharp.Math;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace StgSharp.Vector namespace StgSharp.Vector
{ {
public struct Vec2x1:IEquatable<Vec2x1> public struct Vec2D:IEquatable<Vec2D>
{ {
float a1; float X;
float a2; float Y;
float Direction;
float Length;
public Vec2x1(float x,float y) public Vec2D(float x,float y)
{ {
a1 = x; X = x;
a2 = y; Y = y;
Direction = 0;
} }
public bool Equals(Vec2x1 other) public bool Equals(Vec2D other)
{ {
return true; if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return this.X == other.X && this.Y == other.Y;
}
} }
public override bool Equals(object obj)
public static bool operator ==(Vec2x1 vec1, Vec2x1 vec2)
{ {
return true; if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(Vec2D))
{
return false;
}
else
{
return this.Equals((Vec2D)obj);
}
} }
public static bool operator !=(Vec2x1 vec1, Vec2x1 vec2) public override int GetHashCode()
{ {
return false; return HashCode.Combine(X, Y);
} }
public override string ToString()
{
return $"{this.X},{this.Y}";
}
public static bool operator ==(Vec2D vec1, Vec2D vec2)
{
return vec1.X==vec2.X && vec1.Y==vec2.Y;
}
public static bool operator !=(Vec2D vec1, Vec2D vec2)
{
return !(vec1.X == vec2.X && vec1.Y == vec2.Y);
}
public static Vec2D operator +(Vec2D vec1, Vec2D vec2)
{
return new Vec2D(vec1.X + vec2.X, vec1.Y + vec2.Y);
}
public static Vec2D operator -(Vec2D vec1, Vec2D vec2)
{
return new Vec2D(vec1.X + vec2.X, vec1.Y + vec2.Y);
}
public static
} }
} }