예제 #1
0
 public static FPLong Abs(FPLong v)
 {
     if (v._raw < 0) {
         return v.Inverse;
     }
     else {
         return v;
     }
 }
예제 #2
0
        public static FPLong Sqrt(FPLong f, int numberOfIterations)
        {
            if (f._raw < 0) //NaN in Math.Sqrt
                throw new ArithmeticException("Input Error");
            if (f._raw == 0)
                return 0;
            FPLong k = f + FPLong.OneFP >> 1;
            for (int i = 0; i < numberOfIterations; i++)
                k = (k + (f / k)) >> 1;

            if (k._raw < 0)
                throw new ArithmeticException("Overflow");
            else
                return k;
        }
예제 #3
0
 public static FPLong Min(FPLong v1, FPLong v2)
 {
     return (v1._raw < v2._raw) ? v1 : v2;
 }
예제 #4
0
 public static FPLong Max(FPLong v1, FPLong v2)
 {
     return (v1._raw > v2._raw) ? v1 : v2;
 }
예제 #5
0
 public static FPLong Clamp(FPLong value, FPLong min, FPLong max)
 {
     return (value > min) ? ((value < max) ? value : max) : min;
 }
예제 #6
0
 public static FPLong Sqrt(FPLong f)
 {
     byte numberOfIterations = 8;
     if (f._raw > 100 * FPLong.OneL)
         numberOfIterations = 12;
     if (f._raw > 1000 * FPLong.OneL)
         numberOfIterations = 16;
     return Sqrt(f, numberOfIterations);
 }