octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: signbit and logical tests


From: Mike Miller
Subject: Re: signbit and logical tests
Date: Sun, 10 Feb 2013 11:45:01 -0500

On Sun, Feb 10, 2013 at 11:23 AM, Michael D. Godfrey wrote:
> On 02/10/2013 11:05 AM, Mike Miller wrote:
>>
>> On Sun, Feb 10, 2013 at 1:37 AM, Michael D. Godfrey wrote:
>>>
>>> >It is curious.  The code (in libinterp/corefcn/mappers.cc) seems to
>>> >read as it will return an integer which is what the C++ signbit function
>>> >does.
>>> >However:
>>> >octave:1> sbit = signbit(-1.2)
>>> >sbit =  1
>>> >octave:2> whos
>>> >Variables in the current scope:
>>> >
>>> >    Attr Name        Size                     Bytes  Class
>>> >    ==== ====        ====                     =====  =====
>>> >         sbit        1x1                          8  double
>>> >
>>> >So, I am missing something.
>>
>> The function called there is xsignbit, which is defined at
>>
>>
>> http://hg.savannah.gnu.org/hgweb/octave/file/999f8257313b/liboctave/numeric/lo-mappers.h#l404
>>
>> This template function returns the same type as the argument.
>>
>> -- mike
>
> But, John said:
>>
>> The signbit function in Octave is just a simple wrapper around the system
>> library signbit function, and that returns the value of the sign bit as an
>> integer.  I don't know whether it would be a good idea to change that
>> definition for Octave.  The other function that I know of in Matlab that
>> returns something different from what the C library function returns is
>> strcmp.  So there is precedent for that kind of thing.  Or, if you want a
>> predicate-style function, maybe we should have isnegative instead?
>>
>> jwe
>
> I think that return logical would be more consistent with other Octave
> "logical" functions.
> Changing signbit to isnegative is possible, but, of course, sort order
> treats -0 as 0, so isnegative
> would be a bit confusing.

Understand. I was just explaining why you are seeing a double instead
of an integer. It really is just the value that the C math library
function returns but cast to a double.

My preference is for C functions in Octave to return what the C
library returns, so I'd keep signbit the way it is. Also note that you
can wrap it in logical() to get what you want, e.g.
logical(signbit(-0)).

-- 
mike


reply via email to

[Prev in Thread] Current Thread [Next in Thread]