Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmath.tanh(±0+infj) and tanh(±0+nanj) should return ±0+nanj #122637

Closed
skirpichev opened this issue Aug 3, 2024 · 3 comments
Closed

cmath.tanh(±0+infj) and tanh(±0+nanj) should return ±0+nanj #122637

skirpichev opened this issue Aug 3, 2024 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@skirpichev
Copy link
Contributor

skirpichev commented Aug 3, 2024

Bug report

Bug description:

As per C11 DR#471 (accepted for C17), ctanh (0 + i NaN) and ctanh (0 + i Inf) should return 0 + i NaN (with "invalid" exception in the second case). Currently, real part is nan.

This has corresponding implications for ctan(z), as its errors and special cases are handled as if the operation is implemented by -i*ctanh(i*z).

See glibc patch: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d15e83c5f5231d971472b5ffc9219d54056ca0f1

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@skirpichev skirpichev added the type-bug An unexpected behavior, bug, or error label Aug 3, 2024
skirpichev added a commit to skirpichev/cpython that referenced this issue Aug 3, 2024
As per C11 DR#471, ctanh (0 + i NaN) and ctanh (0 + i Inf) should return
0 + i NaN (with "invalid" exception in the second case).  This has
corresponding implications for ctan(z), as its errors and special cases
are handled as if the operation is implemented by -i*ctanh(i*z).
This patch fixes cmath's code to do same.

Glibs patch: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d15e83c5f5231d971472b5ffc9219d54056ca0f1
@skirpichev
Copy link
Contributor Author

PR is ready for review: #122638

See also #121889

mdickinson pushed a commit that referenced this issue Aug 4, 2024
…2638)

As per C11 DR#471, ctanh (0 + i NaN) and ctanh (0 + i Inf) should return
0 + i NaN (with "invalid" exception in the second case).  This has
corresponding implications for ctan(z), as its errors and special cases
are handled as if the operation is implemented by -i*ctanh(i*z).
This patch fixes cmath's code to do same.

Glibs patch: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d15e83c5f5231d971472b5ffc9219d54056ca0f1
@mdickinson
Copy link
Member

Closed in #122638, with thanks to @skirpichev. As with #121889, I don't think this is behaviour that should be changed in a bugfix release, so it's not a candidate for backport.

@skirpichev
Copy link
Contributor Author

skirpichev commented Aug 4, 2024

Great. Now glibc's libm pass cmath_testcases.txt.

One minor note, now we have slightly misleading comment:

/* First, the C functions that do the real work. Each of the c_*
functions computes and returns the C99 Annex G recommended result

This (and fix for #121889) is available in C17, not C11C99. Though, as you can see, glibc turns this on unconditionally.

Probably, we should adjust comment.

PS: And now this really closed.

brandtbucher pushed a commit to brandtbucher/cpython that referenced this issue Aug 7, 2024
python#122638)

As per C11 DR#471, ctanh (0 + i NaN) and ctanh (0 + i Inf) should return
0 + i NaN (with "invalid" exception in the second case).  This has
corresponding implications for ctan(z), as its errors and special cases
are handled as if the operation is implemented by -i*ctanh(i*z).
This patch fixes cmath's code to do same.

Glibs patch: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d15e83c5f5231d971472b5ffc9219d54056ca0f1
blhsing pushed a commit to blhsing/cpython that referenced this issue Aug 22, 2024
python#122638)

As per C11 DR#471, ctanh (0 + i NaN) and ctanh (0 + i Inf) should return
0 + i NaN (with "invalid" exception in the second case).  This has
corresponding implications for ctan(z), as its errors and special cases
are handled as if the operation is implemented by -i*ctanh(i*z).
This patch fixes cmath's code to do same.

Glibs patch: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d15e83c5f5231d971472b5ffc9219d54056ca0f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants