Author jeff.allen
Recipients jeff.allen, mark.dickinson
Date 2016-01-07.15:41:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In many cases, test_math does not exercise the functions defined by the math module, other than at a few values needing special handling. Where it does test a function with values representative of the domain, the accuracy demanded is often loose in one place and tight in another. By comparison, test_cmath uses more interesting values and a rational approach to accuracy.

In most implementations, math simply proxies an expertly built (and tested) platform library or firmware, so it is unlikely we are the victims of mathematical inexactitude.

We observed this as a problem in the Jython project, where failures in cmath were traced eventually to the naive (but passing) implementation of some functions in math. For Jython, we now supplement test_math with stronger tests more like those in test_cmath. So this issue is really an offer to fold that work back into the CPython test_math, to strengthen testing for all.

In the attached program, in the coverge section, I logged the calls to selected functions from test_math to see what range of values they used. It produces results like:

 [9.881e-324, 7.905e-323, 1.862e-309, 1e-305, 1e-150, ..., 2, 23, 1e+16, 1e+150, 1e+299]
 [-0.0, -inf, 0.0, inf, nan]

 [-0.0, -inf, 0.0, inf, nan]

 [-0.0, -inf, 0.0, inf, nan]

 [-0.0, -inf, 0.0, inf, nan]

The three rows here are positive, negative and "special" arguments, and "..." means I abridged the list.

Where functions are tested, results are expected with a maximum error of 1e-5. On sqrt(1e150), this demands bit-perfect accuracy; on sqrt(1e-150) it demands virtually nothing. 

In the attached program, in the accuracy section, I wrap most of the functions so as to fuzz their results by plus or minus 2e-6, test_math will still pass them. test_cmath uses a relative measure of error (so many ulps of the expected value), which is worth emulating.

If people think it better, coverage and accuracy can be tracked as separate issues.
Date User Action Args
2016-01-07 15:41:23jeff.allensetrecipients: + jeff.allen, mark.dickinson
2016-01-07 15:41:22jeff.allensetmessageid: <>
2016-01-07 15:41:22jeff.allenlinkissue26040 messages
2016-01-07 15:41:21jeff.allencreate