Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with the math library functions

807578Oct 10 2007 — edited Oct 16 2007
Hi,

I encountered a problem related to some functions provided by math library on sun. I narrowed it down to the following test program:

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

void pow_res()
{
double x = 10.0;
double y = 2.5;

printf("pow(%.2e, %.2e):%.20e\n", x, y, pow(10.0, 2.5));
}

void cos_res()
{
double x = -6.433230338433114370e-02;

printf("x:%.20e cos(x):%.20e\n", x, cos(x));
}

int main()
{
pow_res();
cos_res();
return 0;
}
========================================================

The above test program has to be linked with any math library. It is �libm� for amd64/linux, but for sparc we have choice between �libm� and �libmopt�. I am compiling above program with "cc <test_program.c> <-lm/-lmopt>" command.

On sparc, if the above test program is getting linked with �-lm" then it gives same results for the �cos� on both amd64 and sparc, but gives different results (16th decimal digit onward) for �pow�. If it is getting linked with �-lmopt� then it gives same result for the �pow� on both the platforms, but gives different results for �cos�. Linux results match with the amd64 results.

The �Numerical Computation Guide� provided by SUN (ftp://docs-pdf.sun.com/802-5692/802-5692.pdf page 40, table 2.10 ) says that you can trust only 15-17 decimal digits for double calculation. But here the requirement is to match the sparc results exactly with the amd64/linux or at least match the result till 20th decimal digit. I guess it is something to do with the FPU setting either through compiler options or code. I tried many different compiler options, like -fast, different combinations of compiler options provided by -fast macro, but nothing helped.

Following is the system configuration:
Amd64:
gcc version: 3.3.6
OS: RedHat Enterprise Linux 3.0 U7 (Linux 2.4.21-40.ELsmp x86_64)

Sparc:
cc version: Sun C 5.8 Patch 121015-01
OS: SunOS 5.9 Generic_118558-21 sun4u sparc SUNW,Sun-Fire-280R

It will be great if somebody can explain the problem and the solution to get rid of it.

Many thanks,
Sunil
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 13 2007
Added on Oct 10 2007
2 comments
236 views