public static PyObject __mod__(PyObject self, PyObject other) { PyInteger a, b; castOperands(self, other, out a, out b, "modulo"); var newPyInteger = PyInteger.Create(a.InternalValue % b.InternalValue); return(newPyInteger); }
public static PyObject __floordiv__(PyObject self, PyObject other) { PyInteger a, b; castOperands(self, other, out a, out b, "floor division"); var newPyInteger = PyInteger.Create(a.InternalValue / b.InternalValue); return(newPyInteger); }
public static PyObject __sub__(PyObject self, PyObject other) { PyInteger a, b; castOperands(self, other, out a, out b, "subtraction"); var newPyInteger = PyInteger.Create(a.number - b.number); return(newPyInteger); }
public static PyObject __mul__(PyObject self, PyObject other) { PyInteger a, b; castOperands(self, other, out a, out b, "multiplication"); var newPyInteger = PyInteger.Create(a.InternalValue * b.InternalValue); return(newPyInteger); }
public static PyObject __pow__(PyObject self, PyObject other) { PyInteger a, b; castOperands(self, other, out a, out b, "exponent"); double doubleExp = Math.Pow((double)a.InternalValue, (double)b.InternalValue); var newPyInteger = PyInteger.Create((BigInteger)doubleExp); return(newPyInteger); }
public static PyObject __sub__(PyObject self, PyObject other) { // TODO [INTEGERS WITH FLOATS] Handle mixing of PyFloat and PyInteger(PyBool?) with basic arithmetic operators; 2 - 1.0 shouldn't fail. PyInteger a, b; castOperands(self, other, out a, out b, "subtraction"); var newPyInteger = PyInteger.Create(a.InternalValue - b.InternalValue); return(newPyInteger); }
public static PyObject __sub__(PyObject self, PyObject other) { if (other is PyInteger) { return(PyInteger.Create(extractInt(self) - extractInt(other))); } else { return(PyFloat.Create(PyFloatClass.ExtractAsDecimal(self) - PyFloatClass.ExtractAsDecimal(other))); } }
public static object __getitem__(PyList self, PyInteger i) { try { return(self.list[(int)i.InternalValue]); } catch (IndexOutOfRangeException) { // TODO: Represent as a more natural Python exception; throw new Exception("IndexError: list index out of range"); } }
public static void __delitem__(PyList self, PyInteger i) { try { self.list.RemoveAt((int)i.InternalValue); } catch (IndexOutOfRangeException) { // TODO: Represent as a more natural Python exception; throw new Exception("IndexError: list assignment index out of range"); } }
public static PyObject __getitem__(PyTuple self, PyInteger i) { try { return(self.Values[(int)i.number]); } catch (IndexOutOfRangeException) { // TODO: Represent as a more natural Python exception; throw new Exception("IndexError: tuple index out of range"); } }
// TODO [INTEGERS WITH FLOATS] Handle mixing of PyFloat and PyInteger(PyBool?) with basic arithmetic operators; 2 - 1.0 shouldn't fail. private static void castOperands(PyObject self, PyObject other, out PyInteger selfOut, out PyInteger otherOut, string operation) { selfOut = self as PyInteger; otherOut = other as PyInteger; if (selfOut == null) { throw new Exception("Tried to use a non-PyInteger for lvalue of: " + operation); } if (otherOut == null) { throw new Exception("Tried to use a non-PyInteger for rvalue of: " + operation); } }
public static object __next__(PyObject self) { var asIterator = self as PyRangeIterator; if (asIterator.Current >= asIterator.Max) { throw new StopIterationException(); } else { var toReturn = PyInteger.Create(asIterator.Current); asIterator.Current += asIterator.Step; return(toReturn); } }
public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self) { var asPyRange = (PyRange)self; return(PyInteger.Create(Math.Abs((asPyRange.Max - asPyRange.Min) / asPyRange.Step))); }
public static PyInteger __neg__(PyObject self) { return(PyInteger.Create(-((PyInteger)self).InternalValue)); }
public static PyObject __lshift__(PyObject self, PyObject other) { var orded = (int)PyBoolClass.extractInt(self) << (int)PyBoolClass.extractInt(other); return(PyInteger.Create(orded)); }
public static PyObject __xor__(PyObject self, PyObject other) { var orded = PyBoolClass.extractInt(self) ^ PyBoolClass.extractInt(other); return(PyInteger.Create(orded)); }
public static PyObject __and__(PyObject self, PyObject other) { var anded = PyBoolClass.extractInt(self) & PyBoolClass.extractInt(other); return(PyInteger.Create(anded)); }
public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self) { var asStr = (PyString)self; return(PyInteger.Create(asStr.InternalValue.Length)); }
public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self) { var asTuple = (PyTuple)self; return(PyInteger.Create(asTuple.Values.Length)); }
public static void __setitem__(PyList self, PyInteger i, PyObject value) { __setitem__(self, (int)i.InternalValue, value); }
public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self) { var asDict = (PyDict)self; return(PyInteger.Create(asDict.InternalDict.Count)); }
public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self) { var asList = (PyList)self; return(PyInteger.Create(asList.list.Count)); }
public static PyObject __floordiv__(PyObject self, PyObject other) { var newPyInteger = PyInteger.Create((BigInteger)((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other))); return(newPyInteger); }