Daily update on 20231211 by nitload youmu
This commit is contained in:
@@ -1,52 +1,55 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe float ACos(float x)
|
||||
{
|
||||
return MathF.Acos(x);
|
||||
|
||||
int sign = 1;
|
||||
float y;
|
||||
/*
|
||||
int sign = 1;
|
||||
float y;
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
sign = -1;
|
||||
y = -x;
|
||||
}
|
||||
else
|
||||
{
|
||||
y = x;
|
||||
}
|
||||
if (x < 0)
|
||||
{
|
||||
sign = -1;
|
||||
y = -x;
|
||||
}
|
||||
else
|
||||
{
|
||||
y = x;
|
||||
}
|
||||
|
||||
if (x > 1)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
if (x > 1)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
float r, s, u, v = 0.0f;
|
||||
bool transform = (y >= 0.5f);
|
||||
float r, s, u, v = 0.0f;
|
||||
bool transform = (y >= 0.5f);
|
||||
|
||||
if (transform)
|
||||
{
|
||||
r = 0.5f * (1.0f - y);
|
||||
s = Calc.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)
|
||||
{
|
||||
r = 0.5f * (1.0f - y);
|
||||
s = Scaler.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)
|
||||
{
|
||||
@@ -65,11 +68,12 @@ namespace StgSharp.Math
|
||||
else
|
||||
{
|
||||
v = y + y * u;
|
||||
}/**/
|
||||
}
|
||||
|
||||
v = sign * v;
|
||||
|
||||
return piby2 - v;
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using System;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
|
||||
private const float
|
||||
@@ -26,7 +26,8 @@ namespace StgSharp.Math
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public static float ASin(float x)
|
||||
{
|
||||
|
||||
return MathF.Asin(x);
|
||||
/*
|
||||
int sign = 1;
|
||||
float y;
|
||||
|
||||
@@ -51,7 +52,7 @@ namespace StgSharp.Math
|
||||
if (transform)
|
||||
{
|
||||
r = 0.5f * (1.0f - y);
|
||||
s = Calc.Sqrt(r);
|
||||
s = Scaler.Sqrt(r);
|
||||
y = s;
|
||||
}
|
||||
else
|
||||
@@ -64,7 +65,7 @@ namespace StgSharp.Math
|
||||
0.00396137437848476485201154797087F * r) * r) * r) /
|
||||
(1.10496961524520294485512696706F -
|
||||
0.836411276854206731913362287293F * r);
|
||||
/**/
|
||||
/*
|
||||
|
||||
if (transform)
|
||||
{
|
||||
@@ -83,10 +84,10 @@ namespace StgSharp.Math
|
||||
else
|
||||
{
|
||||
v = y + y * u;
|
||||
}/**/
|
||||
}/*
|
||||
|
||||
return sign * v;
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
namespace StgSharp.Math
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe float ATan(float x)
|
||||
{
|
||||
return MathF.Atan(x);
|
||||
/*
|
||||
float sign = 1, angle = 0;
|
||||
if (x < 0)
|
||||
{
|
||||
@@ -75,7 +82,7 @@
|
||||
v *= sign;
|
||||
|
||||
return v;
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Globalization;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
|
||||
public static unsafe float Abs(float x)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Calc
|
||||
public static partial class Scaler
|
||||
{
|
||||
|
||||
public static float Cos(float x)
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace StgSharp.Math
|
||||
{
|
||||
public unsafe delegate float ScalarCalcHandler(float* x);
|
||||
|
||||
public static unsafe partial class Calc
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
|
||||
private static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
|
||||
@@ -17,7 +17,7 @@ namespace StgSharp.Math
|
||||
const uint PAGE_EXECUTE_READWRITE = 0x40;
|
||||
const uint MEM_RELEASE = 0x8000;
|
||||
|
||||
static Calc()
|
||||
static Scaler()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
|
||||
public const float E = 2.718281828f;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Calc
|
||||
public static partial class Scaler
|
||||
{
|
||||
|
||||
private static readonly float[] logArray =
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
/// <summary>
|
||||
/// calculate the value of x^y
|
||||
@@ -36,7 +36,7 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
z = Calc.Log(x) * y;
|
||||
z = Scaler.Log(x) * y;
|
||||
|
||||
bool sign = false;
|
||||
if (z < 0)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using StgSharp.Controlling;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
public static unsafe partial class Scaler
|
||||
{
|
||||
|
||||
internal static float currentSeed
|
||||
@@ -15,32 +16,41 @@ namespace StgSharp.Math
|
||||
= Calc.Abs(System.DateTime.UtcNow.GetHashCode());
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Random()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns a random float number between 0 and 1.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public static unsafe float Random()
|
||||
{
|
||||
public static unsafe float LowProceisionRandom()
|
||||
{
|
||||
float seed = currentSeed;
|
||||
|
||||
float sample = Calc.Pow(Calc.SeedSqrt(seed),2);
|
||||
float sample = Scaler.Pow(Scaler.SeedSqrt(seed), 2);
|
||||
float sample2 = (sample - seed) / seed;
|
||||
sample2 = Calc.Abs(sample2);
|
||||
sample2 = Scaler.Abs(sample2);
|
||||
|
||||
if (sample==1)
|
||||
if (sample == 1)
|
||||
{
|
||||
sample = sample2;
|
||||
}
|
||||
|
||||
|
||||
currentSeed = sample;
|
||||
sample2 *= 1000000;
|
||||
|
||||
float result = sample2-(int)sample2;
|
||||
float result = sample2 - (int)sample2;
|
||||
if (result == 0)
|
||||
{
|
||||
currentSeed = sample2+0.1f;
|
||||
result = Calc.Random();
|
||||
currentSeed = sample2 + 0.1f;
|
||||
result = Scaler.LowProceisionRandom();
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -52,8 +62,8 @@ namespace StgSharp.Math
|
||||
/// <returns></returns>
|
||||
public static unsafe int RandomSeed()
|
||||
{
|
||||
float seedValue1 = Random();
|
||||
float seedValue2 = Random();
|
||||
float seedValue1 = LowProceisionRandom();
|
||||
float seedValue2 = LowProceisionRandom();
|
||||
uint seedValueBits = *(uint*)&seedValue1;
|
||||
|
||||
float seedValue = seedValueBits * seedValue2;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Calc
|
||||
public static partial class Scaler
|
||||
{
|
||||
public const float Pi = 3.1415926f;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Calc
|
||||
public static partial class Scaler
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Sqrt(float x)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Calc
|
||||
public static partial class Scaler
|
||||
{
|
||||
|
||||
public static float Tan(float x)
|
||||
|
||||
Reference in New Issue
Block a user