internal static PythonDictionary GetInvertedRegistry(CodeContext /*!*/ context) { EnsureModuleInitialized(context); return((PythonDictionary)PythonContext.GetContext(context).GetModuleState(_invertedRegistryKey)); }
private static int GetStackSize(CodeContext /*!*/ context) { return((int)PythonContext.GetContext(context).GetModuleState(_stackSizeKey)); }
private static long GetLockCount(CodeContext /*!*/ context) { return((long)PythonContext.GetContext(context).GetModuleState(_lockCountKey)); }
public static object iconcat(CodeContext /*!*/ context, object a, object b) { TestBothSequence(a, b); return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceAdd, a, b)); }
public static object Call(CodeContext /*!*/ context, Delegate @delegate, [ParamDictionary] IDictionary <object, object> dict, params object[] args) { return(PythonContext.GetContext(context).CallWithKeywords(@delegate, args, dict)); }
public static object irshift(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceRightShift, a, b)); }
public static object itruediv(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceTrueDivide, a, b)); }
public static object ne(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.NotEqual, a, b)); }
public static object gt(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.GreaterThan, a, b)); }
public static void setrecursionlimit(CodeContext /*!*/ context, int limit) { PythonContext.GetContext(context).RecursionLimit = limit; }
public static int getrecursionlimit(CodeContext /*!*/ context) { return(PythonContext.GetContext(context).RecursionLimit); }
public static string getdefaultencoding(CodeContext /*!*/ context) { return(PythonContext.GetContext(context).GetDefaultEncodingName()); }
/// <summary> /// Returns the digits for the format spec, no sign is included. /// </summary> private static string DoubleToFormatString(CodeContext /*!*/ context, double self, StringFormatSpec /*!*/ spec) { self = Math.Abs(self); const int DefaultPrecision = 6; int precision = spec.Precision ?? DefaultPrecision; string digits; switch (spec.Type) { case '%': { string fmt = "0." + new string('0', precision) + "%"; if (spec.ThousandsComma) { fmt = "#," + fmt; } digits = self.ToString(fmt, CultureInfo.InvariantCulture); break; } case 'f': case 'F': { string fmt = "0." + new string('0', precision); if (spec.ThousandsComma) { fmt = "#," + fmt; } digits = self.ToString(fmt, CultureInfo.InvariantCulture); break; } case 'e': case 'E': { string fmt = "0." + new string('0', precision) + spec.Type + "+00"; if (spec.ThousandsComma) { fmt = "#," + fmt; } digits = self.ToString(fmt, CultureInfo.InvariantCulture); break; } case '\0': case null: if (spec.Precision != null) { // precision applies to the combined digits before and after the decimal point // so we first need find out how many digits we have before... int digitCnt = 1; double cur = self; while (cur >= 10) { cur /= 10; digitCnt++; } // Use exponents if we don't have enough room for all the digits before. If we // only have as single digit avoid exponents. if (digitCnt > spec.Precision.Value && digitCnt != 1) { // first round off the decimal value self = MathUtils.RoundAwayFromZero(self, 0); // then remove any insignificant digits double pow = Math.Pow(10, digitCnt - Math.Max(spec.Precision.Value, 1)); self = self - (self % pow); // finally format w/ the requested precision string fmt = "0.0" + new string('#', spec.Precision.Value); digits = self.ToString(fmt + "e+00", CultureInfo.InvariantCulture); } else { // we're including all the numbers to the right of the decimal we can, we explicitly // round to match CPython's behavior int decimalPoints = Math.Max(spec.Precision.Value - digitCnt, 0); self = MathUtils.RoundAwayFromZero(self, decimalPoints); digits = self.ToString("0.0" + new string('#', decimalPoints)); } } else { // just the default formatting if (IncludeExponent(self)) { digits = self.ToString("0.#e+00", CultureInfo.InvariantCulture); } else if (spec.ThousandsComma) { digits = self.ToString("#,0.0###", CultureInfo.InvariantCulture); } else { digits = self.ToString("0.0###", CultureInfo.InvariantCulture); } } break; case 'n': case 'g': case 'G': { // precision applies to the combined digits before and after the decimal point // so we first need find out how many digits we have before... int digitCnt = 1; double cur = self; while (cur >= 10) { cur /= 10; digitCnt++; } // Use exponents if we don't have enough room for all the digits before. If we // only have as single digit avoid exponents. if (digitCnt > precision && digitCnt != 1) { // first round off the decimal value self = MathUtils.RoundAwayFromZero(self, 0); // then remove any insignificant digits double pow = Math.Pow(10, digitCnt - Math.Max(precision, 1)); double rest = self / pow; self = self - self % pow; if ((rest % 1) >= .5) { // round up self += pow; } string fmt; if (spec.Type == 'n' && PythonContext.GetContext(context).NumericCulture != PythonContext.CCulture) { // we've already figured out, we don't have any digits for decimal points, so just format as a number + exponent fmt = "0"; } else if (spec.Precision > 1 || digitCnt > 6) { // include the requested precision to the right of the decimal fmt = "0.#" + new string('#', precision); } else { // zero precision, no decimal fmt = "0"; } if (spec.ThousandsComma) { fmt = "#," + fmt; } digits = self.ToString(fmt + (spec.Type == 'G' ? "E+00" : "e+00"), CultureInfo.InvariantCulture); } else { // we're including all the numbers to the right of the decimal we can, we explicitly // round to match CPython's behavior if (self < 1) { // no implicit 0 digitCnt--; } int decimalPoints = Math.Max(precision - digitCnt, 0); self = MathUtils.RoundAwayFromZero(self, decimalPoints); if (spec.Type == 'n' && PythonContext.GetContext(context).NumericCulture != PythonContext.CCulture) { if (digitCnt != precision && (self % 1) != 0) { digits = self.ToString("#,0.0" + new string('#', decimalPoints)); } else { // leave out the decimal if the precision == # of digits or we have a whole number digits = self.ToString("#,0"); } } else { if (digitCnt != precision && (self % 1) != 0) { digits = self.ToString("0.0" + new string('#', decimalPoints)); } else { // leave out the decimal if the precision == # of digits or we have a whole number digits = self.ToString("0"); } } } } break; default: throw PythonOps.ValueError("Unknown format code '{0}' for object of type 'float'", spec.Type.ToString()); } return(digits); }
internal static PythonDictionary GetExtensionCache(CodeContext /*!*/ context) { EnsureModuleInitialized(context); return((PythonDictionary)PythonContext.GetContext(context).GetModuleState(_extensionCacheKey)); }
public static object iand(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceBitwiseAnd, a, b)); }
public static object add(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.Add, a, b)); }
public static object ipow(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlacePower, a, b)); }
public static object floordiv(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.FloorDivide, a, b)); }
public static object isub(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceSubtract, a, b)); }
public static object mul(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.Multiply, a, b)); }
public static object ixor(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.InPlaceExclusiveOr, a, b)); }
public static object or_(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Operation(PythonOperationKind.BitwiseOr, a, b)); }
public static object Call(CodeContext /*!*/ context, Delegate @delegate, params object[] args) { return(PythonContext.GetContext(context).CallSplat(@delegate, args)); }
public static bool contains(CodeContext /*!*/ context, object a, object b) { return(PythonContext.GetContext(context).Contains(b, a)); }
public static int field_size_limit(CodeContext /*!*/ context) { return((int)PythonContext.GetContext(context). GetModuleState(_fieldSizeLimitKey)); }
public static void delitem(CodeContext /*!*/ context, object a, object b) { PythonContext.GetContext(context).DelIndex(a, b); }
private static void SetStackSize(CodeContext /*!*/ context, int stackSize) { PythonContext.GetContext(context).SetModuleState(_stackSizeKey, stackSize); }
public static void setitem(CodeContext /*!*/ context, object a, object b, object c) { PythonContext.GetContext(context).SetIndex(a, b, c); }
private static void SetLockCount(CodeContext /*!*/ context, long lockCount) { PythonContext.GetContext(context).SetModuleState(_lockCountKey, lockCount); }
internal static PythonDictionary GetDispatchTable(CodeContext /*!*/ context) { EnsureModuleInitialized(context); return((PythonDictionary)PythonContext.GetContext(context).GetModuleState(_dispatchTableKey)); }