gcc replaces pow(x, 0.5) by sqrt(x). This is invalid when x is -0. Indeed,
according to ISO C99 (N1256), F.9.4.4:

  pow(±0, y) returns +0 for y > 0 and not an odd integer.

So, pow(-0.0, 0.5) should return +0. But sqrt(-0.0) should return -0 according
to the IEEE 754 standard (and F.9.4.5 from ISO C99).

Testcase:

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

int main (void)
{
  volatile double x = -0.0;

  printf ("sqrt(-0)    = %g\n", sqrt (x));
  printf ("pow(-0,0.5) = %g\n", pow (x, 0.5));
  return 0;
}


-- 
           Summary: gcc replaces pow(x, 0.5) by sqrt(x), invalid when x is -
                    0
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vincent at vinc17 dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43419

Reply via email to