signum() not in math?

Dinu Gherman gherman at
Sat Oct 13 10:43:07 CEST 2001

Tim Peters wrote:
> [Dinu Gherman]
> > The question is: why isn't sign() in the math module (or, may-
> > be built-in)? Is it too trivial? I'm inclined to claim no more
> > so than, say, abs().
> It's certainly far less used than abs().
> > ...
> > Nobody needing it? Surprising.
> That too, I think:  in part of your msg I snipped, you confessed 
> <wink> to not finding a msg about it more recent than nearly 
> 3 years old.

Thanks, Tim!

I'm not quite convinced, though, this should be the ultimate 
reason! The more fundamental question behind these issues is: 
Can someone expect from the Python standard library, too, 'only' 
those 90% of functionality needed by 'the crowd' and be treated 
with regret when not belonging to it, especially when the matter 
is so trivial?

The reason for people not complaining about the absence of the
sign() function need not necessarily be that they use something
like tanh() more often (I doubt so), but simply because they 
can write sign() with far less difficulty than tanh().

One can argue if this is a good thing. Newbies might learn some-
thing by writing sign() themselves, but will probably wonder why 
they *have* to? (While nobody expects to find the Riemann Zeta 
function in the math module, that you get in Mathematica...) 

In math textbooks sign() is typically introduced just before or 
after abs(), which raises the question why Python has chosen to 
implement only abs() and not only sign(), especially as they can 
be expressed in terms of each other? Orthogonal design? Ok, but 
the same is true for sin() and cos() and still, both are there 
in the math module!

As the ActiveState Python cookbook comes closer to being printed
it would be sort of embarassing to see a recipe therein for wri-
ting a signum function, simply because you need it, wouldn't it?



Dinu C. Gherman
UN Resolution 42/159 on fighting international terrorism (1987),
adopted by 153-2 votes (US and Israel against):

More information about the Python-list mailing list