// public static FloatL SinOld(FloatL f) // { // return Math.Sin(f.ToDouble()); // } /// <summary> /// 牛顿法求平方根 /// </summary> /// <param name="c"></param> /// <returns></returns> public static FloatI SqrtOld(FloatI c) { if (c == 0) { return(0); } if (c < new FloatI(0)) { return(new FloatI(-1)); } FloatI err = FloatI.Epsilon; FloatI t = c; int count = 0; while (FloatIMath.Abs(t - c / t) > err * t) { count++; t = (c / t + t) / new FloatI(2.0f); if (count >= 20) { UnityEngine.Debug.LogWarning("FixPoint Sqrt " + c + " current sqrt " + t); break; } } return(t); }
public static FloatI MoveTowards(FloatI current, FloatI target, FloatI maxDelta) { if (FloatIMath.Abs(target - current) <= maxDelta) { return(target); } return(current + FloatIMath.Sign(target - current) * maxDelta); }
public static FloatI LerpAngle(FloatI a, FloatI b, FloatI t) { FloatI num = FloatIMath.Repeat(b - a, 360f); if (num > 180f) { num -= 360f; } return(a + num * FloatIMath.Clamp01(t)); }
public static FloatI DeltaAngle(FloatI current, FloatI target) { FloatI num = FloatIMath.Repeat(target - current, 360f); if (num > 180f) { num -= 360f; } return(num); }
public static FloatI Repeat(FloatI t, FloatI length) { return(t - FloatIMath.Floor(t / length) * length); }
public static FloatI PingPong(FloatI t, FloatI length) { t = FloatIMath.Repeat(t, length * 2f); return(length - FloatIMath.Abs(t - length)); }
public static FloatI MoveTowardsAngle(FloatI current, FloatI target, FloatI maxDelta) { target = current + FloatIMath.DeltaAngle(current, target); return(FloatIMath.MoveTowards(current, target, maxDelta)); }
public static FloatI Lerp(FloatI from, FloatI to, FloatI t) { return(from + (to - from) * FloatIMath.Clamp01(t)); }
public FloatI(double a) { m_numerator = FloatIMath.RoundToInt(a * m_denominator); }
//public const long m_maybeOverflow = m_denominator * 10000; public FloatI(float a) { m_numerator = (int)FloatIMath.RoundToLong(a * m_denominator); }