ATAN2 Special Case

Dear Moderator,

This is regarding some special cases for the ATAN2 function. I tried compiling the code give below using the PGI pgcc (version 7.2-5) and GNU gcc compilers, and the results seem to be different. The output of the gcc compiled code seems to be consistent with the FDLIBM definition used in MATLAB. Is there a difference in the way special cases are defined for the ATAN2 function in the pgi built-in math library?

Thanks,

VV

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

int main()
{
    printf("TESTING ATAN2 SPECIAL CASES\n");
    printf("ATAN2(+0.0,+x) %+20.15e\n",atan2(+0.0,+0.5));
    printf("ATAN2(-0.0,+x) %+20.15e\n",atan2(-0.0,+0.5));
    printf("ATAN2(+0.0,-x) %+20.15e\n",atan2(+0.0,-0.5));
    printf("ATAN2(-0.0,-x) %+20.15e\n",atan2(-0.0,-0.5));

    return 0;
}

pgcc output
<pgcc test.c -o test_pgi>

ATAN2(+0.0,+x) +0.000000000000000e+00
ATAN2(-0.0,+x) +0.000000000000000e+00
ATAN2(+0.0,-x) +3.141592653589793e+00
ATAN2(-0.0,-x) +3.141592653589793e+00

gcc output
<gcc test.c -o test_gcc -lm>

TESTING ATAN2 SPECIAL CASES
ATAN2(+0.0,+x) +0.000000000000000e+00
ATAN2(-0.0,+x) -0.000000000000000e+00
ATAN2(+0.0,-x) +3.141592653589793e+00
ATAN2(-0.0,-x) -3.141592653589793e+00

Hi VV,

This is actually a problem with how we handle “-0” and is a known issue. Unfortunately, there isn’t a work around for this problem except to avoid the use of “-0”.

Sorry,
Mat

Thanks Mat.