Skip to content

mp.acot(cmath.infj) is mpc(real='nan', imag='nan'), should be 0 #796

@skirpichev

Description

@skirpichev

This affects also acoth(), asec() and acsc(). In short, everything, that's using 1/z for inversion. E.g., the acot() implemented as:

def acot(ctx, z):
    if not z:
        return ctx.pi * 0.5
    else:
        return ctx.atan(ctx.one / z)

But:

>>> mp.one/mp.mpc(cmath.infj)
mpc(real='0.0', imag='nan')
>>> fp.one/fp.mpc(cmath.infj)
-0j

On another hand, we have:

>>> mp.mpc(cmath.infj)**-1
mpc(real='0.0', imag='0.0')
>>> fp.mpc(cmath.infj)**-1
(nan+nanj)

Of course, it's yet another instance of this issue. With special rules for mixed arithmetic (e.g. real+complex as in this case), we should have -0j (or just 0 for the mp context, without signed zero).

As a workaround, we could add a branch for infinite z.

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