Exemplo n.º 1
0
    public static fInt Sqrt(fInt fi)
    {
        if (fi.value == 0)
        {
            return(new fInt(0, false));
        }

        fInt prev = new fInt(1);

        for (int i = 0; i < 20; i++)        //could probably go as low as 5 iterations
        {
            prev = prev - ((prev * prev - fi) / (2 * prev));
        }
        //Debug.Log("SQRT " + fi + ": " + prev + " vs " + System.Math.Sqrt(fi.value/(double)SCALE));

        //Round off at the end
        return(prev);


        //---NEWTON'S EQUATION---------- //http://en.wikipedia.org/wiki/Newton%27s_method#Square%5Froot%5Fof%5Fa%5Fnumber
        //f(x) = x^2 - NUMBER_TO_Sqrt
        //(derivative) f'(x) = 2x

        //loop through this multiple times to get more accurate results
        //prevX - f(prevX)/f'(prevX)
    }
Exemplo n.º 2
0
 public static fInt Max(fInt f1, fInt f2)
 {
     if (f1 > f2)
     {
         return(f1);
     }
     else
     {
         return(f2);
     }
 }
Exemplo n.º 3
0
 public static fInt Min(fInt f1, fInt f2)
 {
     if (f1 < f2)
     {
         return(f1);
     }
     else
     {
         return(f2);
     }
 }
Exemplo n.º 4
0
    public static fInt Round(fInt fi)
    {
        fInt fiDecimal = fi.Decimal;

        if (fiDecimal >= MakeFraction(1, 2))
        {
            return((fi - fiDecimal) + 1);
        }
        else
        {
            return(fi - fiDecimal);
        }
    }
Exemplo n.º 5
0
 public static fInt Tan(fInt fi)
 {
     return Sin(fi)/Cos(fi);
 }
Exemplo n.º 6
0
    public static fInt Sqrt(fInt fi)
    {
        if(fi.value == 0) return new fInt(0,false);

        fInt prev = new fInt(1);

        for(int i = 0; i < 20; i++) //could probably go as low as 5 iterations
        {
            prev = prev - ((prev * prev - fi)/(2 * prev));
        }
        //Debug.Log("SQRT " + fi + ": " + prev + " vs " + System.Math.Sqrt(fi.value/(double)SCALE));

        //Round off at the end
        return prev;

        //---NEWTON'S EQUATION---------- //http://en.wikipedia.org/wiki/Newton%27s_method#Square%5Froot%5Fof%5Fa%5Fnumber
        //f(x) = x^2 - NUMBER_TO_Sqrt
        //(derivative) f'(x) = 2x

        //loop through this multiple times to get more accurate results
        //prevX - f(prevX)/f'(prevX)
    }
Exemplo n.º 7
0
 public static fInt Sin(fInt fi)
 {
     return new fInt(SinLookUp((int)fi), false);
 }
Exemplo n.º 8
0
    public static fInt Round(fInt fi)
    {
        fInt fiDecimal = fi.Decimal;

        if(fiDecimal >= MakeFraction(1,2)) return (fi - fiDecimal) + 1;
        else return fi - fiDecimal;
    }
Exemplo n.º 9
0
 public static fInt Min(fInt f1, fInt f2)
 {
     if(f1 < f2) return f1;
     else return f2;
 }
Exemplo n.º 10
0
 public static fInt Max(fInt f1, fInt f2)
 {
     if(f1 > f2) return f1;
     else return f2;
 }
Exemplo n.º 11
0
 public static fInt Cos(fInt fi)
 {
     return new fInt(CosLookUp((int)fi), false);
 }
Exemplo n.º 12
0
 public static fInt Abs(fInt fi)
 {
     return new fInt(((fi.value < 0) ? -fi.value : fi.value), false);
 }
Exemplo n.º 13
0
 public static fInt Tan(fInt fi)
 {
     return(Sin(fi) / Cos(fi));
 }
Exemplo n.º 14
0
 public static fInt Cos(fInt fi)
 {
     return(new fInt(CosLookUp((int)fi), false));
 }
Exemplo n.º 15
0
 public static fInt Sin(fInt fi)
 {
     return(new fInt(SinLookUp((int)fi), false));
 }
Exemplo n.º 16
0
 public static fInt Abs(fInt fi)
 {
     return(new fInt(((fi.value < 0) ? -fi.value : fi.value), false));
 }