New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: docstring for numpy.finfo.eps is incorrect #6940
Comments
Ah, looking at the source, I see that
would be better? Technically, that [As an aside, I much prefer the C99-style definition of epsilon, since it involves only the format and doesn't depend on the semantics of floating-point addition. In particular, the C99 definition doesn't depend on the rounding mode currently in effect, while the |
A pointer to |
Here we are almost 4 years later and this hasn't been fixed. I don't think that #14618 will be sufficient to close this issue. To clarify the bug report, the current definition of eps in the docstring is off by about a factor of 2 from the value of eps returned by np.finfo. (The numbers I give below are for implementations with IEEE-754 64 bit floating point standard.) I.e., np.finfo(1.0).eps = 2**-52 = 2.220446049250313e-16 However, the docstring defines eps as
The actual value of eps that would satisfy the definition 1.0+eps_min != 1.0 is: eps_min = 2**-53+2**-105 = 1.1102230246251568e-16 which is almost 1/2 of the present value of np.finfo(1.0).eps. We probably don't want to change the value of np.finfo(1.0).eps, to keep backwards compatibility, but the docstring definition of eps needs to be corrected to match what is calculated. The source code for np.finfo(1.0)eps uses numpy.MachAr, and looking at the documentation there, which allows other bases besides 2, I think the best definition of of eps is one of the early options that @mdickinson previously suggested. I would also add an example value to the description:
The docstring for epsneg is similarly incorrect. |
I also just stumbled over this inaccuracy. This ought to be fixed. For reference, Matlab documents its |
The current definition is incorrect and confusing due to rounding issues. @gwhammett the proposed definition is both correct and more descriptive and encourage a PR to close this issue. |
Replace inaccurate statements about eps and epsneg attrs with correct statements and examples. Added np.spacing and np.nextafter to See Also. Closes numpy#6940.
* DOC: Improve docs for np.finfo. Replace inaccurate statements about eps and epsneg attrs with correct statements and examples. Added np.spacing and np.nextafter to See Also. Closes #6940. * Removed LaTeX math from finfo docstring. * MAINT: Add periods at end of some sentences. Co-authored-by: Charles Harris <charlesr.harris@gmail.com>
The docstring for
numpy.finfo
currently defines theeps
attribute as:That definition is not correct, at least in the common case of the IEEE 754 binary formats. For example, with the IEEE 754 binary64 format under the usual round-ties-to-even rounding mode, the stated definition gives a value of
2**-53 + 2**-105
(approx.1.1102230246251568e-16
), which is a little over half of the correct value of2**-52
(approx2.220446049250313e-16
).Some possible rewordings:
Or:
Or it could be defined in terms of
nextafter
as:For comparison, section 5.2.4.2.2, paragraph 11 of the C99 standard defines the various
*_EPSILON
macros (DBL_EPSILON
,FLT_EPSILON
, ...) as:The docstring for
epsneg
is similarly incorrect.The text was updated successfully, but these errors were encountered: