/// <summary> /// Calls function from IVSMath N times. /// Returns difference of two parametrs. /// Throws OverflowException if the difference of two parametrs is lower then double.MinValue or higher than double.MaxValue /// </summary> /// <exception cref="OverflowException">Thrown when difference overflows the type double</exception> /// <param name="minuend">The number that is to be subtracted from.</param> /// <param name="subtrahend">The number that is to be subtracted.</param> /// <returns>Difference of two parametrs</returns> public static double Subtract(double minuend, double subtrahend) { double res = 0; for (int i = 0; i < N; i++) { res = IVSMath.Subtract(minuend, subtrahend); } return(res); }
/// <summary> /// Calls function from IVSMath N times. /// Calculates the Inverse of given number. /// </summary> /// <param name="base_">Number which is inversed</param> /// <exception cref="DivideByZeroException">Given number cannot be zero.</exception> /// <exception cref="OverflowException">When the number is too high/low</exception> /// <returns>If the function is successful, it returns inversed number.</returns> public static double Inverse(double base_) { double res = 0; for (int i = 0; i < N; i++) { res = IVSMath.Inverse(base_); } return(res); }
/// <summary> /// Calls function from IVSMath N times. /// Returns sum of two parametrs. /// Throws OverflowException if the sum of two parametrs is bigger then double.MaxValue or lower than double.MinValue /// </summary> /// <exception cref="OverflowException">Thrown when sum overflows the type double</exception> /// <param name="augend">First number to add</param> /// <param name="addend">Second number to add</param> /// <returns>Sum of two arguments</returns> public static double Add(double augend, double addend) { double res = 0; for (int i = 0; i < N; i++) { res = IVSMath.Add(augend, addend); } return(res); }
/// <summary> /// Calls function from IVSMath N times. /// Calculates the factorial of a given non-negative whole number. /// Note: returns a double, so not all digits are computed after a certain threshold. /// </summary> /// <exception cref="ArithmeticException">The given number is outside the domain of the factorial function.</exception> /// <exception cref="OverflowException">The resulting factorial is too large to be stored by a double.</exception> /// <param name="a">The number to calculate the factorial of</param> /// <returns>The factorial of the given number</returns> public static double Factorial(int a) { double res = 0; for (int i = 0; i < N; i++) { res = IVSMath.Factorial(a); } return(res); }
/// <summary> /// Calls function from IVSMath N times. /// Returns a specified number raised to the specified power /// Throws Excpetion if the result is about to overflow, there is division by zero, or base_ = exponent = 0 /// </summary> /// <exception cref="ArithmeticException">Thrown when there is 0^0 operation which is not allowed</exception> /// <exception cref="DivideByZeroException">Thrown when exponent is negative and base is zero which is not allowed operation</exception> /// <param name="base_">A number to be raised</param> /// <param name="exponent">A number that specifies a power</param> /// <param name="ignoreInfinity">Specifies if method should ignore infinity or not. False by default</param> /// <returns>A number raised to a specified power</returns> public static double Power(double base_, int exponent, bool ignoreInfinity = false) { double res = 0; for (int i = 0; i < N; i++) { res = IVSMath.Power(base_, exponent, ignoreInfinity); } return(res); }
/// <summary> /// Calls function from IVSMath N times. /// Calculates the Nth root of given number. /// </summary> /// <param name="radicand">Number which is having its square Nth root taken.</param> /// <param name="degree">The value of N.</param> /// <exception cref="ArithmeticException">Thrown when radicand is negative and degree even at the same time.</exception> /// <exception cref="ArithmeticException">Thrown when degree is zero which cannot be processed.</exception> /// <returns>If the function is successful, it returns value of Nth root.</returns> public static double Root(double radicand, int degree) { double res = 0; for (int i = 0; i < N; i++) { res = IVSMath.Root(radicand, degree); } return(res); }
/// <summary> /// Calls function from IVSMath N times. /// Returns quotient of the two given numbers /// Throws OverflowException if the quotient is too high /// </summary> /// <exception cref="OverflowException">Thrown when quotient overflows the type double</exception> /// <exception cref="DivideByZeroException">Thrown when divisor (second argument) is zero</exception> /// <param name="dividend">Number that is being seperated by the other number</param> /// <param name="divisor">The other number</param> /// <returns>Returns dividend / divisor</returns> public static double Divide(double dividend, double divisor) { double res = 0; for (int i = 0; i < N; i++) { res = IVSMath.Divide(dividend, divisor); } return(res); }
/// <summary> /// Calls function from IVSMath N times. /// Returns product of the two given numbers. /// Throws OverflowException if the product is too high or too low. /// </summary> /// <exception cref="OverflowException">Thrown when product overflows the type double</exception> /// <param name="multiplier">A number that multiplies the other number</param> /// <param name="multiplicand">The other number</param> /// <returns>Returns multiplier x multiplicand</returns> public static double Multiply(double multiplier, double multiplicand) { double res = 0; for (int i = 0; i < N; i++) { res = IVSMath.Multiply(multiplier, multiplicand); } return(res); }
/// <summary>Calculates operations /// (<paramref name="object"/>,<paramref name="event"/>).</summary> /// <param name="object">Object sender</param> /// <param name="event">Event argument</param> /// <returns>Returns calculated double number.</returns> private double Calculate(string operation, double x, double y = 0) { switch (operation) // Decides what operation should be performed and If there is an error then its error string { case "+": try { return(IVSMath.Add(x, y)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; comma = false; wasError = true; return(double.NaN); } case "-": try { return(IVSMath.Subtract(x, y)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; comma = false; wasError = true; return(double.NaN); } case "*": try { return(IVSMath.Multiply(x, y)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } case "/": try { return(IVSMath.Divide(x, y)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } catch (DivideByZeroException) { tb_Out.Text = "Dělení nulou"; wasError = true; comma = false; return(double.NaN); } case "^": try { return(IVSMath.Power(x, Convert.ToInt32(y))); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } catch (DivideByZeroException) { tb_Out.Text = "Dělení nulou"; wasError = true; comma = false; return(double.NaN); } catch (ArithmeticException) { tb_Out.Text = "Nepovolená operace"; wasError = true; comma = false; return(double.NaN); } case "ⁿ√𝑥": try { return(IVSMath.Root(y, Convert.ToInt32(x))); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } catch (ArithmeticException) { tb_Out.Text = "Nepovolená operace"; wasError = true; comma = false; return(double.NaN); } case "𝑥^2": try { return(IVSMath.Power(x, 2)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } catch (ArithmeticException) { tb_Out.Text = "Nepovolená operace"; wasError = true; comma = false; return(double.NaN); } case "²√": try { return(IVSMath.Root(x, 2)); } catch (ArithmeticException) { tb_Out.Text = "Nepovolená operace"; wasError = true; comma = false; return(double.NaN); } case "!": try { return(IVSMath.Factorial((int)x)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } catch (ArithmeticException) { tb_Out.Text = "Nepovolená operace"; wasError = true; comma = false; return(double.NaN); } case "sin": try { return(IVSMath.Sine(x)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } catch (ArithmeticException) { tb_Out.Text = "Nepovolená operace"; wasError = true; comma = false; return(double.NaN); } case "cos": try { return(IVSMath.Cosine(x)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } catch (ArithmeticException) { tb_Out.Text = "Nepovolená operace"; wasError = true; comma = false; return(double.NaN); } case "tan": try { return(IVSMath.Tangent(x)); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } catch (ArithmeticException) { tb_Out.Text = "Nepovolená operace"; wasError = true; comma = false; return(double.NaN); } case "1/𝑥": try { return(IVSMath.Power(x, -1)); } catch (DivideByZeroException) { tb_Out.Text = "Dělení nulou"; wasError = true; comma = false; return(double.NaN); } catch (OverflowException) { tb_Out.Text = "Overflow chyba"; wasError = true; comma = false; return(double.NaN); } } return(0); }