daily update on 20230316 by nitload youmu
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,5 +8,18 @@ namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
{
|
||||
|
||||
public static unsafe float Abs(float x)
|
||||
{
|
||||
uint* a = (uint*)&x;
|
||||
*a &= 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
||||
return *(float*)a;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Calc
|
||||
{
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+27
-24
@@ -1,18 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Calc
|
||||
{
|
||||
/*本方法将小数部分统一提升至2^16处后进行线性近似
|
||||
const uint sqmov = 0b_0100_0111_1000_0000_0000_0000_0000_0000;
|
||||
const float sqmov1 = 0.0015947f;
|
||||
const float sqmov2 = 156.7673435f;
|
||||
const float sqmov3 = 261.2776027f;
|
||||
/**/
|
||||
public static unsafe float Sqrt(float x)
|
||||
{
|
||||
/*
|
||||
@@ -21,10 +12,9 @@ namespace StgSharp.Math
|
||||
* (补充:指数最低位被加到小数位中以抵消一个多余的2 ^ 1的影响)
|
||||
* 小数部分则统一乘以2 ^ 16后由y = Sqrt(x)在1.5 * 2 ^ 16处的切线近似
|
||||
* 为简化操作,提高计算速度,切线左界被移动到远点
|
||||
* 在进一步简化操作后,计算精度达到0.5%,速度约为.Net库函数的1.8倍
|
||||
* 在进一步简化操作后,计算精度达到0.5%,速度约为.Net库函数的3倍
|
||||
*/
|
||||
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
@@ -33,41 +23,54 @@ namespace StgSharp.Math
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* 提取指数位并减去指数位中的127
|
||||
* 由于平方根仅对正数有效
|
||||
* 故不考虑正负号
|
||||
*/
|
||||
/*
|
||||
* 提取指数位并减半
|
||||
* 由于平方根仅对正数有效
|
||||
* 故不考虑正负号
|
||||
*/
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
if (x == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//提取指数位并减去指数位中的127
|
||||
//由于平方根仅对正数有效
|
||||
//故不考虑正负号
|
||||
uint a = *(uint*)&x;
|
||||
uint f = a;
|
||||
f >>= 23;
|
||||
f /= 2;
|
||||
f += 64;
|
||||
|
||||
/*
|
||||
* 提取小数位
|
||||
* 由于平方根仅对正数有效
|
||||
* 故不考虑正负号
|
||||
*/
|
||||
//提取小数位
|
||||
//由于平方根仅对正数有效
|
||||
//故不考虑正负号
|
||||
|
||||
a -= 0b_0011_1111_0000_0000_0000_0000_0000_0000;
|
||||
uint e = a << 8;
|
||||
e >>= 8;
|
||||
|
||||
/*线性近似*/
|
||||
//线性近似
|
||||
e *= 0b_1101_0001;
|
||||
e >>= 24;
|
||||
e += 0b_0000_0000_0001_0000_1010_1000_1110_0010;
|
||||
|
||||
/*还原指数*/
|
||||
//还原指数
|
||||
f <<= 23;
|
||||
e += f;
|
||||
|
||||
float result = *(float*)&e;
|
||||
result = (result + x / result) / 2;
|
||||
return (result + x / result) / 2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,6 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Colum2D operator *(Colum2D colum, float x)
|
||||
{
|
||||
return new Colum2D(colum.X * x,colum.Y * x);
|
||||
|
||||
@@ -771,7 +771,6 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static unsafe Matrix4x2 multiple(this Matrix4x2 matrix1, Matrix2x2 matrix2)
|
||||
{
|
||||
float* p = &matrix1.row1.X;
|
||||
@@ -845,7 +844,7 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="matrix1"></param>
|
||||
@@ -911,15 +910,73 @@ namespace StgSharp.Math
|
||||
var a22 = new Colum2D(*(p1 + 8), *(p1 + 11));
|
||||
|
||||
var b1 = new Matrix2x2(*(p2 + 0), *(p2 + 0), *(p2 + 0), *(p2 + 0));
|
||||
var B2 = matrix2.row3;
|
||||
var b2 = matrix2.row3;
|
||||
|
||||
var c1 = a11.multiple(b1) + a12.multiple(b2);
|
||||
var c2 = a21.multiple(b1) + a22.multiple(b2);
|
||||
|
||||
return new Matrix4x2(c1.row1,c1.row2,c2.row1,c2.row2);
|
||||
|
||||
}
|
||||
|
||||
public static unsafe Matrix4x3 multiple(this Matrix4x3 matrix1, Matrix3x3 matrix2)
|
||||
{ }
|
||||
{
|
||||
float* p1 = &matrix1.row1.X;
|
||||
float* p2 = &matrix2.row1.X;
|
||||
|
||||
var a11 = new Matrix2x2(*(p1 + 0), *(p1 + 1), *(p1 + 3), *(p1 + 4));
|
||||
var a12 = new Colum2D(*(p1 + 2), *(p1 + 5));
|
||||
var a21 = new Matrix2x2(*(p1 + 6), *(p1 + 7), *(p1 + 9), *(p1 + 10));
|
||||
var a22 = new Colum2D(*(p1 + 8), *(p1 + 11));
|
||||
|
||||
var b11 = new Matrix2x2(*(p2 + 0), *(p2 + 1), *(p2 + 3), *(p2 + 4));
|
||||
var b12 = new Colum2D(*(p2 + 2), *(p2 + 5));
|
||||
var b21 = new Vec2D(*(p2 + 9), *(p2 + 10));
|
||||
var b22 = matrix2.row3.Z;
|
||||
|
||||
var c11 = a11.multiple(b11) + a12.multiple(b21);
|
||||
var c12 = a11.multiple(b12) + a12 * b22;
|
||||
var c21 = a21.multiple(b11) + a22.multiple(b21);
|
||||
var c22 = a21.multiple(b12) + a22 * b22;
|
||||
|
||||
float* p3 = &c11.row1.X;
|
||||
float* p4 = &c21.row1.X;
|
||||
|
||||
return new Matrix4x3(
|
||||
*(p3 + 0), *(p3 + 1),c12.X,
|
||||
*(p3 + 2), *(p3 + 3),c12.Y,
|
||||
*(p4 + 0), *(p4 + 1),c22.X,
|
||||
*(p4 + 2), *(p4 + 3),c22.Y
|
||||
);
|
||||
}
|
||||
|
||||
public static unsafe Matrix4x4 multiple(this Matrix4x3 matrix1, Matrix3x4 matrix2)
|
||||
{ }
|
||||
{
|
||||
float* p1 = &matrix1.row1.X;
|
||||
float* p2 = &matrix2.row1.X;
|
||||
|
||||
var a11 = new Matrix2x2(*(p1 + 0), *(p1 + 1), *(p1 + 3), *(p1 + 4));
|
||||
var a12 = new Colum2D(*(p1 + 2), *(p1 + 5));
|
||||
var a21 = new Matrix2x2(*(p1 + 6), *(p1 + 7), *(p1 + 9), *(p1 + 10));
|
||||
var a22 = new Colum2D(*(p1 + 8), *(p1 + 11));
|
||||
|
||||
var b11 = new Matrix2x2(*(p2 + 0), *(p2 + 1), *(p2 + 4), *(p2 + 5));
|
||||
var b12 = new Matrix2x2(*(p2 + 2), *(p2 + 3), *(p2 + 6), *(p2 + 7));
|
||||
var b21 = matrix2.row3.Point1;
|
||||
var b22 = matrix2.row3.Point2;
|
||||
|
||||
var c11 = a11.multiple(b11) + a12.multiple(b21);
|
||||
var c12 = a11.multiple(b12) + a12.multiple(b22);
|
||||
var c21 = a21.multiple(b11) + a22.multiple(b21);
|
||||
var c22 = a21.multiple(b12) + a22.multiple(b22);
|
||||
|
||||
return new Matrix4x4(
|
||||
new Vec4D(c11.row1, c12.row1),
|
||||
new Vec4D(c11.row2, c12.row2),
|
||||
new Vec4D(c21.row1, c22.row1),
|
||||
new Vec4D(c21.row2, c22.row2)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -19,13 +19,6 @@
|
||||
<param name="x"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Calc.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.Calc.Log(System.Single)">
|
||||
<summary>
|
||||
|
||||
@@ -179,6 +172,14 @@
|
||||
<param name="matrix2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.VectorCalc.multiple(StgSharp.Math.Matrix3x2,StgSharp.Math.Matrix2x2)">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<param name="matrix1"></param>
|
||||
<param name="matrix2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.VectorCalc.multiple(StgSharp.Math.Matrix3x2,StgSharp.Math.Matrix2x3)">
|
||||
<summary>
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
0b8c0a7b886549f6ada3150538cfdb0d2275591c
|
||||
3a9e429a025cbd1bcea4abf9fbdb2cf05dc117a7
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -19,13 +19,6 @@
|
||||
<param name="x"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Calc.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.Calc.Log(System.Single)">
|
||||
<summary>
|
||||
|
||||
@@ -179,6 +172,14 @@
|
||||
<param name="matrix2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.VectorCalc.multiple(StgSharp.Math.Matrix3x2,StgSharp.Math.Matrix2x2)">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<param name="matrix1"></param>
|
||||
<param name="matrix2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.VectorCalc.multiple(StgSharp.Math.Matrix3x2,StgSharp.Math.Matrix2x3)">
|
||||
<summary>
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -7,17 +7,43 @@ internal class Program
|
||||
{
|
||||
private unsafe static void Main(string[] args)
|
||||
{
|
||||
var a = new Matrix3x2(1, 2, 3, 4, 5, 6);
|
||||
var b = new Matrix2x2(1, 2, 3, 4);
|
||||
var c = new Colum2D(1, 2);
|
||||
var d = new Vec2D(1, 2);
|
||||
var e = new Vec3D(1,2,3);
|
||||
var f = new Matrix2x2(1,2,3,4);
|
||||
|
||||
float a = MathF.Sqrt(10.00f) ;
|
||||
Console.WriteLine(a);
|
||||
Console.WriteLine("\n");
|
||||
Console.WriteLine(a.multiple(b));
|
||||
|
||||
|
||||
|
||||
/*
|
||||
double time;
|
||||
TimeSpan span;
|
||||
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
Stopwatch stopwatch01 = Stopwatch.StartNew();
|
||||
stopwatch01.Start();
|
||||
for (int t = 0; t < 1000000; t++)
|
||||
{
|
||||
float a = Calc.Sqrt(t);
|
||||
}
|
||||
stopwatch01.Stop();
|
||||
span = stopwatch01.Elapsed;
|
||||
time = span.TotalMilliseconds;
|
||||
Console.WriteLine(time);
|
||||
|
||||
Stopwatch stopwatch02 = new Stopwatch();
|
||||
stopwatch02.Start();
|
||||
for (int t = 0; t < 1000000; t++)
|
||||
{
|
||||
float a = MathF.Sqrt(t);
|
||||
}
|
||||
stopwatch02.Stop();
|
||||
span = stopwatch02.Elapsed;
|
||||
time = span.TotalMilliseconds;
|
||||
Console.WriteLine(time);
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -19,13 +19,6 @@
|
||||
<param name="x"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Calc.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.Calc.Log(System.Single)">
|
||||
<summary>
|
||||
|
||||
@@ -179,6 +172,14 @@
|
||||
<param name="matrix2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.VectorCalc.multiple(StgSharp.Math.Matrix3x2,StgSharp.Math.Matrix2x2)">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<param name="matrix1"></param>
|
||||
<param name="matrix2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.VectorCalc.multiple(StgSharp.Math.Matrix3x2,StgSharp.Math.Matrix2x3)">
|
||||
<summary>
|
||||
|
||||
|
||||
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