arcsin(x) added

This commit is contained in:
Nitload
2023-01-26 01:45:38 +08:00
parent 05869ac0ae
commit f75fcacc0d
36 changed files with 212 additions and 12 deletions
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp
{
//对4字节空间的联合体的C#实现
[StructLayout(LayoutKind.Explicit, Size = 4)]
public struct Union4
{
[FieldOffset(0)]
public byte b0;
[FieldOffset(1)]
public byte b1;
[FieldOffset(2)]
public byte b2;
[FieldOffset(3)]
public byte b3;
//得到对应的int值
[FieldOffset(0)]
public uint i;
//得到对应的float值
[FieldOffset(0)]
public float f;
public Union4(float x, uint y)
{
b0 = 0;
b1 = 0;
b2 = 0;
b3 = 0;
i = 0;
f = x;
y = i;
}
}
}
+30
View File
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp
{
//对8字节空间的联合体的C#实现
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct Union8
{
[FieldOffset(0)]
public byte b0;
[FieldOffset(1)]
public byte b1;
[FieldOffset(2)]
public byte b2;
[FieldOffset(3)]
public byte b3;
//得到对应的int值
[FieldOffset(0)]
public int i1;
[FieldOffset(4)]
public int i2;
//得到对应的float值
[FieldOffset(0)]
public double f;
}
}
+92
View File
@@ -0,0 +1,92 @@
// some of the code is rewritten from the AMD code:
// https://github.com/amd/aocl-libm-ose/blob/a43e092b03213eb0e129a1cc129900e6e4475778/src/ref/asinf.c
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
public static unsafe partial class Math
{
const float
piby2_tail = 7.5497894159e-08f, /* 0x33a22168 */
hpiby2_head = 7.8539812565e-01f, /* 0x3f490fda */
piby2 = 1.5707963705e+00f; /* 0x3fc90fdb */
/// <summary>
/// Reurns the value of ArcSin(x)
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static float ASin(float x )
{
int sign = 1;
float y ;
if (x<0)
{
sign = -1;
y = -x;
}
else
{
y = x;
}
if ( x>1)
{
throw new ArgumentException();
}
float r, s, u, v = 0.0f;
bool transform = (y >= 0.5f);
if (transform)
{
r = 0.5f * (1.0f - y);
s = StgSharp.Math.Sqrt(r);
y = s;
}
else
{
r = y * y;
}
u= r * (0.184161606965100694821398249421F +
(-0.0565298683201845211985026327361F +
(-0.0133819288943925804214011424456F -
0.00396137437848476485201154797087F * r) * r) * r) /
(1.10496961524520294485512696706F -
0.836411276854206731913362287293F * r);
/**/
if (transform)
{
float c, s1, p, q;
uint us;
us = *(uint*)&s;
uint uss = us & 0xffff0000;
s1 = *(float*)&uss;
c = (r - s1 * s1) / (s + s1);
p = 2.0F * s * u - (piby2_tail - 2.0F * c);
q = hpiby2_head - 2.0F * s1;
v = hpiby2_head - (p - q);
}
else
{
v = y + y * u;
}/**/
return sign * v * 90 / piby2;
}
}
}
+10
View File
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp
{
public static unsafe partial class Math
{
}
}
-1
View File
@@ -8,7 +8,6 @@ namespace StgSharp
public static partial class Math
{
/*本方法将小数部分统一提升至2^16处后进行线性近似
const uint sqmov = 0b_0100_0111_1000_0000_0000_0000_0000_0000;
const float sqmov1 = 0.0015947f;
const float sqmov2 = 156.7673435f;
@@ -4,6 +4,14 @@
<name>StgSharp</name>
</assembly>
<members>
<member name="M:StgSharp.Math.ASin(System.Single)">
<summary>
Reurns the value of ArcSin(x)
</summary>
<param name="x"></param>
<returns></returns>
<exception cref="T:System.ArgumentException"></exception>
</member>
<member name="M:StgSharp.Math.Log(System.Single)">
<summary>
@@ -1 +1 @@
db0ba6dd25ed071a0f5414145ab29a83438c6530
b7317d4b12ba4162c78ad3d204d71202d31826dd
@@ -4,6 +4,14 @@
<name>StgSharp</name>
</assembly>
<members>
<member name="M:StgSharp.Math.ASin(System.Single)">
<summary>
Reurns the value of ArcSin(x)
</summary>
<param name="x"></param>
<returns></returns>
<exception cref="T:System.ArgumentException"></exception>
</member>
<member name="M:StgSharp.Math.Log(System.Single)">
<summary>