Ejemplo n.º 1
0
        public static PyObject __truediv__(PyObject self, PyObject other)
        {
            PyInteger a, b;

            castOperands(self, other, out a, out b, "true division");
            var newPyFloat = PyFloat.Create(((Decimal)a.InternalValue) / ((Decimal)b.InternalValue));

            return(newPyFloat);
        }
Ejemplo n.º 2
0
        public static PyObject __floordiv__(PyObject self, PyObject other)
        {
            PyFloat a, b;

            castOperands(self, other, out a, out b, "floor division");
            var newPyInteger = PyFloat.Create(Math.Floor(a.number / b.number));

            return(newPyInteger);
        }
Ejemplo n.º 3
0
        public static PyObject __mod__(PyObject self, PyObject other)
        {
            PyFloat a, b;

            castOperands(self, other, out a, out b, "modulo");
            var newPyInteger = PyFloat.Create(a.number % b.number);

            return(newPyInteger);
        }
Ejemplo n.º 4
0
        public static PyObject __sub__(PyObject self, PyObject other)
        {
            PyFloat a, b;

            castOperands(self, other, out a, out b, "subtract");
            var newPyFloat = PyFloat.Create(a.number - b.number);

            return(newPyFloat);
        }
Ejemplo n.º 5
0
        public static PyObject __truediv__(PyObject self, PyObject other)
        {
            PyFloat a, b;

            castOperands(self, other, out a, out b, "division");
            var newPyFloat = PyFloat.Create(a.number / b.number);

            return(newPyFloat);
        }
Ejemplo n.º 6
0
        public static PyObject __mul__(PyObject self, PyObject other)
        {
            PyFloat a, b;

            castOperands(self, other, out a, out b, "multiplication");
            var newPyFloat = PyFloat.Create(a.number * b.number);

            return(newPyFloat);
        }
Ejemplo n.º 7
0
        public static PyObject __add__(PyObject self, PyObject other)
        {
            PyFloat a, b;

            castOperands(self, other, out a, out b, "addition");
            var newPyFloat = PyFloat.Create(a.InternalValue + b.InternalValue);

            return(newPyFloat);
        }
Ejemplo n.º 8
0
        public static PyObject __pow__(PyObject self, PyObject other)
        {
            PyFloat a, b;

            castOperands(self, other, out a, out b, "exponent");
            double doubleExp  = Math.Pow((double)a.number, (double)b.number);
            var    newPyFloat = PyFloat.Create(doubleExp);

            return(newPyFloat);
        }
Ejemplo n.º 9
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.º 10
0
        private static void castOperands(PyObject self, PyObject other, out PyFloat selfOut, out PyFloat otherOut, string operation)
        {
            selfOut = self as PyFloat;
            if (selfOut == null)
            {
                throw new Exception("Tried to use a non-PyFloat for lvalue of: " + operation);
            }

            var rightFloat = other as PyFloat;

            if (rightFloat != null)
            {
                otherOut = rightFloat;
                return;
            }

            var rightInt = other as PyInteger;

            if (rightInt != null)
            {
                otherOut = PyFloat.Create((decimal)rightInt.number);
                return;
            }

            var rightBool = other as PyBool;

            if (rightBool != null)
            {
                otherOut = PyFloat.Create(rightBool.boolean ? 1.0 : 0.0);
                return;
            }

            var rightStr = other as PyString;

            if (rightStr != null)
            {
                otherOut = PyFloat.Create(Decimal.Parse(rightStr.str));
                return;
            }

            else
            {
                throw new Exception("TypeError: unsupported operand(s) for " + operation + " 'float' and '" + other.__class__.Name + "'");
            }
        }
Ejemplo n.º 11
0
        public static PyObject __truediv__(PyObject self, PyObject other)
        {
            var newPyFloat = PyFloat.Create((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other));

            return(newPyFloat);
        }
Ejemplo n.º 12
0
 public static PyFloat __neg__(PyObject self)
 {
     return(PyFloat.Create(-((PyFloat)self).InternalValue));
 }