On 11/28/19 2:51 PM, Marein wrote: > The math.copysign(x, y) function always returns a float, even when the > given x is an int, i.e. math.copysign(3, -1) gives -3.0. This is > documented behaviour, but I find it somewhat surprising given that the > name suggests that it only copies a sign, and it's also annoying in > situations when an int is strictly needed (i.e. as the step argument > to range), requiring an additional cast. > > I'm interested to hear whether it might be a good idea to preserve the > int/float type of the argument in math.copysign.
In my experience, copysign is really only needed for floating point numbers, and where it is used, efficiency is often at least somewhat important so adding code to make it work to produce an int result would slow things down. For a range step, I find using a ternary operation to be clearer than using copysign. -- Richard Damon _______________________________________________ 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/J6FSILWPCDZE523QRIPNOZBZDZFX5CJ2/ Code of Conduct: http://python.org/psf/codeofconduct/