分散文件结构,添加了枚举类型的一个辅助类
This commit is contained in:
127
Runtime/MicroLibrary/MacroMath.cs
Normal file
127
Runtime/MicroLibrary/MacroMath.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><>ѧ<EFBFBD><D1A7>
|
||||
/// </summary>
|
||||
public static partial class MacroMath
|
||||
{
|
||||
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
/// <summary>
|
||||
/// <20><>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong MurmurFinalize(ulong index)
|
||||
{
|
||||
index ^= index >> 33;
|
||||
index *= 0xff51afd7ed558ccd;
|
||||
index ^= index >> 33;
|
||||
index *= 0xc4ceb9fe1a85ec53;
|
||||
index ^= index >> 33;
|
||||
return index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong RandomNumber(ulong index)
|
||||
{
|
||||
index *= 1103515245;
|
||||
index += 12345;
|
||||
index *= 6364136223846793005UL;
|
||||
index += 1442695040888963407UL;
|
||||
index %= 18446744073709551615UL;
|
||||
return index;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region <EFBFBD><EFBFBD>ѧ
|
||||
|
||||
/// <summary>
|
||||
/// pmod
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double PMod(double a, double b)
|
||||
{
|
||||
double z = a % b;
|
||||
double w = (z < 0) ? -1 : 1;
|
||||
z = (z < 0) ? -z : z;
|
||||
if(w < 0)
|
||||
return b - z;
|
||||
else
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float MinPositive(float a, float b)
|
||||
=> Math.Min(Math.Max(0, a), Math.Max(0, b));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int MinPositive(int a, int b)
|
||||
=> Math.Min(Math.Max(0, a), Math.Max(0, b));
|
||||
|
||||
#endregion
|
||||
|
||||
#region <EFBFBD>ֽڿ<EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetByteState(ref int target, int site, bool state)
|
||||
{
|
||||
if(state)
|
||||
target |= 1 << site;
|
||||
|
||||
else
|
||||
target &= 0xff - (1 << site);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void SetByteState(ref int target, Enum site, bool state)
|
||||
{
|
||||
SetByteState(ref target, Convert.ToInt32(site), state);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool GetByteState(int target, int site)
|
||||
{
|
||||
return (target >> site & 0x01) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool GetByteState(int target, Enum site)
|
||||
{
|
||||
return GetByteState(target, Convert.ToInt32(site));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user