Sin, cos, tan 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.
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static partial class Math
|
||||
{
|
||||
|
||||
public static float Cos(float x)
|
||||
{
|
||||
float refer = x / 360.0f;
|
||||
refer -= (int)refer;
|
||||
|
||||
refer *= 40;
|
||||
int a = (int)refer; //大分度,查表
|
||||
refer -= a; //小分度,拟合
|
||||
|
||||
float refer2 = refer * refer;
|
||||
|
||||
|
||||
return -sinData[a] * (0.1570796327f * refer - 6.459640975e-4f * refer * refer2)
|
||||
+ cosData[a] * (1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,10 @@ namespace StgSharp
|
||||
/// </returns>
|
||||
public unsafe static float Log(float x)
|
||||
{
|
||||
|
||||
if (x<0)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
uint input = *(uint*)&x;
|
||||
|
||||
uint f = input;
|
||||
@@ -62,6 +65,13 @@ namespace StgSharp
|
||||
result +
|
||||
logArray[order];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static float Log(float x, float y)
|
||||
{
|
||||
return Log(x)/Log(y);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,47 @@ namespace StgSharp
|
||||
{
|
||||
public static partial class Math
|
||||
{
|
||||
private static readonly float[] sinData =
|
||||
{
|
||||
0f, 0.15643446239373f, 0.309016989278255f, 0.453990492577218f, 0.587785243621462f,
|
||||
0.707106771713121f, 0.80901698492516f, 0.891006515673128f, 0.951056509671091f, 0.987688336822657f,
|
||||
1f, 0.987688345205947f, 0.951056526231247f, 0.891006540002384f, 0.80901701642445f,
|
||||
0.707106809606826f, 0.587785286976515f, 0.453990540326073f, 0.309017040245177f, 0.156434515323744f,
|
||||
5.35897931701074E-08f, -0.156434409463716f, -0.309016938311333f, -0.453990444828362f, -0.587785200266408f,
|
||||
-0.707106733819413f, -0.809016953425868f, -0.891006491343869f, -0.951056493110931f, -0.987688328439363f,
|
||||
-0.999999999999997f, -0.987688353589235f, -0.951056542791401f, -0.891006564331638f, -0.809017047923737f,
|
||||
-0.70710684750053f, -0.587785330331566f, -0.453990588074927f, -0.309017091212098f, -0.156434568253757f,
|
||||
|
||||
|
||||
};
|
||||
private static readonly float[] cosData =
|
||||
{
|
||||
1f, 0.987688341014302f, 0.951056517951169f, 0.891006527837756f, 0.809017000674805f,
|
||||
0.707106790659974f, 0.587785265298989f, 0.453990516451646f, 0.309017014761716f, 0.156434488858737f,
|
||||
2.67948965850537E-08f, -0.156434435928723f, -0.309016963794794f, -0.453990468702791f, -0.587785221943935f,
|
||||
-0.707106752766267f, -0.809016969175515f, -0.891006503508499f, -0.951056501391011f, -0.98768833263101f,
|
||||
-0.999999999999999f, -0.987688349397591f, -0.951056534511324f, -0.891006552167012f, -0.809017032174094f,
|
||||
-0.707106828553679f, -0.587785308654041f, -0.4539905642005f, -0.309017065728638f, -0.156434541788751f,
|
||||
-8.03846893110719E-08f, 0.156434382998709f, 0.309016912827872f, 0.453990420953934f, 0.58778517858888f,
|
||||
0.707106714872559f, 0.809016937676222f, 0.891006479179238f, 0.951056484830851f, 0.987688324247716f,
|
||||
|
||||
|
||||
};
|
||||
|
||||
public static unsafe float Sin(float x)
|
||||
{
|
||||
float refer = x / 360.0f;
|
||||
refer -= (int)refer;
|
||||
|
||||
refer *= 40;
|
||||
int a = (int)refer; //大分度,查表
|
||||
refer -= a; //小分度,拟合
|
||||
|
||||
float refer2 = refer * refer;
|
||||
|
||||
|
||||
return sinData[a]*(1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2 )
|
||||
+ cosData[a] * (0.1570796327f * refer - 6.459640975e-4f * refer * refer2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public static partial class Math
|
||||
{
|
||||
|
||||
public static float Tan(float x)
|
||||
{
|
||||
float refer = x / 360.0f;
|
||||
refer -= (int)refer;
|
||||
|
||||
refer *= 40;
|
||||
int a = (int)refer; //大分度,查表
|
||||
refer -= a; //小分度,拟合
|
||||
|
||||
float refer2 = refer * refer;
|
||||
|
||||
float sin = (0.1570796327f * refer - 6.459640975e-4f * refer * refer2);
|
||||
float cos = (1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2);
|
||||
|
||||
return ( sinData[a] * cos + cosData[a] * sin )
|
||||
/ ( cosData[a] * cos - sinData[a] * sin );
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
9f6c1da9ad577916e70408e10ff0292581a33dcb
|
||||
db0ba6dd25ed071a0f5414145ab29a83438c6530
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -11,14 +11,12 @@ internal class Program
|
||||
Console.WriteLine(cc/2);
|
||||
/**/
|
||||
|
||||
|
||||
/*
|
||||
float aa = 261.2776027f;
|
||||
uint bb = *(uint*)&aa;
|
||||
Console.WriteLine(Convert.ToString(bb,toBase:2));
|
||||
Console.WriteLine(StgSharp.Math.Log(3.5f));
|
||||
Console.WriteLine(StgSharp.Math.Sin(1.06f));
|
||||
/**/
|
||||
|
||||
|
||||
/*
|
||||
for (int wasd = 0; wasd < 100; wasd++)
|
||||
{
|
||||
float time = 1000000;
|
||||
@@ -27,7 +25,7 @@ internal class Program
|
||||
stopwatch.Start(); // 开始监视代码运行时间
|
||||
for (float i = 2; i < time; i++)
|
||||
{
|
||||
a = StgSharp.Math.Log(i);
|
||||
a = StgSharp.Math.Tan(i);
|
||||
}
|
||||
stopwatch.Stop(); // 停止监视
|
||||
TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间
|
||||
@@ -41,7 +39,7 @@ internal class Program
|
||||
stopwatch1.Start();
|
||||
for (double i = 2; i < time2; i++)
|
||||
{
|
||||
b = System.Math.Log(i);
|
||||
b = System.Math.Tan(i);
|
||||
}
|
||||
stopwatch1.Stop();
|
||||
timespan = stopwatch1.Elapsed;
|
||||
@@ -51,13 +49,13 @@ internal class Program
|
||||
}
|
||||
/**/
|
||||
|
||||
/*
|
||||
|
||||
double accuracy = 0;
|
||||
for (float i = 1.001f; i < 4; i += 0.001f)
|
||||
for (float i = 1f; i < 4000000; i += 1f)
|
||||
{
|
||||
double r1 = StgSharp.Math.Log(i);
|
||||
double r2 = System.Math.Log(i);
|
||||
double ac = ( System.Math.Max(r1,r2)- System.Math.Min(r1, r2) ) / System.Math.Max(r1, r2);
|
||||
double r1 = StgSharp.Math.Sin(i);
|
||||
double r2 = System.Math.Sin(i * ( 2 * System.Math.PI) / 360);
|
||||
double ac = ( System.Math.Max(r1,r2)- System.Math.Min(r1, r2) ) / r2;
|
||||
if (ac>accuracy)
|
||||
{
|
||||
accuracy = ac;
|
||||
@@ -70,6 +68,8 @@ internal class Program
|
||||
}
|
||||
Console.WriteLine(accuracy);
|
||||
/**/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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.
Reference in New Issue
Block a user