/// <summary> /// Метод GetFermat производит расчет простых чисел Ферма /// </summary> /// <param name="n">Неотрицательное целое число</param> /// <returns>Возращает простые числа Ферма</returns> public static Int32[] GetFermat(this Int32[] n) { Int32[] f = null; for (Int32 i = 0; i < n.Count(); i++) { if (n[i] >= 0) { f[i] = ArithmeticFunctions <Int32> .PowTwo(2, ArithmeticFunctions <Int32> .PowTwo(2, n[i])) + 1; } } return(f); }
// mn = 2 ^ n - 1 /// <summary> /// Метод GetMersennes производит расчет простых четных чисел Марсена /// </summary> /// <param name="n">Четное число больше нуля</param> /// <returns>Возращает массив простых чисел Марсена</returns> public static Int32[] GetMersennes(this Int32[] n) { Int32[] f = null; for (Int32 i = 0; i < n.Count(); i++) { if (n[i] % 2 == 0) { f[i] += ArithmeticFunctions <Int32> .PowTwo(2, n[i]) - 1; } } return(f); }
/// <summary> /// Performs the binary(2 operand) operation described by a given opcode value. If the /// opcode does not correspond to a binary operation, the first operand is returned /// (like an identity function, but only for the first operand) /// </summary> /// <param name="opcode">opcode corresponding to the operation to perform</param> /// <param name="firstOperand">the first operand for the operation</param> /// <param name="secondOperand">the second operand for the operation</param> /// <returns>the result of the operation</returns> private decimal PerformBinaryOperation(Opcodes opcode, decimal firstOperand, decimal secondOperand) { switch (opcode) { case Opcodes.AdditionOperation: return(ArithmeticFunctions.CalculateAddition(firstOperand, secondOperand)); case Opcodes.SubtractionOperation: return(ArithmeticFunctions.CalculateSubtraction(firstOperand, secondOperand)); case Opcodes.MultiplicationOperation: return(ArithmeticFunctions.CalculateMultiplication(firstOperand, secondOperand)); case Opcodes.DivisionOperation: return(ArithmeticFunctions.CalculateDivision(firstOperand, secondOperand)); default: return(firstOperand); } }
/// <summary> /// Метод QuadraticEquationFunc производит решение квадратного уровнения /// </summary> /// <param name="a">Первый коэффициент</param> /// <param name="b">Второй коэффициент</param> /// <param name="c">Свободный член</param> /// <returns>Возращает массив коэфициентов</returns> public static Double[] QuadraticEquationFunc(Double a, Double b, Double c) { Double d = ArithmeticFunctions <Double> .DivideTwo(ArithmeticFunctions <Double> .MultiplyTwo(b, b), ArithmeticFunctionsExcellent <Double, Double> .MultiplyTwo(ArithmeticFunctionsExcellent <Double, Int32> .MultiplyTwo(a, 4), c)); if (d > 0) { Double x1 = (-b + Math.Sqrt(d)) / 2 / a; Double x2 = (-b - Math.Sqrt(d)) / 2 / a; return(new Double[] { x1, x2 }); } else if (d == 0) { Double x1 = b / 2 / a; Double x2 = b / 2 / a; return(new Double[] { x1, x2 }); } return(null); }