In Python 2, returning an int where a float was expected could break existing code (since in Python 2 int and float behave differently under division), but in Python 3 int is virtually a subclass of float (see PEP 3141). So it's not a crazy idea.

However, it's a bit of a slippery slope. Pretty much everything in the math module always returns a float. Or do you propose that math.sin(0) also return 1 instead of 1.0?

Also, how important is it to use this? I suspect the only reason it exists as a builtin is that it handles -0.0 correctly. But that's really only of interest to people doing serious floating point stuff. For everyone else, it's pretty much this one-liner:

def copysign(x, y):
    return abs(x) if y >= 0 else -abs(x)

On Thu, Nov 28, 2019 at 4:20 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.
Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct:

--Guido van Rossum (
Pronouns: he/him (why is my pronoun here?)