[Python-ideas] Why no sign function?
Nick Coghlan
ncoghlan at gmail.com
Tue Apr 27 11:52:06 CEST 2010
Mark Dickinson wrote:
> On Mon, Apr 26, 2010 at 10:36 PM, Mark Dickinson <dickinsm at gmail.com> wrote:
>> If a sign function were implemented, I'd probably want something like
>> IEEE 754's signbit function
>
> Correction: it's C99 that has a signbit function. IEEE 754-2008
> specifies an 'isSignMinus' function with exactly the same semantics:
> values with the sign bit set (including -0.0, -inf, and NaNs whose
> sign bit is set) return True; other values return False.
>
> I wouldn't object to a `math.is_signed` function or a
> `float.is_signed` method with these semantics. It's not clear where
> is the better place: we have `math.isnan` and `math.isinf`, but
> `float.is_integer`.
"is_signed" would probably be a bad name for this purpose. In typical
compsci parlance, all of our numeric types are signed.
For the semantics you're talking about, math.signbit would be a more
reasonable name. (since we can legitimately answer the question for both
integers and floats, whereas "is_integer" is a pretty redundant question
if you are dealing with an integer type)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-ideas
mailing list