[Python-ideas] Why no sign function?

cool-RR cool-rr at cool-rr.com
Mon Apr 26 23:21:39 CEST 2010


On Mon, Apr 26, 2010 at 11:16 PM, Xavier Ho <contact at xavierho.com> wrote:

> On Tue, Apr 27, 2010 at 7:12 AM, 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.
>>
>>
> I really hate to shot you down man. First of all, how are you returning the
> sign? True/False for positive or negative? What about zero? Is zero a
> positive or a negative number?
>
> Secondly, when you get the output, how are you using it? Comparison -- ah
> wait, there is always if x > 0 ...
>
> I think you need to carefully think about these ideas before proposing
> them. I feel you're wasting your own time, here.
>
> Cheers,
> Xav
>

Hey Xavier,

I don't feel I'm wasting my time. If you feel I'm wasting yours you are free
to ignore my messages.

I return 1 for positive, 0 for zero, -1 for negative. Yes, I know I can
improvise something like it, by using `x > 0` or `cmp(x, 0)`, but I like
code that reads like what it does.

Ram.


-- 
Sincerely,
Ram Rachum
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100426/d3c49a85/attachment.html>


More information about the Python-ideas mailing list