Message9285
I've noticed that our implementation of the (real) math module is at the root of many of our cmath problems. sinh(x) = (exp(x) - exp(-x)) / 2 in theory, but it's not accurate to compute this way for small x. For abs(x) < 2**-53, it just evaluates to zero.
Yet Jython math passes the tests in test_math.py . Why?
I decided to look at the range of x (not counting 0, 1, inf and nan) over which these methods are actually tested. Test values come from the same file cmath_testcases.txt as is used for cmath. test_math.MathTests.test_testfile() reads the file, then uses only the cases where the argument is real. The resultant coverage is this:
test_testfile (__main__.TestCaseCoverage) ...
acos 5e-324 <= x <= 0.9999999999999999
acosh 1.0000000000000002 <= x <= 1.5653640340214026e+308
asin 1e-323 <= x <= 0.9999999999999999
asinh 5e-324 <= x <= 1.6025136110019349e+308
atan 1.0516056964171069e+308 <= x <= 1.440812624377215e+308
atanh 1e-323 <= x <= 0.9999999999999999
cos None <= x <= None
cosh None <= x <= None
exp 745.0 <= x <= 745.0
log 1e-323 <= x <= 1.440860577601428e+308
log10 1e-323 <= x <= 1.440860577601428e+308
sin None <= x <= None
sinh None <= x <= None
sqrt 1e-323 <= x <= 1e+299
tan None <= x <= None
tanh None <= x <= None
None means they aren't tested at all. This happens when all the non-trivial examples use a complex argument. In addition, test_math.py only requires the library to get within 1e-5 of the reference answer, quite unlike the more demanding test_cmath.py .
So that's why we pass. I'll add to our cmath_testcases.txt, some examples I generate to address that.
But this also implies CPython (real) math is not tested properly, except to the extent cmath relies on it. I think improved rigour here is something we could give back. |
|
Date |
User |
Action |
Args |
2015-01-01 22:21:19 | jeff.allen | set | messageid: <1420150879.46.0.317754342194.issue2237@psf.upfronthosting.co.za> |
2015-01-01 22:21:19 | jeff.allen | set | recipients:
+ jeff.allen |
2015-01-01 22:21:19 | jeff.allen | link | issue2237 messages |
2015-01-01 22:21:18 | jeff.allen | create | |
|