using System; namespace Psychlops { public static class Math { public static readonly double PI = 3.14159265, E = 2.718281828459045, LOG2E = 1.44269504088896340736; public static Random random_generator; static Math() { random_generator = new Random(); } public static double max(double val1, double val2) { return val1 > val2 ? val1 : val2; } public static double min(double val1, double val2) { return val1 < val2 ? val1 : val2; } public static void shuffle(X[] array, int n) { int a; X tmp; for(int i = 1; i < n; i++){ a = random(i + 1); tmp = array[i]; array[i] = array[a]; array[a] = tmp; } } public static double mod(double lhs, double rhs) { return lhs - System.Math.Floor(lhs/rhs)*rhs; } public static double abs(double x) { return System.Math.Abs(x); } public static double sin(double x) { return System.Math.Sin(x); } public static double cos(double x) { return System.Math.Cos(x); } public static double tan(double x) { return System.Math.Tan(x); } public static double sqrt(double x) { return System.Math.Sqrt(x); } public static double exp(double x) { return System.Math.Exp(x); } public static double log(double x) { return System.Math.Log(x); } public static double log2(double val) { return log(val) * LOG2E; } /*public static int round(double val) { double integer_part, particle = modf(val, &integer_part); return ((particle < 0.5 | (particle == 0.5 && (int)integer_part % 2 == 0)) ? (int)integer_part : (int)integer_part + 1); }*/ public static double radius(double x, double y) { return System.Math.Sqrt(x * x + y * y); } public static double random() { return (random_generator.NextDouble()); } public static int random(int x) { return (int)((random_generator.NextDouble()) * x); } public static double random(double x) { return (random_generator.NextDouble()) * x; } public static double random(double x, double y) { return (random_generator.NextDouble()) * (y-x) + x; } public static double gaussian(double x, double sigma) { return exp(- (x*x) / (2*sigma*sigma)); } } }