gh-122637: fix tanh(±0+infj) and tanh(±0+nanj) to return ±0+nanj (#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
This commit is contained in:
Sergey B Kirpichev 2024-08-04 12:05:30 +03:00 committed by GitHub
parent 3462a80d2c
commit e6fad7a0e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 14 deletions

View File

@ -1992,9 +1992,9 @@ tanh0065 tanh 1.797e+308 0.0 -> 1.0 0.0
--special values
tanh1000 tanh 0.0 0.0 -> 0.0 0.0
tanh1001 tanh 0.0 inf -> nan nan invalid
tanh1001 tanh 0.0 inf -> 0.0 nan invalid
tanh1002 tanh 2.3 inf -> nan nan invalid
tanh1003 tanh 0.0 nan -> nan nan
tanh1003 tanh 0.0 nan -> 0.0 nan
tanh1004 tanh 2.3 nan -> nan nan
tanh1005 tanh inf 0.0 -> 1.0 0.0
tanh1006 tanh inf 0.7 -> 1.0 0.0
@ -2009,7 +2009,7 @@ tanh1014 tanh nan 2.3 -> nan nan
tanh1015 tanh nan inf -> nan nan
tanh1016 tanh nan nan -> nan nan
tanh1017 tanh 0.0 -0.0 -> 0.0 -0.0
tanh1018 tanh 0.0 -inf -> nan nan invalid
tanh1018 tanh 0.0 -inf -> 0.0 nan invalid
tanh1019 tanh 2.3 -inf -> nan nan invalid
tanh1020 tanh inf -0.0 -> 1.0 -0.0
tanh1021 tanh inf -0.7 -> 1.0 -0.0
@ -2022,9 +2022,9 @@ tanh1027 tanh nan -0.0 -> nan -0.0
tanh1028 tanh nan -2.3 -> nan nan
tanh1029 tanh nan -inf -> nan nan
tanh1030 tanh -0.0 -0.0 -> -0.0 -0.0
tanh1031 tanh -0.0 -inf -> nan nan invalid
tanh1031 tanh -0.0 -inf -> -0.0 nan invalid
tanh1032 tanh -2.3 -inf -> nan nan invalid
tanh1033 tanh -0.0 nan -> nan nan
tanh1033 tanh -0.0 nan -> -0.0 nan
tanh1034 tanh -2.3 nan -> nan nan
tanh1035 tanh -inf -0.0 -> -1.0 -0.0
tanh1036 tanh -inf -0.7 -> -1.0 -0.0
@ -2035,7 +2035,7 @@ tanh1040 tanh -inf -3.5 -> -1.0 -0.0
tanh1041 tanh -inf -inf -> -1.0 0.0 ignore-imag-sign
tanh1042 tanh -inf nan -> -1.0 0.0 ignore-imag-sign
tanh1043 tanh -0.0 0.0 -> -0.0 0.0
tanh1044 tanh -0.0 inf -> nan nan invalid
tanh1044 tanh -0.0 inf -> -0.0 nan invalid
tanh1045 tanh -2.3 inf -> nan nan invalid
tanh1046 tanh -inf 0.0 -> -1.0 0.0
tanh1047 tanh -inf 0.7 -> -1.0 0.0
@ -2307,9 +2307,9 @@ tan0066 tan -8.79645943005142 0.0 -> 0.7265425280053614098 0.0
-- special values
tan1000 tan -0.0 0.0 -> -0.0 0.0
tan1001 tan -inf 0.0 -> nan nan invalid
tan1001 tan -inf 0.0 -> nan 0.0 invalid
tan1002 tan -inf 2.2999999999999998 -> nan nan invalid
tan1003 tan nan 0.0 -> nan nan
tan1003 tan nan 0.0 -> nan 0.0
tan1004 tan nan 2.2999999999999998 -> nan nan
tan1005 tan -0.0 inf -> -0.0 1.0
tan1006 tan -0.69999999999999996 inf -> -0.0 1.0
@ -2324,7 +2324,7 @@ tan1014 tan -2.2999999999999998 nan -> nan nan
tan1015 tan -inf nan -> nan nan
tan1016 tan nan nan -> nan nan
tan1017 tan 0.0 0.0 -> 0.0 0.0
tan1018 tan inf 0.0 -> nan nan invalid
tan1018 tan inf 0.0 -> nan 0.0 invalid
tan1019 tan inf 2.2999999999999998 -> nan nan invalid
tan1020 tan 0.0 inf -> 0.0 1.0
tan1021 tan 0.69999999999999996 inf -> 0.0 1.0
@ -2337,9 +2337,9 @@ tan1027 tan 0.0 nan -> 0.0 nan
tan1028 tan 2.2999999999999998 nan -> nan nan
tan1029 tan inf nan -> nan nan
tan1030 tan 0.0 -0.0 -> 0.0 -0.0
tan1031 tan inf -0.0 -> nan nan invalid
tan1031 tan inf -0.0 -> nan -0.0 invalid
tan1032 tan inf -2.2999999999999998 -> nan nan invalid
tan1033 tan nan -0.0 -> nan nan
tan1033 tan nan -0.0 -> nan -0.0
tan1034 tan nan -2.2999999999999998 -> nan nan
tan1035 tan 0.0 -inf -> 0.0 -1.0
tan1036 tan 0.69999999999999996 -inf -> 0.0 -1.0
@ -2350,7 +2350,7 @@ tan1040 tan 3.5 -inf -> 0.0 -1.0
tan1041 tan inf -inf -> -0.0 -1.0 ignore-real-sign
tan1042 tan nan -inf -> -0.0 -1.0 ignore-real-sign
tan1043 tan -0.0 -0.0 -> -0.0 -0.0
tan1044 tan -inf -0.0 -> nan nan invalid
tan1044 tan -inf -0.0 -> nan -0.0 invalid
tan1045 tan -inf -2.2999999999999998 -> nan nan invalid
tan1046 tan -0.0 -inf -> -0.0 -1.0
tan1047 tan -0.69999999999999996 -inf -> -0.0 -1.0

View File

@ -0,0 +1 @@
Adjust ``cmath.tanh(nanj)`` and ``cmath.tanh(infj)`` for recent C standards.

View File

@ -1339,8 +1339,8 @@ cmath_exec(PyObject *mod)
INIT_SPECIAL_VALUES(tanh_special_values, {
C(-1.,0.) C(U,U) C(-1.,-0.) C(-1.,0.) C(U,U) C(-1.,0.) C(-1.,0.)
C(N,N) C(U,U) C(U,U) C(U,U) C(U,U) C(N,N) C(N,N)
C(N,N) C(U,U) C(-0.,-0.) C(-0.,0.) C(U,U) C(N,N) C(N,N)
C(N,N) C(U,U) C(0.,-0.) C(0.,0.) C(U,U) C(N,N) C(N,N)
C(-0.0,N) C(U,U) C(-0.,-0.) C(-0.,0.) C(U,U) C(-0.0,N) C(-0.,N)
C(0.0,N) C(U,U) C(0.,-0.) C(0.,0.) C(U,U) C(0.0,N) C(0.,N)
C(N,N) C(U,U) C(U,U) C(U,U) C(U,U) C(N,N) C(N,N)
C(1.,0.) C(U,U) C(1.,-0.) C(1.,0.) C(U,U) C(1.,0.) C(1.,0.)
C(N,N) C(N,N) C(N,-0.) C(N,0.) C(N,N) C(N,N) C(N,N)