Skip to content

mpf shouldn't have __complex__ magic method #794

@skirpichev

Description

@skirpichev

I think it was a mistake to add one. Neither gmpy2.mpfr nor float types have it.

This produces funny results (seen while working on #793):

>>> import math, mpmath
>>> z = complex(mpmath.inf, +0.0); mpmath.fp.asin(z)
(1.5707963267948966+infj)
>>> z = complex(math.inf, +0.0); mpmath.fp.asin(z)
(1.5707963267948966+infj)
>>> z = complex(mpmath.inf, -0.0); mpmath.fp.asin(z)  # WTF?
(1.5707963267948966+infj)
>>> z = complex(math.inf, -0.0); mpmath.fp.asin(z)  # ok
(1.5707963267948966-infj)

This happens, because with using __complex__() dunder, the mpmath.inf coerced to complex(math.inf,0) and then imaginary component built by complex constructor as complex(math.inf,0).imag + (-0.0)=0.0-0.0=0.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions