Consider the following test program
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, char* argv[])
{
double a=1,c=0;
double i = a/c; // divide by 0 yields infinity
double j = a*4.5;
double k = c/c; // 0 divide 0 yields NaN
FILE * fp = fopen("ttt.txt","wt");
fprintf(fp,"%f\t%f\t%f\t",i,j,k);
fclose(fp);
double aa,bb,cc;
fp = fopen("ttt.txt","rt");
fscanf(fp,"%lf%lf%lf",&aa,&bb,&cc);
cout<<aa<<endl<<bb<<endl<<cc<<endl;
}
when compiled with gcc (any platform that I have tried) creates a file ttt.txt with the contents
Inf 4.500000 NaN
gives the output
Inf
4.5
NaN
No surprises there. Correct behavior under the rules of C99, and things like Matlab
Compiling the same program under Microsoft Visual Studio 2008 however gives a file ttt.txt with the contents
1.#INF00 4.500000 -1.#IND00
and gives an output of
1
-9.25596e+061
-9.25596e+061
Such that Microsoft C can not even read it's own representations of Inf and NaN let alone the standard ones, which is utterly useless - any why they would implement it this way is completely beyond me. I know that MSVcc is not completely C99 compliant - BUT Does anyone have any suggestions on how to persuade it to read and write these values, compiler switches, another version of stdio.h, anything.
It seems that the only way around this is to implement my own functions to replace fscanf and fprintf but that does seem like re-inventing the wheel. I can't believe I'm the first person to find this annoying - to the point of making Microsoft's stdio library useless, and yet Google is turning up nothing on the subject