On 02/10/2013 10:05 AM, Mike Miller wrote:
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
As usual, this is a bit more complex/confusing than first meets the eye.
I see now it looks like C (not C++, but C) defined "signbit()" so that
the compiler could generate adequate information about the sign bit with
minimal amounts of assembly instructions. That is, whatever combination
of shifting, register manipulations, etc. that is minimum is adequate.
No need to make that signbit() result be 1 because more than likely, the
programmer writing C code will do something like
if (signbit(x)) {
}
So, if the compiler does some extra step to make signbit() 0 or 1, it's
a bit like doing the same conditional test twice.
Now, here is the monkey wrench. There is a standard C++ (not C, but C++)
library function std:signbit which DOES produce a logical 0 or 1. Observe:
address@hidden cat signbit.c
#include <math.h>
#include <stdio.h>
int main()
{
printf ("signbit(-12.0) = %d\n", signbit(-12.0));
}
[1]+ Done gvim signbit.c
address@hidden gcc -m64 -o signbit signbit.c
address@hidden ./signbit
signbit(-12.0) = 128
address@hidden cat signbit.c
/*#include <math.h>*/
#include <stdio.h>
int main()
{
printf ("signbit(-12.0) = %d\n", signbit(-12.0));
}
address@hidden gcc -m64 -o signbit signbit.c
address@hidden ./signbit
signbit(-12.0) = 1