It should always work. The result is the same regardless of the branch
chosen, but it runs a bit faster on CPython because "is 0" avoids an
expensive comparison with an mpmath number.
Fredrik
Aaron Meurer
On Thu, Aug 4, 2011 at 3:23 AM, smichr <smi...@gmail.com> wrote:
> In ctx_mp_python.py the expression `other is 0` is being used. Will
> this always work or should `other == 0` be used?
>
> --
> You received this message because you are subscribed to the Google Groups "mpmath" group.
> To post to this group, send email to mpm...@googlegroups.com.
> To unsubscribe from this group, send email to mpmath+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mpmath?hl=en.
>
>
In fact, 'other == 0' would be wrong because it would cause an mpf to
be returned instead of an mpc when the sum is a complex number with
zero imaginary part.
The code would be correct if the "False" branch were always taken. The
"is 0" check is just an optimization for CPython that speeds up very
short sums of real numbers. I guess it could be commented as such.
Fredrik
Indeed a comment would be helpful.
Aaron Meurer
On Thu, Aug 4, 2011 at 3:43 AM, Fredrik Johansson