42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
|
using System;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
public static class MathHelper
|
|||
|
{
|
|||
|
|
|||
|
public static T Min<T>(T a, T b) where T : IComparable<T>
|
|||
|
{
|
|||
|
return a.CompareTo(b) < 0 ? a : b;
|
|||
|
}
|
|||
|
public static T Max<T>(T a, T b)where T:IComparable<T>
|
|||
|
{
|
|||
|
return a.CompareTo(b)>0 ? a : b;
|
|||
|
}
|
|||
|
public static int RoundToInt(float d)
|
|||
|
{
|
|||
|
return (int)Math.Round(d, MidpointRounding.AwayFromZero);
|
|||
|
}
|
|||
|
public static long RoundToLong(float d)
|
|||
|
{
|
|||
|
return (long)Math.Round(d, MidpointRounding.AwayFromZero);
|
|||
|
}
|
|||
|
|
|||
|
public static double Abs(double v)
|
|||
|
{
|
|||
|
return v.CompareTo(0) < 0 ? -v : v;
|
|||
|
}
|
|||
|
public static int Abs(int v)
|
|||
|
{
|
|||
|
return v.CompareTo(0) < 0 ? -v : v;
|
|||
|
}
|
|||
|
public static string FloatToIntString(this float f)
|
|||
|
{
|
|||
|
return $"{f:f0}";
|
|||
|
}
|
|||
|
public static string FloatToPercentString(this float f)
|
|||
|
{
|
|||
|
return $"{f:p2}";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|