示例#1
0
//         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);
    }
示例#2
0
 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);
 }
示例#3
0
    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));
    }
示例#4
0
    public static FloatI DeltaAngle(FloatI current, FloatI target)
    {
        FloatI num = FloatIMath.Repeat(target - current, 360f);

        if (num > 180f)
        {
            num -= 360f;
        }
        return(num);
    }
示例#5
0
 public static FloatI Repeat(FloatI t, FloatI length)
 {
     return(t - FloatIMath.Floor(t / length) * length);
 }
示例#6
0
 public static FloatI PingPong(FloatI t, FloatI length)
 {
     t = FloatIMath.Repeat(t, length * 2f);
     return(length - FloatIMath.Abs(t - length));
 }
示例#7
0
 public static FloatI MoveTowardsAngle(FloatI current, FloatI target, FloatI maxDelta)
 {
     target = current + FloatIMath.DeltaAngle(current, target);
     return(FloatIMath.MoveTowards(current, target, maxDelta));
 }
示例#8
0
 public static FloatI Lerp(FloatI from, FloatI to, FloatI t)
 {
     return(from + (to - from) * FloatIMath.Clamp01(t));
 }
示例#9
0
 public FloatI(double a)
 {
     m_numerator = FloatIMath.RoundToInt(a * m_denominator);
 }
示例#10
0
    //public const long m_maybeOverflow = m_denominator * 10000;


    public FloatI(float a)
    {
        m_numerator = (int)FloatIMath.RoundToLong(a * m_denominator);
    }