Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Useful Treatment of NaN and Inf by Microsoft C++
    primarykey
    data
    text
    <p>Consider the following test program </p> <pre><code>#include &lt;iostream&gt; #include &lt;stdio.h&gt; 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",&amp;aa,&amp;bb,&amp;cc); cout&lt;&lt;aa&lt;&lt;endl&lt;&lt;bb&lt;&lt;endl&lt;&lt;cc&lt;&lt;endl; } </code></pre> <p>when compiled with gcc (any platform that I have tried) creates a file ttt.txt with the contents </p> <p>Inf 4.500000 NaN </p> <p>gives the output <br/></p> <p>Inf<br/> 4.5<br/> NaN<br/></p> <p>No surprises there. Correct behavior under the rules of C99, and things like Matlab</p> <p>Compiling the same program under Microsoft Visual Studio 2008 however gives a file ttt.txt with the contents</p> <p>1.#INF00 4.500000 -1.#IND00 </p> <p>and gives an output of <br/></p> <p>1<br/> -9.25596e+061<br/> -9.25596e+061<br/></p> <p>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.</p> <p>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</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload