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