octave-maintainers
[Top][All Lists]
Advanced

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

Re: signbit and logical tests


From: Michael D. Godfrey
Subject: Re: signbit and logical tests
Date: Sun, 10 Feb 2013 11:23:31 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

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.

Michael






reply via email to

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