File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -519,15 +519,11 @@ def testTanhSign(self):
519519 # of zero, then atan and atanh will also have difficulties with
520520 # the sign of complex zeros.
521521 @requires_IEEE_754
522- @unittest .skipIf (sysconfig .get_config_var ('LOG1P_DROPS_ZERO_SIGN' ),
523- "system log1p() function doesn't preserve the sign" )
524522 def testAtanSign (self ):
525523 for z in complex_zeros :
526524 self .assertComplexIdentical (cmath .atan (z ), z )
527525
528526 @requires_IEEE_754
529- @unittest .skipIf (sysconfig .get_config_var ('LOG1P_DROPS_ZERO_SIGN' ),
530- "system log1p() function doesn't preserve the sign" )
531527 def testAtanhSign (self ):
532528 for z in complex_zeros :
533529 self .assertComplexIdentical (cmath .atanh (z ), z )
Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ Core and Builtins
104104Library
105105-------
106106
107+ - Issue #15477: In cmath and math modules, add workaround for platforms whose
108+ system-supplied log1p function doesn't respect signs of zeros.
109+
107110- Issue #11062: Fix adding a message from file to Babyl mailbox.
108111
109112- Issue #15646: Prevent equivalent of a fork bomb when using
Original file line number Diff line number Diff line change @@ -189,6 +189,27 @@ _Py_expm1(double x)
189189 significant loss of precision that arises from direct evaluation when x is
190190 small. */
191191
192+ #ifdef HAVE_LOG1P
193+
194+ double
195+ _Py_log1p (double x )
196+ {
197+ /* Some platforms supply a log1p function but don't respect the sign of
198+ zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0.
199+
200+ To save fiddling with configure tests and platform checks, we handle the
201+ special case of zero input directly on all platforms.
202+ */
203+ if (x == 0.0 ) {
204+ return x ;
205+ }
206+ else {
207+ return log1p (x );
208+ }
209+ }
210+
211+ #else
212+
192213double
193214_Py_log1p (double x )
194215{
@@ -230,3 +251,5 @@ _Py_log1p(double x)
230251 return log (1. + x );
231252 }
232253}
254+
255+ #endif /* ifdef HAVE_LOG1P */
Original file line number Diff line number Diff line change @@ -36,10 +36,6 @@ double _Py_log1p(double x);
3636#define m_expm1 _Py_expm1
3737#endif
3838
39- #ifdef HAVE_LOG1P
40- #define m_log1p log1p
41- #else
42- /* if the system doesn't have log1p, use the substitute
43- function defined in Modules/_math.c. */
39+ /* Use the substitute from _math.c on all platforms:
40+ it includes workarounds for buggy handling of zeros. */
4441#define m_log1p _Py_log1p
45- #endif
You can’t perform that action at this time.
0 commit comments