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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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))); } }
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 + "'"); } }
public static PyObject __truediv__(PyObject self, PyObject other) { var newPyFloat = PyFloat.Create((decimal)extractInt(self) / PyFloatClass.ExtractAsDecimal(other)); return(newPyFloat); }
public static PyFloat __neg__(PyObject self) { return(PyFloat.Create(-((PyFloat)self).InternalValue)); }