public static dynamic RandomInt(dynamic a, dynamic b) { int resultA = DynamicCast.ConvertToInt(a); int resultB = DynamicCast.ConvertToInt(b); return(resultA < resultB?Utils.RandomInt(resultA, resultB) : Utils.RandomInt(resultB, resultA)); }
public static bool IsPrime(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); // http://en.wikipedia.org/wiki/Primality_test#Naive_methods if (Math.Abs(resultA - 2.0) < Tolerance || Math.Abs(resultA - 3.0) < Tolerance) { return(true); } // False if n is NaN, negative, is 1, or not whole. And false if n is divisible by 2 or 3. if ( double.IsNaN(resultA) || resultA <= 1 || Math.Abs(resultA % 1) > Tolerance || Math.Abs(resultA % 2) < Tolerance || Math.Abs(resultA % 3) < Tolerance) { return(false); } // Check all the numbers of form 6k +/- 1, up to sqrt(n). for (var x = 6; x <= Math.Sqrt(resultA) + 1; x += 6) { if (Math.Abs(resultA % (x - 1)) < Tolerance || Math.Abs(resultA % (x + 1)) < Tolerance) { return(false); } } return(true); }
public static dynamic Pow(dynamic a, dynamic b) { double resultA = DynamicCast.ConvertToDouble(a); double resultB = DynamicCast.ConvertToDouble(b); return(Math.Pow(resultA, resultB)); }
public static dynamic Sum(dynamic a, dynamic b) { double resultA = DynamicCast.ConvertToDouble(a); double resultB = DynamicCast.ConvertToDouble(b); return(resultA + resultB); }
public static bool DivisionBy(dynamic a, dynamic divisionBy) { double resultA = DynamicCast.ConvertToDouble(a); double resultDivisionBy = DynamicCast.ConvertToDouble(divisionBy); return(Math.Abs(resultA % resultDivisionBy) < Tolerance); }
public static dynamic RoundDown(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); resultA -= 0.5d; return(Math.Round(resultA)); }
public static char GetLetterFromEnd(dynamic text, dynamic index) { string resultText = ConvertToString(text); int resultIndex = DynamicCast.ConvertToInt(index); if (string.IsNullOrEmpty(resultText) || resultIndex == 0) { return('\0'); } return(resultText.Length - resultIndex > 0 ? resultText[resultText.Length - resultIndex] : '\0'); }
public static dynamic Division(dynamic a, dynamic b) { double resultA = DynamicCast.ConvertToDouble(a); double resultB = DynamicCast.ConvertToDouble(b); if (Math.Abs(resultB) < Tolerance) { return(double.PositiveInfinity); } return(resultA / resultB); }
public static string Substring(dynamic text, string where1, dynamic at1, string where2, dynamic at2) { string resultText = ConvertToString(text); int at1Result = DynamicCast.ConvertToInt(at1); int at2Result = DynamicCast.ConvertToInt(at2); var getAt = new Func <dynamic, int, int>((where, at) => { switch (@where) { case "FROM_START": at--; break; case "FROM_END": at = resultText.Length - at; break; case "FIRST": at = 0; break; case "LAST": at = resultText.Length - 1; break; default: throw new ApplicationException("Unhandled option (GetSubstring)."); } return(at); }); at1 = getAt(where1, at1Result); at2 = getAt(where2, at2Result) + 1; try { return(resultText.Substring(at1, at2 - at1)); } catch (Exception e) { Log($"Can not get Substring({at1}, {at2 - at1}); for {resultText}."); return(""); } }
public static dynamic Log10(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); return(Math.Log10(resultA)); }
public static dynamic Tan(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); return(Math.Tan(resultA / 180 * Math.PI)); }
public static dynamic Negative(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); return(-resultA); }
public static dynamic Pow10(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); return(Math.Pow(10.0, resultA)); }
public static dynamic Sqrt(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); return(Math.Sqrt(resultA)); }
public static dynamic Atan(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); return(Math.Atan(resultA) / Math.PI * 180); }
public static bool IsWhole(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); return(Math.Abs(resultA % 1) < Tolerance); }
public static bool IsNegative(dynamic a) { double resultA = DynamicCast.ConvertToDouble(a); return(resultA < 0); }