question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DOC: docstring for numpy.finfo.eps is incorrect

See original GitHub issue

The docstring for numpy.finfo currently defines the eps attribute as:

The smallest representable positive number such that 1.0 + eps != 1.0. […]

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 of 2**-52 (approx 2.220446049250313e-16).

In [36]: eps = 2**-53 + 2**-105

In [37]: eps
Out[37]: 1.1102230246251568e-16

In [38]: 1.0 + eps != 1.0
Out[38]: True

In [39]: 1.0 + np.nextafter(eps, -np.inf) != 1.0
Out[39]: False

In [40]: np.finfo(float).eps
Out[40]: 2.2204460492503131e-16

Some possible rewordings:

The smallest positive number such that 1.0 + eps is representable.

Or:

The difference between 1.0 and the smallest representable float larger than 1.0.

Or it could be defined in terms of nextafter as:

The value of np.nextafter(1.0, np.inf) - 1.0.

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 difference between 1 and the least value greater than 1 that is representable in the given floating point type, b1− p

The docstring for epsneg is similarly incorrect.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gwhammettcommented, Dec 8, 2019

Here we are almost 4 years later and this hasn’t been fixed. I don’t think that https://github.com/numpy/numpy/pull/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 smallest representable positive number such that 1.0 + eps != 1.0.”

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 difference between 1.0 and the smallest representable float larger than 1.0. (For 64 bit binary floats in the IEEE-754 standard, eps = 2**-52 ≅ 2.22e-16.)”

The docstring for epsneg is similarly incorrect.

0reactions
rossbarcommented, Feb 26, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle rounding to negative zero in Python docstring ...
I have a docstring test that relies on np. array2string using suppress_small=True, which will make small values round to zero.
Read more >
Validation — numpydoc v1.6.0rc1.dev0 Manual - Read the Docs
This will report the errors detected, such as incorrect capitalization, wrong order of the sections, and many other issues. Docstring Validation during Sphinx ......
Read more >
NumPy User Guide
It is a Python library that provides a multidi- mensional array object, various derived objects (such as masked arrays and matrices), and an ......
Read more >
finfo — Ivy 1.0 documentation
smallest positive floating-point number with full precision. This function conforms to the Array API Standard. This docstring is an extension of the docstring...
Read more >
1.4.3. More elaborate arrays - Scipy Lecture Notes
np.finfo(np.float32).eps ... False. Complex floating-point numbers: ... While it is off topic in a chapter on numpy, let's take a moment to recall...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found