bpo-29962: add math.remainder#950
Conversation
|
|
||
| .. function:: remainder(x, y) | ||
|
|
||
| Return the IEEE 754-style remainder of ``x`` with respect to ``y``. For |
There was a problem hiding this comment.
There is a bit of inconsistency in the file, but I see that in general the parameters do not have a code markup but italic: x and y instead of x and y.
I also see in general there are two whitespaces after the period.
There was a problem hiding this comment.
Thanks. Fix on the way.
|
|
||
| .. function:: remainder(x, y) | ||
|
|
||
| Return the IEEE 754-style remainder of ``x`` with respect to ``y``. For |
There was a problem hiding this comment.
Parameters usually are formatted with italic. *x* and *y*.
| of *x* and are floats. | ||
|
|
||
|
|
||
| .. function:: remainder(x, y) |
There was a problem hiding this comment.
Shouldn't it be named remainder_near as decimal.remainder_near?
There was a problem hiding this comment.
That's not clear to me: see discussion in the bpo issue.
| Return the IEEE 754-style remainder of ``x`` with respect to ``y``. For | ||
| finite ``x`` and finite nonzero ``y``, this is the difference ``x - n*y``, | ||
| where ``n`` is the closest integer to the exact value of the quotient ``x / | ||
| y``. If ``x / y`` is exactly halfway between two consecutive integers, the |
There was a problem hiding this comment.
Sentences are separated by two spaces in this file.
There was a problem hiding this comment.
Thanks. I think I caught all the single spaces.
| nearest *even* integer is used for ``n``. The remainder ``r = remainder(x, | ||
| y)`` thus always satisfies ``abs(r) <= 0.5 * abs(y)``. | ||
|
|
||
| Special cases follow IEEE 754: in particular, ``remainder(x, math.inf)`` is |
There was a problem hiding this comment.
And remainder(x, -math.inf)?
| math | ||
| ---- | ||
|
|
||
| New ``remainder`` function, implementing the IEEE 754-style remainder |
There was a problem hiding this comment.
Maybe make it a reference? :func:'~math.remainder'?
| } | ||
| else { | ||
| assert(m == c); | ||
| r = m - 2.0 * fmod(0.5 * (absx - m), absy); |
There was a problem hiding this comment.
Could you add any comment?
|
The coverage complaint seems to be because the line in the tests isn't being covered, and that's because none of the tests are failing. I'm not sure what to do about that. |
| Added support for :ref:`file descriptors <path_fd>` in :func:`~os.scandir` | ||
| on Unix. (Contributed by Serhiy Storchaka in :issue:`25996`.) | ||
|
|
||
| math |
There was a problem hiding this comment.
math should be between locale and os.
There was a problem hiding this comment.
Whoops, so it should. Thanks!
…pite of possible rounding error.
SylvainDe
left a comment
There was a problem hiding this comment.
Small questions about the tests
| # triples (x, y, remainder(x, y)) in hexadecimal form. | ||
| testcases = [ | ||
| # Remainders modulo 1, showing the ties-to-even behaviour. | ||
| '-4.0 1 -0.0', |
There was a problem hiding this comment.
Any reason for using strings to be splitted instead of a more natural container like tuples?
There was a problem hiding this comment.
Just personal preference, really. I find the individual cases to be easier to read and write this way. Comparing:
'0x1.921fb54442d18p+0 0x1.921fb54442d18p+2 0x1.921fb54442d18p+0',
'-1.4 -0.c 0.4',
with
('0x1.921fb54442d18p+0', '0x1.921fb54442d18p+2', '0x1.921fb54442d18p+0'),
('-1.4', '-0.c', '0.4'),
there's a lot more noise in the latter representation.
There was a problem hiding this comment.
Of course, if Python had direct support for hex floating-point literals, then
(0x1.921fb54442d18p+0, 0x1.921fb54442d18p+2, 0x1.921fb54442d18p+0),
would be the obvious representation. But it doesn't. :-(
| actual = math.remainder(-x, y) | ||
| validate_spec(-x, y, actual) | ||
|
|
||
| # Special values. |
There was a problem hiding this comment.
Should these cases be moved into tests on their own?
There was a problem hiding this comment.
Possibly. I wanted to stay (somewhat) consistent with the existing test structure, which is mostly one test method per wrapped libm function. One day it would be nice to rework test_math. But not today.
Add IEEE 754-style remainder operation.