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 < python-ideas@python.org> wrote: > On Dec 4, 2019, at 06:57, Marein <python-id...@marein.net> 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 -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/3NXOYLLPT5FSJ6YJFFL6FZUKB677NXNZ/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MXLAHFRJEK2AOL6O7XCYPXG467NBIQHZ/ Code of Conduct: http://python.org/psf/codeofconduct/