10000 Merge pull request #14503 from ahaldane/tweak_round_docstring · numpy/numpy@79cb45d · GitHub
[go: up one dir, main page]

Skip to content

Commit 79cb45d

Browse files
authored
Merge pull request #14503 from ahaldane/tweak_round_docstring
DOC: tweak np.round docstring to clarify floating-point error
2 parents 09d5473 + d6d9faf commit 79cb45d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

numpy/core/fromnumeric.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,11 +3129,10 @@ def around(a, decimals=0, out=None):
31293129
31303130
``np.around`` uses a fast but sometimes inexact algorithm to round
31313131
floating-point datatypes. For positive `decimals` it is equivalent to
3132-
``np.true_divide(np.rint(a * 10**decimals), 10**decimals)``, which is
3133-
inexact for large floating-point values or large values of `decimals` due
3134-
the inexact representation of decimal fractions in the IEEE floating point
3135-
standard [1]_ and errors introduced when scaling by powers of ten. For
3136-
instance, note the extra "1" in the following:
3132+
``np.true_divide(np.rint(a * 10**decimals), 10**decimals)``, which has
3133+
error due to the inexact representation of decimal fractions in the IEEE
3134+
floating point standard [1]_ and errors introduced when scaling by powers
3135+
of ten. For instance, note the extra "1" in the following:
31373136
31383137
>>> np.round(56294995342131.5, 3)
31393138
56294995342131.51
@@ -3154,6 +3153,9 @@ def around(a, decimals=0, out=None):
31543153
31553154
>>> round(56294995342131.5, 3)
31563155
56294995342131.5
3156+
>>> np.round(16.055, 2), round(16.055, 2) # equals 16.0549999999999997
3157+
(16.06, 16.05)
3158+
31573159
31583160
References
31593161
----------

0 commit comments

Comments
 (0)
0