diff options
-rw-r--r-- | Lib/test/math_testcases.txt | 72 | ||||
-rw-r--r-- | Lib/test/test_math.py | 8 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/mathmodule.c | 2 |
4 files changed, 75 insertions, 9 deletions
diff --git a/Lib/test/math_testcases.txt b/Lib/test/math_testcases.txt index be1a49f..5e24335 100644 --- a/Lib/test/math_testcases.txt +++ b/Lib/test/math_testcases.txt @@ -371,6 +371,78 @@ gam0141 gamma -127.45117632943295 -> 1.1831110896236810e-214 ----------------------------------------------------------- +-- log1p: log(1 + x), without precision loss for small x -- +----------------------------------------------------------- + +-- special values +log1p0000 log1p 0.0 -> 0.0 +log1p0001 log1p -0.0 -> -0.0 +log1p0002 log1p inf -> inf +log1p0003 log1p -inf -> nan invalid +log1p0004 log1p nan -> nan + +-- singularity at -1.0 +log1p0010 log1p -1.0 -> -inf divide-by-zero +log1p0011 log1p -0.9999999999999999 -> -36.736800569677101 + +-- finite values < 1.0 are invalid +log1p0020 log1p -1.0000000000000002 -> nan invalid +log1p0021 log1p -1.1 -> nan invalid +log1p0022 log1p -2.0 -> nan invalid +log1p0023 log1p -1e300 -> nan invalid + +-- tiny x: log1p(x) ~ x +log1p0110 log1p 5e-324 -> 5e-324 +log1p0111 log1p 1e-320 -> 1e-320 +log1p0112 log1p 1e-300 -> 1e-300 +log1p0113 log1p 1e-150 -> 1e-150 +log1p0114 log1p 1e-20 -> 1e-20 + +log1p0120 log1p -5e-324 -> -5e-324 +log1p0121 log1p -1e-320 -> -1e-320 +log1p0122 log1p -1e-300 -> -1e-300 +log1p0123 log1p -1e-150 -> -1e-150 +log1p0124 log1p -1e-20 -> -1e-20 + +-- some (mostly) random small and moderate-sized values +log1p0200 log1p -0.89156889782277482 -> -2.2216403106762863 +log1p0201 log1p -0.23858496047770464 -> -0.27257668276980057 +log1p0202 log1p -0.011641726191307515 -> -0.011710021654495657 +log1p0203 log1p -0.0090126398571693817 -> -0.0090534993825007650 +log1p0204 log1p -0.00023442805985712781 -> -0.00023445554240995693 +log1p0205 log1p -1.5672870980936349e-5 -> -1.5672993801662046e-5 +log1p0206 log1p -7.9650013274825295e-6 -> -7.9650330482740401e-6 +log1p0207 log1p -2.5202948343227410e-7 -> -2.5202951519170971e-7 +log1p0208 log1p -8.2446372820745855e-11 -> -8.2446372824144559e-11 +log1p0209 log1p -8.1663670046490789e-12 -> -8.1663670046824230e-12 +log1p0210 log1p 7.0351735084656292e-18 -> 7.0351735084656292e-18 +log1p0211 log1p 5.2732161907375226e-12 -> 5.2732161907236188e-12 +log1p0212 log1p 1.0000000000000000e-10 -> 9.9999999995000007e-11 +log1p0213 log1p 2.1401273266000197e-9 -> 2.1401273243099470e-9 +log1p0214 log1p 1.2668914653979560e-8 -> 1.2668914573728861e-8 +log1p0215 log1p 1.6250007816299069e-6 -> 1.6249994613175672e-6 +log1p0216 log1p 8.3740495645839399e-6 -> 8.3740145024266269e-6 +log1p0217 log1p 3.0000000000000001e-5 -> 2.9999550008999799e-5 +log1p0218 log1p 0.0070000000000000001 -> 0.0069756137364252423 +log1p0219 log1p 0.013026235315053002 -> 0.012942123564008787 +log1p0220 log1p 0.013497160797236184 -> 0.013406885521915038 +log1p0221 log1p 0.027625599078135284 -> 0.027250897463483054 +log1p0222 log1p 0.14179687245544870 -> 0.13260322540908789 + +-- large values +log1p0300 log1p 1.7976931348623157e+308 -> 709.78271289338397 +log1p0301 log1p 1.0000000000000001e+300 -> 690.77552789821368 +log1p0302 log1p 1.0000000000000001e+70 -> 161.18095650958321 +log1p0303 log1p 10000000000.000000 -> 23.025850930040455 + +-- other values transferred from testLog1p in test_math +log1p0400 log1p -0.63212055882855767 -> -1.0000000000000000 +log1p0401 log1p 1.7182818284590451 -> 1.0000000000000000 +log1p0402 log1p 1.0000000000000000 -> 0.69314718055994529 +log1p0403 log1p 1.2379400392853803e+27 -> 62.383246250395075 + + +----------------------------------------------------------- -- expm1: exp(x) - 1, without precision loss for small x -- ----------------------------------------------------------- diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index d6f14b2..12e7f98 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -647,15 +647,7 @@ class MathTests(unittest.TestCase): def testLog1p(self): self.assertRaises(TypeError, math.log1p) - self.ftest('log1p(1/e -1)', math.log1p(1/math.e-1), -1) - self.ftest('log1p(0)', math.log1p(0), 0) - self.ftest('log1p(e-1)', math.log1p(math.e-1), 1) - self.ftest('log1p(1)', math.log1p(1), math.log(2)) - self.assertEquals(math.log1p(INF), INF) - self.assertRaises(ValueError, math.log1p, NINF) - self.assertTrue(math.isnan(math.log1p(NAN))) n= 2**90 - self.assertAlmostEquals(math.log1p(n), 62.383246250395075) self.assertAlmostEquals(math.log1p(n), math.log1p(float(n))) def testLog10(self): @@ -468,6 +468,8 @@ C-API Library ------- +- Issue #9186: Fix math.log1p(-1.0) to raise ValueError, not OverflowError. + - Issue #9130: Fix validation of relative imports in parser module. - Issue #9128: Fix validation of class decorators in parser module. diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 7911251..b1d7a36 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -896,7 +896,7 @@ FUNC1A(gamma, m_tgamma, "gamma(x)\n\nGamma function at x.") FUNC1A(lgamma, m_lgamma, "lgamma(x)\n\nNatural logarithm of absolute value of Gamma function at x.") -FUNC1(log1p, m_log1p, 1, +FUNC1(log1p, m_log1p, 0, "log1p(x)\n\nReturn the natural logarithm of 1+x (base e).\n" "The result is computed in a way which is accurate for x near zero.") FUNC1(sin, sin, 0, |