The __invert__ methods, which controls the behaviour of the ~ operator, of Integers and ints are different.
In Python, for an int x, its invert ~x is defined to be its two's complement and is given by -1-x <https://wiki.python.org/moin/BitwiseOperators>. On the other hand, in Sage for an Integer x (from sage.rings.integer.Integer), its __invert__ is defined to be 1 / x <https://github.com/sagemath/sage/blob/master/src/sage/rings/integer.pyx#L5999-L6011> . Unfortunately this difference means that ~x different results in Sage and Python and so is causing some of my scripts and packages that run under Python to break under Sage. Most notably, that under Sage ~0 raises a "ZeroDivisionError: Rational division by zero" error rather than returning -1. Looking through the git history it appears that this has been the convention since at least October 2006 <https://github.com/sagemath/sage/blob/b94db547579596d7979e28aa9aff1cdb45193bcc/src/sage/rings/integer.pyx#L1590-L1593>. Is there a reason why __invert__ was chosen to act this way rather than match the Python convention? -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
