[Python-ideas] Why no sign function?

Mark Dickinson dickinsm at gmail.com
Mon Apr 26 23:36:14 CEST 2010


On Mon, Apr 26, 2010 at 10:12 PM, cool-RR <cool-rr at cool-rr.com> wrote:
> This was probably discussed a lot. Why is there no simple `sign` function in
> Python, like in the math module or something? I mean one that tells you the
> sign of a number.

What are your use-cases?  Can you give some examples of how you'd
expect to use it?

Given math.copysign and direct comparisons like "if x > 0", I don't
think I've ever wanted a sign function.

If a sign function were implemented, I'd probably want something like
IEEE 754's signbit function, returning 1 for negative values and -0.0,
and 0 for positive values and 0.0.  Ideally, something giving a
boolean result:  hasSignBit.  (Insert better name here.)

Mark



More information about the Python-ideas mailing list