On 11/04/2019 11.45, Xin, Peixing wrote: > Hi, Math experts: > > Looking at the codes below, for many math operations, CPython is checking errno to determine the error status even though the math function returns normal value back. Is it a safe solution? From the description here http://man7.org/linux/man-pages/man3/errno.3.html and https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152351, it looks apis probably set the errno when normal result is returned. Or being a side effect by calling other APIs in the implementation. In this situation, CPython's math operation might raise exceptions however in fact the result is correct. > > https://github.com/python/cpython/blob/master/Modules/mathmodule.c#L956 > https://github.com/python/cpython/blob/master/Modules/mathmodule.c#L864 This is safe because all places first set errno to 0. Errno is a thread local variable, so other threads cannot influence the variable during the calls. This is one of the many quirks that Mark has implemented for platforms bugs in various libm. Christian
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4