Robert Klemme wrote:
> On 29.04.2009 17:39, Jeff Schwab wrote:
>> Robert Klemme wrote:
>>> On 28.04.2009 22:27, Jeff Schwab wrote:
>>>> Thomas B. wrote:
>>>>> Hello.
>>>>>
>>>>> I have a simple question - how to detect if a variable contains a 
>>>>> Float
>>>>> of value -0.0? Is there any special method for this, or any comparison
>>>>> that distinguishes negative zero from a the regular zero?
>>>>
>>>> NB: I'm not sure how portable this is.
>>>>
>>>> def negative_zero?(number)
>>>>   inverse = 1 / number.to_f
>>>>   inverse < 0 && inverse.infinite? ? true : false
>>>
>>> Why do you use the ternary operator to convert a boolean into a boolean?
>>
>> I don't.  Float#infinite? can return nil, -1, or +1, but never true or 
>> false. Without the ternary, the original client code produces the 
>> following, far less meaningful output, including the blank line:
>>
>> false
>> -1
>>
>> false
> 
> Well, but all these are perfectly boolean values in Ruby.

They can be used seamlessly in boolean contexts, but that does not make 
them boolean values in the sense that true and false are.

> There is no 
> need to convert the expression other than for display maybe.

You mean, like, maybe in a Usenet post?

> But in 
> that case I'd do the conversion outside the method as it does not add 
> any semantics to the method implementation but costs time.

Have you done enough profiling to demonstrate that there is in fact a 
performance penalty, and that it justifies adding complexity to the 
client code?  Silliness.  Let the function return consistent, 
predictable values, and quit your whining.