Daily update on 20230204 by nitload youmu, pow func added
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -25,18 +25,6 @@ namespace StgSharp
|
|||||||
//得到对应的float值
|
//得到对应的float值
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
public float f;
|
public float f;
|
||||||
|
|
||||||
|
|
||||||
public Union4(float x, uint y)
|
|
||||||
{
|
|
||||||
b0 = 0;
|
|
||||||
b1 = 0;
|
|
||||||
b2 = 0;
|
|
||||||
b3 = 0;
|
|
||||||
i = 0;
|
|
||||||
f = x;
|
|
||||||
y = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using StgSharp;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -17,15 +16,9 @@ namespace StgSharp
|
|||||||
get { return _referencePoint; }
|
get { return _referencePoint; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public float VecX
|
float IGeometry.ExpressionX => throw new NotImplementedException();
|
||||||
{
|
|
||||||
get { return _vecX; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public float VecY
|
float IGeometry.ExpressionY => throw new NotImplementedException();
|
||||||
{
|
|
||||||
get { return _vecY; }
|
|
||||||
}
|
|
||||||
|
|
||||||
ContainerNode<INode> INode.ID
|
ContainerNode<INode> INode.ID
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace StgSharp
|
||||||
|
{
|
||||||
|
public delegate float ExpressionHandler
|
||||||
|
(
|
||||||
|
Counter<uint> tickCounter,
|
||||||
|
float beginRange,
|
||||||
|
float endRange
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -14,12 +14,12 @@ namespace StgSharp
|
|||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float VecX
|
internal float ExpressionX
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float VecY
|
internal float ExpressionY
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,21 +18,17 @@ namespace StgSharp
|
|||||||
get { return _referencePoint; }
|
get { return _referencePoint; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public float VecX
|
|
||||||
{
|
|
||||||
get { return _vecX; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public float VecY
|
|
||||||
{
|
|
||||||
get { return _vecY; }
|
|
||||||
}
|
|
||||||
|
|
||||||
ContainerNode<INode> INode.ID
|
ContainerNode<INode> INode.ID
|
||||||
{
|
{
|
||||||
get { return _id; }
|
get { return _id; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float IGeometry.ExpressionX => throw new NotImplementedException();
|
||||||
|
|
||||||
|
float IGeometry.ExpressionY => throw new NotImplementedException();
|
||||||
|
|
||||||
public Line( Point referencePoint, float vecX, float vecY)
|
public Line( Point referencePoint, float vecX, float vecY)
|
||||||
{
|
{
|
||||||
_referencePoint = referencePoint;
|
_referencePoint = referencePoint;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp
|
namespace StgSharp
|
||||||
{
|
{
|
||||||
public class Triangle : IGeometry
|
public class Triangle
|
||||||
{
|
{
|
||||||
internal ContainerNode<INode> _id;
|
internal ContainerNode<INode> _id;
|
||||||
|
|
||||||
@@ -29,10 +29,7 @@ namespace StgSharp
|
|||||||
get { return _referencePoint.Y; }
|
get { return _referencePoint.Y; }
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainerNode<INode> INode.ID
|
|
||||||
{
|
|
||||||
get { return _id; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public float SetArrayX(Counter<uint> tickCounter)
|
public float SetArrayX(Counter<uint> tickCounter)
|
||||||
{
|
{
|
||||||
@@ -44,16 +41,6 @@ namespace StgSharp
|
|||||||
return _setArrayYHandler.Invoke(tickCounter);
|
return _setArrayYHandler.Invoke(tickCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INode.setID<T>(ContainerNode<T> id)
|
|
||||||
{
|
|
||||||
if (id == null)
|
|
||||||
{
|
|
||||||
_id = id as ContainerNode<INode>;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Cannot set id teice!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace StgSharp
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Cannot set id teice!");
|
throw new ArgumentException("Cannot set id twice!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
|
//
|
||||||
|
//
|
||||||
// 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
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,22 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp
|
namespace StgSharp
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public static unsafe partial class Math
|
public static unsafe partial class Math
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the bits of a float number
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">The given float number</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static uint GetBits32(float x)
|
||||||
|
{
|
||||||
|
Union4 union = new Union4();
|
||||||
|
union.f = x;
|
||||||
|
return union.i;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ namespace StgSharp
|
|||||||
0.53062825106217f, 0.536493370514568f, 0.542324290825362f, 0.548121408509688f, 0.553885113226438f, 0.559615787935423f, 0.56531380905006f, 0.570979546585738f, 0.576613364303994f, 0.582215619852664f,
|
0.53062825106217f, 0.536493370514568f, 0.542324290825362f, 0.548121408509688f, 0.553885113226438f, 0.559615787935423f, 0.56531380905006f, 0.570979546585738f, 0.576613364303994f, 0.582215619852664f,
|
||||||
0.587786664902119f, 0.593326845277734f, 0.598836501088704f, 0.60431596685333f, 0.609765571620894f, 0.615185639090233f, 0.62057648772511f, 0.625938430866495f, 0.631271776841858f, 0.636576829071551f,
|
0.587786664902119f, 0.593326845277734f, 0.598836501088704f, 0.60431596685333f, 0.609765571620894f, 0.615185639090233f, 0.62057648772511f, 0.625938430866495f, 0.631271776841858f, 0.636576829071551f,
|
||||||
0.641853886172395f, 0.647103242058538f, 0.65232518603969f, 0.657520002916794f, 0.662687973075237f, 0.667829372575655f, 0.672944473242426f, 0.678033542749897f, 0.683096844706444f, 0.688134638736401f,
|
0.641853886172395f, 0.647103242058538f, 0.65232518603969f, 0.657520002916794f, 0.662687973075237f, 0.667829372575655f, 0.672944473242426f, 0.678033542749897f, 0.683096844706444f, 0.688134638736401f,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,7 +37,7 @@ namespace StgSharp
|
|||||||
{
|
{
|
||||||
if (x<0)
|
if (x<0)
|
||||||
{
|
{
|
||||||
throw new ArgumentException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
uint input = *(uint*)&x;
|
uint input = *(uint*)&x;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace StgSharp
|
||||||
|
{
|
||||||
|
public static unsafe partial class Math
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// calculate the value of x^y
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x"></param>
|
||||||
|
/// <param name="y"></param>
|
||||||
|
/// <returns>Returns the value of x^y</returns>
|
||||||
|
public static unsafe float Pow(float x, float y)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* x^y = E ^ ( log( x ) * y )
|
||||||
|
* Now define z = | log(x) * y | = m * n
|
||||||
|
* and m is an integer, and 0.5 < |n| < 1
|
||||||
|
* then E ^ z = ( E ^ n ) ^ m
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* As a float number can be expressed in (1+e)*(2^f)
|
||||||
|
* n = (1+e)/2
|
||||||
|
* m = 2 ^ (f + 1)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
float z, t;
|
||||||
|
if (x == 1 || y == 0)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x==1&&y==0)
|
||||||
|
{
|
||||||
|
return 1.0f / 0;
|
||||||
|
}
|
||||||
|
z = StgSharp.Math.Log(x) * y;
|
||||||
|
|
||||||
|
bool sign = false;
|
||||||
|
if (z < 0)
|
||||||
|
{
|
||||||
|
sign = true;
|
||||||
|
z = -z;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (z<0.5f)
|
||||||
|
{
|
||||||
|
t = 1.0f + z * (
|
||||||
|
1.0f + z * (
|
||||||
|
0.5f + z * (
|
||||||
|
0.1666666667f + z * (
|
||||||
|
0.0416666666667f + z *
|
||||||
|
8.333333333e-3f))));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uint zBit = *(uint*)&z;
|
||||||
|
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
||||||
|
uint uintm = (zBitAbs >> 23);
|
||||||
|
int m = (*(int*)&uintm) - 126;
|
||||||
|
|
||||||
|
|
||||||
|
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111)
|
||||||
|
+ 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
||||||
|
float n = *(float*)&nBit - 1;
|
||||||
|
|
||||||
|
t = 2.718281828f + n * (
|
||||||
|
2.718281828f + n * (
|
||||||
|
1.359140914f + n * (
|
||||||
|
0.4530469714f + n * (
|
||||||
|
0.1132617429f + n *
|
||||||
|
0.02265234857f))));
|
||||||
|
|
||||||
|
for (int i = 0; i < m; i++)
|
||||||
|
{
|
||||||
|
t = t * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (sign)
|
||||||
|
{
|
||||||
|
t = 1 / t;
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,15 @@ namespace StgSharp
|
|||||||
* 在进一步简化操作后,计算精度达到0.5%,速度约为.Net库函数的1.8倍
|
* 在进一步简化操作后,计算精度达到0.5%,速度约为.Net库函数的1.8倍
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
if (x < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
if (x == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* 提取指数位并减去指数位中的127
|
* 提取指数位并减去指数位中的127
|
||||||
* 由于平方根仅对正数有效
|
* 由于平方根仅对正数有效
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,13 @@
|
|||||||
<returns></returns>
|
<returns></returns>
|
||||||
<exception cref="T:System.ArgumentException"></exception>
|
<exception cref="T:System.ArgumentException"></exception>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:StgSharp.Math.GetBits32(System.Single)">
|
||||||
|
<summary>
|
||||||
|
Get the bits of a float number
|
||||||
|
</summary>
|
||||||
|
<param name="x">The given float number</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:StgSharp.Math.Log(System.Single)">
|
<member name="M:StgSharp.Math.Log(System.Single)">
|
||||||
<summary>
|
<summary>
|
||||||
|
|
||||||
@@ -21,5 +28,13 @@
|
|||||||
Returns the value of ln(x).
|
Returns the value of ln(x).
|
||||||
</returns>
|
</returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:StgSharp.Math.Pow(System.Single,System.Single)">
|
||||||
|
<summary>
|
||||||
|
calculate the value of x^y
|
||||||
|
</summary>
|
||||||
|
<param name="x"></param>
|
||||||
|
<param name="y"></param>
|
||||||
|
<returns>Returns the value of x^y</returns>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
b7317d4b12ba4162c78ad3d204d71202d31826dd
|
d6533ff9d6a5f9bebff84d6c130d7f9b4e85612a
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,13 @@
|
|||||||
<returns></returns>
|
<returns></returns>
|
||||||
<exception cref="T:System.ArgumentException"></exception>
|
<exception cref="T:System.ArgumentException"></exception>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:StgSharp.Math.GetBits32(System.Single)">
|
||||||
|
<summary>
|
||||||
|
Get the bits of a float number
|
||||||
|
</summary>
|
||||||
|
<param name="x">The given float number</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:StgSharp.Math.Log(System.Single)">
|
<member name="M:StgSharp.Math.Log(System.Single)">
|
||||||
<summary>
|
<summary>
|
||||||
|
|
||||||
@@ -21,5 +28,13 @@
|
|||||||
Returns the value of ln(x).
|
Returns the value of ln(x).
|
||||||
</returns>
|
</returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:StgSharp.Math.Pow(System.Single,System.Single)">
|
||||||
|
<summary>
|
||||||
|
calculate the value of x^y
|
||||||
|
</summary>
|
||||||
|
<param name="x"></param>
|
||||||
|
<param name="y"></param>
|
||||||
|
<returns>Returns the value of x^y</returns>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -12,12 +12,13 @@ internal class Program
|
|||||||
/**/
|
/**/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
float test = StgSharp.Math.ASin(StgSharp.Math.Sqrt(3.0f) / 2);
|
float test = StgSharp.Math.Pow(4.0f,0.125f);
|
||||||
Console.WriteLine(test);
|
Console.WriteLine(test);
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int wasd = 0; wasd < 100; wasd++)
|
// 测速
|
||||||
|
for (int cycle = 0; cycle < 100; cycle++)
|
||||||
{
|
{
|
||||||
float time = 1000000;
|
float time = 1000000;
|
||||||
float a = 114514;
|
float a = 114514;
|
||||||
@@ -25,7 +26,7 @@ internal class Program
|
|||||||
stopwatch.Start(); // 开始监视代码运行时间
|
stopwatch.Start(); // 开始监视代码运行时间
|
||||||
for (float i = 2; i < time; i++)
|
for (float i = 2; i < time; i++)
|
||||||
{
|
{
|
||||||
a = StgSharp.Math.ASin(i/(time/2)-1);
|
a = StgSharp.Math.Pow(i, i);
|
||||||
}
|
}
|
||||||
stopwatch.Stop(); // 停止监视
|
stopwatch.Stop(); // 停止监视
|
||||||
TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
|
TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
|
||||||
@@ -39,7 +40,7 @@ internal class Program
|
|||||||
stopwatch1.Start();
|
stopwatch1.Start();
|
||||||
for (float i = 2; i < time2; i++)
|
for (float i = 2; i < time2; i++)
|
||||||
{
|
{
|
||||||
b = System.MathF.Asin(i / (time / 2) - 1);
|
b = System.MathF.Pow(i, i);
|
||||||
}
|
}
|
||||||
stopwatch1.Stop();
|
stopwatch1.Stop();
|
||||||
timespan = stopwatch1.Elapsed;
|
timespan = stopwatch1.Elapsed;
|
||||||
@@ -49,13 +50,15 @@ internal class Program
|
|||||||
}
|
}
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
|
//精度测试
|
||||||
double accuracy = 0;
|
double accuracy = 0;
|
||||||
for (float i = -1f; i < 1f; i += 0.000001f)
|
for (float i = -10f; i < 2000f; i += 0.01f)
|
||||||
{
|
{
|
||||||
|
|
||||||
double r1 = StgSharp.Math.ASin(i);
|
double r1 = StgSharp.Math.Pow(2,i);
|
||||||
double r2 = System.Math.Asin(i)*180/3.1415926;
|
double r2 = System.Math.Pow(2,i);
|
||||||
double ac = ( System.Math.Max(r1,r2)- System.Math.Min(r1, r2) ) / r2;
|
double ac = ( System.Math.Max(r1,r2)- System.Math.Min(r1, r2) ) / r2;
|
||||||
if (ac>accuracy)
|
if (ac>accuracy)
|
||||||
{
|
{
|
||||||
@@ -72,8 +75,5 @@ internal class Program
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,13 @@
|
|||||||
<returns></returns>
|
<returns></returns>
|
||||||
<exception cref="T:System.ArgumentException"></exception>
|
<exception cref="T:System.ArgumentException"></exception>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:StgSharp.Math.GetBits32(System.Single)">
|
||||||
|
<summary>
|
||||||
|
Get the bits of a float number
|
||||||
|
</summary>
|
||||||
|
<param name="x">The given float number</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:StgSharp.Math.Log(System.Single)">
|
<member name="M:StgSharp.Math.Log(System.Single)">
|
||||||
<summary>
|
<summary>
|
||||||
|
|
||||||
@@ -21,5 +28,13 @@
|
|||||||
Returns the value of ln(x).
|
Returns the value of ln(x).
|
||||||
</returns>
|
</returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:StgSharp.Math.Pow(System.Single,System.Single)">
|
||||||
|
<summary>
|
||||||
|
calculate the value of x^y
|
||||||
|
</summary>
|
||||||
|
<param name="x"></param>
|
||||||
|
<param name="y"></param>
|
||||||
|
<returns>Returns the value of x^y</returns>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user