Message9287
New issue to separate this from related #2237.
The Jython implementation of a few math functions has been inaccurate in parts of their domain, and this has gone unnoticed by test_math.
In test.test_math, class MathTests tests each of the methods in math at various special values, such as sin(pi/2) and exp(1). The success criterion, applied in MathTests.ftest, is that the absolute difference from the expected value be at most 1e-5.
In addition, MathTests.test_testfile takes examples from cmath_testcases.txt (which test_cmath also uses), and using only those cases where the argument and the result are both real, once more uses ftest and a 1e-5 tolerance.
This is not a very tight criterion, and for several functions the cases provided, if there are any at all, do not explore interesting parts of the domain. In contrast, test.test_cmath finds a more interesting set of test cases and tolerates much smaller errors.
The number of positive and negative arguments with which each function is tested, and their range, is listed here:
acos 16 +ve 1e-323 <= x <= 0.9999999999999999
18 -ve -1.0 <= x <= -5e-324
acosh 16 +ve 1.0000000000000002 <= x <= 1.5653640340214026e+308
asin 14 +ve 1e-323 <= x <= 0.9999999999999999
16 -ve -1.0 <= x <= -1e-323
asinh 4 +ve 3.38339e-318 <= x <= 1.6025136110019349e+308
4 -ve -1.2775271979042634e+308 <= x <= -5e-324
atan 2 +ve 1.2956339389525244e+308 <= x <= 1.440812624377215e+308
2 -ve -1.0631786461936417e+308 <= x <= -1.0516056964171069e+308
atanh 16 +ve 1e-323 <= x <= 0.9999999999999999
16 -ve -0.9999999999999999 <= x <= -1e-323
cos 0 +ve None <= x <= None
0 -ve None <= x <= None
cosh 0 +ve None <= x <= None
0 -ve None <= x <= None
exp 0 +ve None <= x <= None
1 -ve -745.0 <= x <= -745.0
log 32 +ve 1e-323 <= x <= 1.440860577601428e+308
log10 32 +ve 1e-323 <= x <= 1.440860577601428e+308
sin 0 +ve None <= x <= None
0 -ve None <= x <= None
sinh 0 +ve None <= x <= None
0 -ve None <= x <= None
sqrt 30 +ve 1e-323 <= x <= 1e+299
tan 0 +ve None <= x <= None
0 -ve None <= x <= None
tanh 0 +ve None <= x <= None
0 -ve None <= x <= None
The original approach may be satisfactory for CPython math because it is little more than a facade on the C math library, and must also tolerate platform variations. The java.lang.Math class underlying Jython's math makes strong guarantees about accuracy.
I propose to augment cmath_testcases.txt with real-valued cases to cover the domain of each of these functions, and apply a tighter acceptance criterion. |
|
Date |
User |
Action |
Args |
2015-01-03 22:41:28 | jeff.allen | set | recipients:
+ jeff.allen, zyasoft |
2015-01-03 22:41:28 | jeff.allen | set | messageid: <1420324888.12.0.382224489024.issue2244@psf.upfronthosting.co.za> |
2015-01-03 22:41:27 | jeff.allen | link | issue2244 messages |
2015-01-03 22:41:26 | jeff.allen | create | |
|