public static float Divide(float a, float b) { if (b == 0) { Prog.ThrowError(3); } return(a / b); }
public static double Divide(double a, double b) { if (b == 0) { Prog.ThrowError(3); } return(a / b); }
public static float Reciprocal(float a) { if (a == 0) { Prog.ThrowError(5); } return(1 / a); }
public static double Reciprocal(double a) { if (a == 0) { Prog.ThrowError(5); } return(1 / a); }
//Checking for errors public bool Validate(string param) { if (!(ArrayLib.Count(param.ToCharArray(), '(') == ArrayLib.Count(param.ToCharArray(), ')'))) { Prog.ThrowError(1); return(false); } for (int i = 0; i < param.Length; i++) { if (ArrayLib.Contains(OPERATORS, param[i]) && ArrayLib.Contains(OPERATORS, param[i + 1])) { Prog.ThrowError(0); return(false); } } return(true); }
public static int Factorial(int a) { if (a < 0) { Prog.ThrowError(6); } if (a != (int)a) { Prog.ThrowError(7); } if (a == 0) { return(1); } else { return(a * Factorial(a - 1)); } }
public static double Sqr(int a) { if (a < 0) { Prog.ThrowError(4); } double guess = 1; while (guess * guess <= a) { guess++; } guess--; for (int i = 0; i < 10; i++) { double f = guess * guess - a; double f_der = 2 * guess; guess = guess - (f / f_der); } return(guess); }