This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

isfinite returning wrong results


I'm having trouble figuring this out.  isfinite is sometimes returning
incorrect results.

In one more complicated program, I saw isfinite returning false for
negative 0 and true for -Inf, and otherwise correctly, but once I got
it down to this test case, isfinite, which is just a macro in math.h
that calls fpclassify twice, returns true for everything.  The macro
looks to be completely correct, and fpclassify is working.

$ cat isfin.c
#include <stdio.h>
#include <math.h>

int main(int argc, char **argv) {
  double z = 0;
  double nan = 0/z;
  double inf = pow(9,999);
  double ninf = pow(-9,999);
  double nz = -(long double)0;

  printf("nan %g inf %g ninf %g z %g nz %g\n", nan, inf, ninf, z, nz);
  printf("fpclassify: nan %d inf %d ninf %d z %d nz %d\n", fpclassify(nan),
         fpclassify(inf), fpclassify(ninf), fpclassify(z), fpclassify(nz));
  printf("isfinite: nan %d inf %d ninf %d z %d nz %d\n", isfinite(nan),
         isfinite(inf), isfinite(ninf), isfinite(z), isfinite(nz));

  return 0;
}

$ gcc -o isfin.exe -Wall isfin.c;./isfin
nan NaN inf Inf ninf -Inf z 0 nz -0
fpclassify: nan 0 inf 1 ninf 1 z 2 nz 2
isfinite: nan 1 inf 1 ninf 1 z 1 nz 1

Attachment: cygcheck.out
Description: Text document

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]