Gentoo Archives: gentoo-science

From: Darren Dale <dd55@×××××××.edu>
To: gentoo-science@l.g.o
Subject: Re: [gentoo-science] question about signbit
Date: Thu, 27 Oct 2005 12:53:28
Message-Id: 200510270852.35524.dd55@cornell.edu
In Reply to: Re: [gentoo-science] question about signbit by Marco Matthies
1 Hi Marco,
2
3 On Saturday 22 October 2005 5:05 pm, Marco Matthies wrote:
4 > Darren Dale wrote:
5 > > On my system, SciPy's signbit function reports that the sign bit is not
6 > > set for any number, positive or negative. Could someone here help me
7 > > understand how to test the libc signbit function? I have to admit I have
8 > > no experience with C programming.
9 >
10 > Hi Darren,
11 >
12 > the signbit fuction is actually a macro (as the manpage says) defined in
13 > math.h that in turn calls the right inline function (for the type
14 > needed) which is defined in mathinline.h --- so as far as i can see,
15 > libc should not be involved, only header files. I have attached a small
16 > example below on how to use the function. Please note the use of
17 > -std=c99 (you may also use -std=gnu99) as the macro is only activated
18 > when in C99 mode and gcc's default mode is C89 ("ANSI C"). If you're
19 > interested in the differences between the two standards the wikipedia
20 > entry on c has some info:
21 > http://en.wikipedia.org/wiki/C_programming_language
22 >
23 >
24 > the program (save it under signbit_test.c):
25 > [cut]
26 > #include <math.h>
27 > #include <stdio.h>
28 >
29 > int main() {
30 > printf("sign of 1.7 is %d\n", signbit(1.7));
31 > printf("sign of -1.1 is %d\n", signbit(-1.1));
32 > printf("sign of -0.0 is %d\n", signbit(-0.0));
33 > printf("sign of 0.0 is %d\n", signbit(0.0));
34 > return 0;
35 > }
36 > [/cut]
37 >
38 > compile with:
39 > gcc -Wall -std=c99 -lm signbit_test.c -o signbit_test
40 >
41 > run with:
42 > ./signbit_test
43 >
44 > should produce this output:
45 > sign of 1.7 is 0
46 > sign of -1.1 is -2147483648
47 > sign of -0.0 is -2147483648
48 > sign of 0.0 is 0
49 >
50 > This was run with gcc 3.4.4 on amd64, if you want to i can try on a x86
51 > install in qemu.
52
53 Here is another test:
54
55 #include <math.h>
56 #include <stdio.h>
57
58 int main() {
59 printf("signbit(-1): %d\n", signbit(-1));
60 printf("isnan(0.0/0): %d\n", isnan(0.0/0));
61 printf("isinf(1.0/0): %d\n", isinf(1.0/0));
62 return 0;
63 }
64
65 which yields:
66
67 signbit(-1): -2147483648
68 isnan(0.0/0): 1
69 isinf(1.0/0): 1
70
71 Do you know why signbit doesn't yield 1? I wonder if this might be the source
72 of the problem in Scipy.
73
74 Thanks,
75 Darren
76 --
77 gentoo-science@g.o mailing list

Replies

Subject Author
Re: [gentoo-science] question about signbit Miguel Barao <mjsb@×××××××××××××××.pt>
Re: [gentoo-science] question about signbit Marco Matthies <marco-ml@×××.net>