Atan2, Atan2f, Atan2l Give Inconsistent Results On Solaris

(Doc ID 1936259.1)

Last updated on SEPTEMBER 21, 2017

Applies to:

Oracle Solaris Studio - Version 12.3 and later
Information in this document applies to any platform.


atan2 returns 0 for all combinations of +/-0 as argument:


OS: Oracle Solaris 10 1/13 s10s_u10wos_17b SPARC
cc: Sun C 5.12 SunOS_sparc Patch 148917-07 2013/10/18
acomp: Sun C 5.12 SunOS_sparc Patch 148917-07 2013/10/18
ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.1518

Test case:

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

int main() {

   double pzero_double, nzero_double;

   pzero_double = 0.0;
   nzero_double = 0.0 * -1.0;
   printf("pzero: %g\n", pzero_double);
   printf("nzero: %g\n", nzero_double);

   printf("atan2(pzero, nzero) = %g (expected: +pi)\n", atan2(pzero_double, nzero_double));
   printf("atan2(nzero, nzero) = %g (expected: -pi)\n", atan2(nzero_double, nzero_double));
   printf("atan2(pzero, pzero) = %g (expected: +0)\n", atan2(pzero_double, pzero_double));
   printf("atan2(nzero, pzero) = %g (expected: -0)\n", atan2(nzero_double, pzero_double));

   return 0;


pzero: 0
nzero: -0

atan2(pzero, nzero) = 0 (expected: +pi)
atan2(nzero, nzero) = 0 (expected: -pi)
atan2(pzero, pzero) = 0 (expected: +0)
atan2(nzero, pzero) = 0 (expected: -0)


Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms