daily update on 20230205 by nitload youmu
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class Math
|
||||
{
|
||||
|
||||
|
||||
public static unsafe float ACos(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;
|
||||
}/**/
|
||||
|
||||
v = sign * v * 90 / piby2;
|
||||
|
||||
return 90-v;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace StgSharp
|
||||
public static unsafe partial class Math
|
||||
{
|
||||
|
||||
const float
|
||||
private const float
|
||||
piby2_tail = 7.5497894159e-08f, /* 0x33a22168 */
|
||||
hpiby2_head = 7.8539812565e-01f, /* 0x3f490fda */
|
||||
piby2 = 1.5707963705e+00f; /* 0x3fc90fdb */
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static unsafe partial class Math
|
||||
{
|
||||
|
||||
public const float E = 2.718281828f;
|
||||
/// <summary>
|
||||
/// Get the value of E ^ x;
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <returns></returns>
|
||||
public static unsafe float Exp(float x)
|
||||
{
|
||||
if (x == 1)
|
||||
{
|
||||
return E;
|
||||
}
|
||||
if (x == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool sign = false;
|
||||
if (x<0)
|
||||
{
|
||||
sign = true;
|
||||
x = -x;
|
||||
}
|
||||
|
||||
float z = x , t;
|
||||
if (x<0.5f)
|
||||
{
|
||||
t = 1.0f + x * (
|
||||
1.0f + x * (
|
||||
0.5f + x * (
|
||||
0.1666666667f + x * (
|
||||
0.0416666666667f + x *
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,13 @@
|
||||
<returns></returns>
|
||||
<exception cref="T:System.ArgumentException"></exception>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Exp(System.Single)">
|
||||
<summary>
|
||||
Get the value of E ^ x;
|
||||
</summary>
|
||||
<param name="x"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.GetBits32(System.Single)">
|
||||
<summary>
|
||||
Get the bits of a float number
|
||||
|
||||
@@ -1 +1 @@
|
||||
d6533ff9d6a5f9bebff84d6c130d7f9b4e85612a
|
||||
57d2afd7a707b689bdeb3640509f8f39355cee04
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,13 @@
|
||||
<returns></returns>
|
||||
<exception cref="T:System.ArgumentException"></exception>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Exp(System.Single)">
|
||||
<summary>
|
||||
Get the value of E ^ x;
|
||||
</summary>
|
||||
<param name="x"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.GetBits32(System.Single)">
|
||||
<summary>
|
||||
Get the bits of a float number
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user