1 |
Darren Dale wrote: |
2 |
> On my system, SciPy's signbit function reports that the sign bit is not set |
3 |
> for any number, positive or negative. Could someone here help me understand |
4 |
> how to test the libc signbit function? I have to admit I have no experience |
5 |
> with C programming. |
6 |
|
7 |
Hi Darren, |
8 |
|
9 |
the signbit fuction is actually a macro (as the manpage says) defined in |
10 |
math.h that in turn calls the right inline function (for the type |
11 |
needed) which is defined in mathinline.h --- so as far as i can see, |
12 |
libc should not be involved, only header files. I have attached a small |
13 |
example below on how to use the function. Please note the use of |
14 |
-std=c99 (you may also use -std=gnu99) as the macro is only activated |
15 |
when in C99 mode and gcc's default mode is C89 ("ANSI C"). If you're |
16 |
interested in the differences between the two standards the wikipedia |
17 |
entry on c has some info: |
18 |
http://en.wikipedia.org/wiki/C_programming_language |
19 |
|
20 |
|
21 |
the program (save it under signbit_test.c): |
22 |
[cut] |
23 |
#include <math.h> |
24 |
#include <stdio.h> |
25 |
|
26 |
int main() { |
27 |
printf("sign of 1.7 is %d\n", signbit(1.7)); |
28 |
printf("sign of -1.1 is %d\n", signbit(-1.1)); |
29 |
printf("sign of -0.0 is %d\n", signbit(-0.0)); |
30 |
printf("sign of 0.0 is %d\n", signbit(0.0)); |
31 |
return 0; |
32 |
} |
33 |
[/cut] |
34 |
|
35 |
compile with: |
36 |
gcc -Wall -std=c99 -lm signbit_test.c -o signbit_test |
37 |
|
38 |
run with: |
39 |
./signbit_test |
40 |
|
41 |
should produce this output: |
42 |
sign of 1.7 is 0 |
43 |
sign of -1.1 is -2147483648 |
44 |
sign of -0.0 is -2147483648 |
45 |
sign of 0.0 is 0 |
46 |
|
47 |
This was run with gcc 3.4.4 on amd64, if you want to i can try on a x86 |
48 |
install in qemu. |
49 |
|
50 |
Marco |
51 |
-- |
52 |
gentoo-science@g.o mailing list |