Index: Lib/test/test_math.py =================================================================== --- Lib/test/test_math.py (révision 86282) +++ Lib/test/test_math.py (copie de travail) @@ -8,6 +8,7 @@ import sys import random import struct +import sysconfig eps = 1E-05 NAN = float('nan') @@ -891,11 +892,16 @@ self.ftest('tanh(inf)', math.tanh(INF), 1) self.ftest('tanh(-inf)', math.tanh(NINF), -1) self.assertTrue(math.isnan(math.tanh(NAN))) + + @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"), + 'need IEEE double float') + @unittest.skipIf(sysconfig.get_config_var('TANH_PRESERVES_ZERO_SIGN') == 0, + "system tanh() function doesn't copy the sign") + def testTanhSign(self): # check that tanh(-0.) == -0. on IEEE 754 systems - if float.__getformat__("double").startswith("IEEE"): - self.assertEqual(math.tanh(-0.), -0.) - self.assertEqual(math.copysign(1., math.tanh(-0.)), - math.copysign(1., -0.)) + self.assertEqual(math.tanh(-0.), -0.) + self.assertEqual(math.copysign(1., math.tanh(-0.)), + math.copysign(1., -0.)) def test_trunc(self): self.assertEqual(math.trunc(1), 1) Index: Lib/test/test_cmath.py =================================================================== --- Lib/test/test_cmath.py (révision 86282) +++ Lib/test/test_cmath.py (copie de travail) @@ -3,6 +3,7 @@ import unittest import cmath, math from cmath import phase, polar, rect, pi +import sysconfig INF = float('inf') NAN = float('nan') @@ -61,6 +62,11 @@ def tearDown(self): self.test_values.close() + def assertComplexEqual(self, a, b): + self.assertEqual(a, b) + self.assertEqual(math.copysign(1., a.real), math.copysign(1., b.real)) + self.assertEqual(math.copysign(1., a.imag), math.copysign(1., b.imag)) + def rAssertAlmostEqual(self, a, b, rel_err = 2e-15, abs_err = 5e-323, msg=None): """Fail if the two floating-point numbers are not almost equal. @@ -473,7 +479,15 @@ self.assertTrue(cmath.isinf(complex(NAN, INF))) self.assertTrue(cmath.isinf(complex(INF, NAN))) + @unittest.skipIf(sysconfig.get_config_var('TANH_PRESERVES_ZERO_SIGN') == 0, + "system tanh() function doesn't copy the sign") + def testTanhSign(self): + self.assertComplexEqual(cmath.tanh(complex(0., .0j)), complex(0., .0j)) + self.assertComplexEqual(cmath.tanh(complex(0., -.0j)), complex(0., -.0j)) + self.assertComplexEqual(cmath.tanh(complex(-0., .0j)), complex(-0., .0j)) + self.assertComplexEqual(cmath.tanh(complex(-0., -.0j)), complex(-0., -.0j)) + def test_main(): run_unittest(CMathTests) Index: Lib/test/cmath_testcases.txt =================================================================== --- Lib/test/cmath_testcases.txt (révision 86282) +++ Lib/test/cmath_testcases.txt (copie de travail) @@ -1858,12 +1858,6 @@ -- tanh: Hyperbolic Tangent -- ------------------------------ --- zeros -tanh0000 tanh 0.0 0.0 -> 0.0 0.0 -tanh0001 tanh 0.0 -0.0 -> 0.0 -0.0 -tanh0002 tanh -0.0 0.0 -> -0.0 0.0 -tanh0003 tanh -0.0 -0.0 -> -0.0 -0.0 - -- random inputs tanh0004 tanh -21.200500450664993 -1.6970729480342996 -> -1.0 1.9241352344849399e-19 tanh0005 tanh -0.34158771504251928 -8.0848504951747131 -> -2.123711225855613 1.2827526782026006