[issue31630] math.tan has poor accuracy near pi/2 on OpenBSD and NetBSD

Tim Peters report at bugs.python.org
Wed Nov 1 16:42:47 EDT 2017


Tim Peters <tim at python.org> added the comment:

Since fdlibm uses tan(x) ~= -1/(x-pi/2) in this range, and the reciprocals of the bad results have a whole of bunch of trailing zero bits, my guess is that argument reduction (the "x-pi/2" part) is screwing up (losing bits of pi/2 beyond the long string of initial bits that cancel out).  In which case it's likely sin(x) will return a poor result too, for the same reason (while cos(x) will return 1.0).  IOW, I'd be surprised if sin(x)/cos(x) were materially better.  If so, it's not just tan() that's flawed.  That can be checked easily enough (e.g., change the Python program I posted to use sin() instead of tan()).

Regardless, assuming we don't want to write our own libm, it's highly desirable that platform experts be aware of the flaw(s) on platforms where it occurs.  Otherwise they'll never make the noise needed to get it fixed.

OTOH, it's not an error _in_ Python if we don't supply libm, so the Python test suite really shouldn't fail on these.  Spray warnings to stderr?  Create a new "platform (lack of) quality" class of soft failure?  "Pass or fail, period" misses the mark here :-(

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31630>
_______________________________________


More information about the Python-bugs-list mailing list