signum() not in math?

Tim Peters tim.one at home.com
Sat Oct 13 00:20:52 EDT 2001


[Dinu Gherman]
> Time for a periodic frenzy about the standard lib again... ;-)

All right!  Controversy, conflict, catharsis and group hugs.

> How comes there is no sign() or signum() function in math?

You won't like the real answer, so maybe I won't give it.  OK, I will:
Python's math module is just a bunch of macro-generated thin wrappers around
the platform libm:

FUNC1(acos, acos,
      "acos(x)\n\nReturn the arc cosine (measured in radians) of x.")
FUNC1(asin, asin,
      "asin(x)\n\nReturn the arc sine (measured in radians) of x.")
FUNC1(atan, atan,
      "atan(x)\n\nReturn the arc tangent (measured in radians) of x.")

etc.

Python doesn't have signum because standard C doesn't, and that's all there
is to it.  The only thing Python's math module has that wasn't in strict C89
is math.hypot() (which almost every libm has, despite its absence in the C89
standard).  Conversely, everything in std C89 libm is in Python's math
module.

> ...
> 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.

> Ahh, a missing PEP, even? That could be the case... ;-)

The new C99 mandates a whole pile of useful new functions, although not this
one (the new signbit() function seems to come closest).  Chalk it up to a
lack of number-crunching worker bees.

in-the-meantime-try-comparing-to-0<wink>-ly y'rs  - tim





More information about the Python-list mailing list