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:05:56 -0500

On Sun, Feb 10, 2013 at 12:48 AM, Daniel J Sebald
<address@hidden> wrote:
> On 02/09/2013 09:02 PM, Michael D. Godfrey wrote:
>> This does not quite appear to be the case because this problem started
>> with bug #38291 which
>> showed that on at least one 32bit system (Ubuntu) the returned value for
>> true is 512.
>> That is why my test for == 1 failed.
>
> Just curious how that is coming about.  Any guess?  I would think that C
> defines a logical true as 1.

The return value for signbit is defined as zero for false, non-zero
for true. You can easily verify this with a C program:

address@hidden:~/src$ cat signbit.c
#include <math.h>
#include <stdio.h>
int main()
{
    printf ("signbit(-12.0) = %d\n", signbit(-12.0));
}
address@hidden:~/src$ gcc -m64 -o signbit signbit.c -lm; ./signbit
signbit(-12.0) = 128
address@hidden:~/src$ gcc -m32 -o signbit signbit.c -lm; ./signbit
signbit(-12.0) = -2147483648


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


reply via email to

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