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); }
public static __ct__ Csqrt(this __t.Name__ number) { if (number >= 0) { return(new __ct__(Sqrt(number), 0)); } else { return(new __ct__(0, Sqrt(-number))); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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 }
public static __t.Name__ Cosh(this __t.Name__ x) => __cast__System.Math.Cosh(x);
public static __t.Name__ Atan(this __t.Name__ x) => __cast__System.Math.Atan(x);
public static __t.Name__ Atan2(__t.Name__ y, __t.Name__ x) => __cast__System.Math.Atan2(y, x);
public static __t.Name__ Exp(this __t.Name__ x) => /*# if (t != Meta.DoubleType) { */ (__t.Name__) /*# } */ System.Math.Exp(x);
public static __t.Name__ AcosC(this __t.Name__ x) => __cast__System.Math.Acos(Clamp(x, -1, 1));
public static __t.Name__ Atanh(this __t.Name__ x) => __cast__(0.5 * System.Math.Log((1.0 + x) / (1.0 - x)));
public static double Log2(this __t.Name__ x) => x.Log() * Constant.Ln2Inv;
public static __t.Name__ PowerOfTwo(this __t.Name__ x) => /*# if (t != Meta.DoubleType) { */ (__t.Name__) /*# } */ System.Math.Pow(2, x);
public static __st.Name__ Square(this __t.Name__ x) => x * x;
public static bool IsPowerOfTwo(this __t.Name__ x) => (x & (x - 1)) == 0;
public static double Sqrt(this __t.Name__ x) => Math.Sqrt(x);
public static double Log(this __t.Name__ x, double basis) => x.Log() / basis.Log();
public static __t.Name__ Tanh(this __t.Name__ x) => __cast__System.Math.Tanh(x);
public static __t.Name__ Floor(this __t.Name__ x) => /*# if (t != Meta.DoubleType) { */ (__t.Name__) /*# } */ Math.Floor(x);
public static __t.Name__ Acosh(this __t.Name__ x) => __cast__System.Math.Log(x + System.Math.Sqrt(x * x - 1.0));
public static double Log10(this __t.Name__ x) => Math.Log10(x);
public static bool ApproximateEquals(this __t.Name__ x, __t.Name__ y, __t.Name__ epsilon) => Abs(x - y) <= epsilon;
public static __t.Name__ Abs(this __t.Name__ x) => Math.Abs(x);
public static __t.Name__ Acos(this __t.Name__ x) => __cast__System.Math.Acos(x);
public static __ct.Name__ Pow(this __t.Name__ x, __ct.Name__ y) => /*# if (ct != Meta.DoubleType) {*/ (__t.Name__) /*# } */ System.Math.Pow(x, y);