-
Notifications
You must be signed in to change notification settings - Fork 206
mp.acot(cmath.infj) is mpc(real='nan', imag='nan'), should be 0 #796
Copy link
Copy link
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behavior
Milestone
Description
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)
-0jOn 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behavior