示例#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);
        }
示例#2
0
文件: PyFloat.cs 项目: bamyazi/cloaca
        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);
        }
示例#3
0
文件: PyFloat.cs 项目: bamyazi/cloaca
        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);
        }
示例#4
0
文件: PyFloat.cs 项目: bamyazi/cloaca
        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);
        }
示例#5
0
文件: PyFloat.cs 项目: bamyazi/cloaca
        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);
        }
示例#6
0
文件: PyFloat.cs 项目: bamyazi/cloaca
        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);
        }
示例#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);
        }
示例#8
0
文件: PyFloat.cs 项目: bamyazi/cloaca
        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);
        }
示例#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)));
     }
 }
示例#10
0
文件: PyFloat.cs 项目: bamyazi/cloaca
        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 + "'");
            }
        }
示例#11
0
        public static PyObject __truediv__(PyObject self, PyObject other)
        {
            var newPyFloat = PyFloat.Create((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other));

            return(newPyFloat);
        }
示例#12
0
 public static PyFloat __neg__(PyObject self)
 {
     return(PyFloat.Create(-((PyFloat)self).InternalValue));
 }