Exemplo n.º 1
0
        public static __t.Name__ ModP(this __t.Name__ a, __t.Name__ b)
        {
            var m = a % b;

            if (m < 0)
            {
                m += b;
            }
            return((__t.Name__)m);
        }
Exemplo n.º 2
0
 public static __ct__ Csqrt(this __t.Name__ number)
 {
     if (number >= 0)
     {
         return(new __ct__(Sqrt(number), 0));
     }
     else
     {
         return(new __ct__(0, Sqrt(-number)));
     }
 }
Exemplo n.º 3
0
 public static __t.Name__ Clamp(this __t.Name__ x, __t.Name__ a, __t.Name__ b)
 {
     if (x < a)
     {
         return(a);
     }
     if (x > b)
     {
         return(b);
     }
     return(x);
 }
Exemplo n.º 4
0
 public static __t.Name__ ClampExcl(this __t.Name__ x, Range1__t.Char__ range)
 {
     if (x < range.Min)
     {
         return(range.Min);
     }
     if (x >= range.Max)
     {
         return((__t.Name__)(range.Max - 1));
     }
     return(x);
 }
Exemplo n.º 5
0
 public static __t.Name__ ClampExcl(this __t.Name__ x, __t.Name__ a, __t.Name__ b)
 {
     if (x < a)
     {
         return(a);
     }
     if (x >= b)
     {
         return((__t.Name__)(b - 1));
     }
     return(x);
 }
Exemplo n.º 6
0
 public static __t.Name__ Clamp(this __t.Name__ x, Range1__t.Char__ range)
 {
     if (x < range.Min)
     {
         return(range.Min);
     }
     if (x > range.Max)
     {
         return(range.Max);
     }
     return(x);
 }
Exemplo n.º 7
0
 public static __t.Name__ NextPowerOfTwo(this __t.Name__ x)
 {
     --x;
     x |= x >> 1;
     x |= x >> 2;
     x |= x >> 4;
     x |= x >> 8;
     x |= x >> 16;
     //# if (t == Meta.LongType) {
     x |= x >> 32;
     //# }
     return(++x);
 }
Exemplo n.º 8
0
        public static bool IsPrime(this __t.Name__ value)
        {
            __t.Name__ imax = (__t.Name__)System.Math.Sqrt(value);

            for (__t.Name__ i = 2; i <= imax; i++)
            {
                if (value % i == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 9
0
 public static __t.Name__ PrevPowerOfTwo(this __t.Name__ x)
 {
     if (x <= 0)
     {
         return(0);
     }
     x >>= 1;
     x  |= x >> 1;
     x  |= x >> 2;
     x  |= x >> 4;
     x  |= x >> 8;
     x  |= x >> 16;
     //# if (t == Meta.LongType) {
     x |= x >> 32;
     //# }
     return(++x);
 }
Exemplo n.º 10
0
        public static __t.Name__ FastAtan2(__t.Name__ y, __t.Name__ x)
        {
            __t.Name__ angle;
            double     piThreeFourths = Constant.Pi * 3 / 4;
            double     yAbs           = y.Abs() + Constant <double> .PositiveTinyValue; // prevent 0/0 condition

            if (x >= 0)
            {
                double r = (x - yAbs) / (x + yAbs);
                angle = __cast__(Constant.PiQuarter * (1 - r));
            }
            else
            {
                double r = (x + yAbs) / (yAbs - x);
                angle = __cast__(piThreeFourths - Constant.PiQuarter * r);
            }

            return(y < 0 ? -angle : angle); // negate if in quad III or IV
        }
Exemplo n.º 11
0
 public static __t.Name__ Cosh(this __t.Name__ x) => __cast__System.Math.Cosh(x);
Exemplo n.º 12
0
 public static __t.Name__ Atan(this __t.Name__ x) => __cast__System.Math.Atan(x);
Exemplo n.º 13
0
 public static __t.Name__ Atan2(__t.Name__ y, __t.Name__ x) => __cast__System.Math.Atan2(y, x);
Exemplo n.º 14
0
 public static __t.Name__ Exp(this __t.Name__ x)
 => /*# if (t != Meta.DoubleType) { */ (__t.Name__) /*# } */ System.Math.Exp(x);
Exemplo n.º 15
0
 public static __t.Name__ AcosC(this __t.Name__ x) => __cast__System.Math.Acos(Clamp(x, -1, 1));
Exemplo n.º 16
0
 public static __t.Name__ Atanh(this __t.Name__ x)
 => __cast__(0.5 * System.Math.Log((1.0 + x) / (1.0 - x)));
Exemplo n.º 17
0
 public static double Log2(this __t.Name__ x) => x.Log() * Constant.Ln2Inv;
Exemplo n.º 18
0
 public static __t.Name__ PowerOfTwo(this __t.Name__ x)
 => /*# if (t != Meta.DoubleType) { */ (__t.Name__) /*# } */ System.Math.Pow(2, x);
Exemplo n.º 19
0
 public static __st.Name__ Square(this __t.Name__ x) => x * x;
Exemplo n.º 20
0
 public static bool IsPowerOfTwo(this __t.Name__ x) => (x & (x - 1)) == 0;
Exemplo n.º 21
0
 public static double Sqrt(this __t.Name__ x) => Math.Sqrt(x);
Exemplo n.º 22
0
 public static double Log(this __t.Name__ x, double basis) => x.Log() / basis.Log();
Exemplo n.º 23
0
 public static __t.Name__ Tanh(this __t.Name__ x) => __cast__System.Math.Tanh(x);
Exemplo n.º 24
0
 public static __t.Name__ Floor(this __t.Name__ x)
 => /*# if (t != Meta.DoubleType) { */ (__t.Name__) /*# } */ Math.Floor(x);
Exemplo n.º 25
0
 public static __t.Name__ Acosh(this __t.Name__ x)
 => __cast__System.Math.Log(x + System.Math.Sqrt(x * x - 1.0));
Exemplo n.º 26
0
 public static double Log10(this __t.Name__ x) => Math.Log10(x);
Exemplo n.º 27
0
 public static bool ApproximateEquals(this __t.Name__ x, __t.Name__ y, __t.Name__ epsilon)
 => Abs(x - y) <= epsilon;
Exemplo n.º 28
0
 public static __t.Name__ Abs(this __t.Name__ x) => Math.Abs(x);
Exemplo n.º 29
0
 public static __t.Name__ Acos(this __t.Name__ x) => __cast__System.Math.Acos(x);
Exemplo n.º 30
0
 public static __ct.Name__ Pow(this __t.Name__ x, __ct.Name__ y)
 => /*# if (ct != Meta.DoubleType) {*/ (__t.Name__) /*# } */ System.Math.Pow(x, y);