I suspect Tim Peters had a good reason to include copysign() rather than sign().
On Wed, Dec 4, 2019 at 10:28 AM Andrew Barnert via Python-ideas < firstname.lastname@example.org> wrote:
On Dec 4, 2019, at 06:57, Marein email@example.com wrote:
I was using it like this: range(start, end, sign(end-start)), to
automatically have a range going up or down. But that's really the only concrete case I know.
If your only use for non-float-specific copysign would be implementing sign, why not ask for sign instead? It seems much more directly useful here, and potentially more widely useful as well.
But I don’t think that’s needed either. It still doesn’t come up that often, and when it does, anyone can implement it trivially yourself (unlike float copysign).
Plus, if your only use for sign is for this range, why not just wrap that whole thing in a function and put it in your toolkit?
def birange(start, stop): return range(start, stop, 1 if stop>=start else -1)
Unlike using either sign or copysign, this doesn’t force the reader to stop and think about whether start==stop is safe, it will obviously safely give you an empty range.
(You can extend this to be more flexible (take just stop, or start and stop, or start and stop and abs(step) arguments) if you need it.)
Python-ideas mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://firstname.lastname@example.org/message/3NXOYL... Code of Conduct: http://python.org/psf/codeofconduct/