Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 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)));
     }
 }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asDict = (PyDict)self;

            return(PyInteger.Create(asDict.InternalDict.Count));
        }
Ejemplo n.º 10
0
        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)));
        }
Ejemplo n.º 11
0
 public static PyInteger __neg__(PyObject self)
 {
     return(PyInteger.Create(-((PyInteger)self).InternalValue));
 }
Ejemplo n.º 12
0
        public static PyObject __lshift__(PyObject self, PyObject other)
        {
            var orded = (int)PyBoolClass.extractInt(self) << (int)PyBoolClass.extractInt(other);

            return(PyInteger.Create(orded));
        }
Ejemplo n.º 13
0
        public static PyObject __xor__(PyObject self, PyObject other)
        {
            var orded = PyBoolClass.extractInt(self) ^ PyBoolClass.extractInt(other);

            return(PyInteger.Create(orded));
        }
Ejemplo n.º 14
0
        public static PyObject __and__(PyObject self, PyObject other)
        {
            var anded = PyBoolClass.extractInt(self) & PyBoolClass.extractInt(other);

            return(PyInteger.Create(anded));
        }
Ejemplo n.º 15
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asStr = (PyString)self;

            return(PyInteger.Create(asStr.InternalValue.Length));
        }
Ejemplo n.º 16
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asList = (PyList)self;

            return(PyInteger.Create(asList.list.Count));
        }
Ejemplo n.º 17
0
        public static PyObject __floordiv__(PyObject self, PyObject other)
        {
            var newPyInteger = PyInteger.Create((BigInteger)((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other)));

            return(newPyInteger);
        }
Ejemplo n.º 18
0
        public static PyInteger __len__(IInterpreter interpreter, FrameContext context, PyObject self)
        {
            var asTuple = (PyTuple)self;

            return(PyInteger.Create(asTuple.Values.Length));
        }