Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Could someone please try this 6-lic C program?

1 view
Skip to first unread message

David Kirkby

unread,
Dec 31, 2009, 11:26:13 AM12/31/09
to
Is there anyone with access to a native IBM C compiler who could tell
me the output of this program

#include <math.h>
#include <stdio.h>

int main() {
printf("%.16lf\n",exp(1.0));
}


I've tried this program on 9 different hardware/software combinations,
using both the GNU and native compilers on AIX, HP-UX (PA-RISC),
Linux, Solaris 10 (SPARC), Open Solaris (x86). All except Sun Studio
on SPARC give a correctly rounded result of 2.7182818284590451, but
Sun Studio on SPARC gives a different answer of 2.7182818284590455.

I'd like to know what IBM's compiler on AIX gives, if anyone has a
minute and could compile it.

Dave

Michael Kraemer

unread,
Jan 1, 2010, 5:19:54 AM1/1/10
to
David Kirkby schrieb:

VAC 6, on AIX 5.1:

$ cc -o davidkirkby -lm davidkirkby.c
$ davidkirkby
2.7182818284590451

sjm

unread,
Jan 1, 2010, 7:40:31 AM1/1/10
to

12:38 $ pwd
/home/simon/src/6-line
12:38 $ ls
doit.c
12:38 $ cat doit.c
#include <math.h>
#include <stdio.h>

int main() {
printf("%.16lf\n",exp(1.0));

}
12:38 $ xlc -qversion
IBM XL C/C++ Enterprise Edition V8.0 for AIX
Version: 08.00.0000.0000
12:38 $ CC=xlc make CFLAGS=-lm doit
xlc -lm doit.c -o doit
12:38 $ ./doit
2.7182818284590451
12:40 $ uname -vr
2 5
12:40 $

David Kirkby

unread,
Jan 1, 2010, 9:21:57 AM1/1/10
to

Thank you both for computing this. Solaris on SPARC gives a different
value as you can see if Sun Studio is used. In fact, it gives a
different value with gcc if a slightly more complex program is
compiled. It would appear that in this case, gcc can inline this, so
does not need to make a call to the maths library.

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
double x = 1.0;
if (argc>1)
x = atof(argv[1]);
printf("%.16lf\n",exp(x));
}

The above prints the a different value on SPARC to all other systems
tried.

Whether this is a bug in Sun's maths library is open to opinion. It
may be that Sun do not feel it worth spending the extra processor
cycles to get a more accurate result, when subsequent computations are
later performed on a processor using only 64 bits, where the precision
will soon be lost. On x86 the situation is different, because the
floating point processor uses 80 bits internally. I've no idea where
processors used on AIX and HP-UX fit in. Both give a more accurate
result than SPARC.

Anyway, thank you both for your help. It was much appreciated.

Dave

0 new messages