<?xml version="1.0" encoding="windows-1252"?>
<node id="984270" title="Re^2: Exploring IEEE754 floating point bit patterns." created="2012-07-29 02:46:06" updated="2012-07-29 02:46:06">
<type id="11">
note</type>
<author id="171588">
BrowserUk</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;
Actually, make that 10 separate symbols, as the 5 nan symbols that appear in the output of BrowserUk's qnan.c, under some circumstances, will be suffixed with '0' ('00' in the case of -1.#IND).I wonder why so many symbols are needed ?
&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;The suffixing of zeros to the symbols is just an artifact of using "%f" printf format, which implicitly is equivalent to "%.6f" and therefore requires that the fractional part be padded with trailing zeros to 6 places.

&lt;p&gt;If you adjust the template, you can see this. (The printf from your code above + output):&lt;code&gt;
    printf("%f %f\n",       inf / inf, -(inf / inf)); // -1.#IND00 -1.#IND00
    printf("%.4f %.4f\n",   inf / inf, -(inf / inf)); // -1.#IND -1.#IND
    printf("%.10f %.10f\n", inf / inf, -(inf / inf)); // -1.#IND000000 -1.#IND000000
&lt;/code&gt;

&lt;P&gt;I've found %g more useful:&lt;code&gt;
    printf("%g %g\n", inf / inf, -(inf / inf));      // -1.#IND -1.#IND
&lt;/code&gt;

&lt;blockquote&gt;&lt;i&gt;
It's also interesting that,of my Microsoft compilers (6.0, 7.0 and 8.0), none of them produce the same output as BrowserUk's 9.0 compiler.
&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;The changes are (roughly) in line with the timing of the compiler releases relative to the requirements of the various ANSI C standards C89/C90/C99/C11; and as affected by the updates to the IEEE754 (1987) standard and its revision in 2004. (Roughly:)

&lt;blockquote&gt;&lt;i&gt;
For that program, my 8.0 MS compiler outputs: -1.#IND00 -1.#IND00 but my gcc-4.5.2 produces: -1.#IND00 1.#QNAN0 Which one is doing it correctly ?
&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;You'll hate this answer. Effectively, &lt;b&gt;they both are!&lt;/b&gt;.

&lt;P&gt;The problem is, the computer scientists and the mathematicians can't agree on a single [http://en.wikipedia.org/wiki/NaN#Function_definition|Function definition] with respect to FP math. 

&lt;p&gt;The problem is two-fold:

&lt;ol&gt;&lt;li&gt;FP math isn't like real math (Real in the mathematical sense).

&lt;p&gt;Eg. FP is not always associative: &lt;code&gt;
print +( 10.0**20 + 1 ) - 10.0**20;;
0

print +( 10.0**20 - 10.0**20 ) + 1;;
1
&lt;/code&gt;

&lt;/li&gt;&lt;li&gt;Mathematicians have conventions for the results of some operations that don't quite work arithmetically.

&lt;p&gt;Eg. infinity**0 == 1!

&lt;P&gt;These allow their operations on the continuous Real domain to avoid singularity points

&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;You pays your money and makes your choice.

&lt;blockquote&gt;&lt;i&gt;What operations will result in a signalling nan ?&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;From what I've been able to discover, &lt;b&gt;none of them!&lt;/b&gt; (At least as far as MSC v9 is concerned.)

&lt;p&gt;The problem here is that the IEEE-754 &lt;i&gt;allows&lt;/i&gt; for traps, but doesn't &lt;i&gt;require them&lt;/i&gt;. See [http://en.wikipedia.org/wiki/NaN#Signaling_NaN|Signaling NaNs]

&lt;P&gt;My take on what I see coming out of my attempts to produce NaNs with MSC(v9), is that they settled on using -1.#IND as the result of any math operation that is (for want of a better phrase) 'not well defined'. eg. sqrt( -1 ), 0/0; fmod( 1, 0 ) etc.

&lt;div class="pmsig"&gt;&lt;div class="pmsig-171588"&gt;
&lt;hr /&gt;
&lt;font size=1 &gt;
&lt;div&gt;With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'&lt;/div&gt;
&lt;div&gt;Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.&lt;/div&gt;
&lt;div&gt;"Science is about questioning the status quo. Questioning authority". &lt;/div&gt;
&lt;div&gt;In the absence of evidence, opinion is indistinguishable from prejudice.
&lt;p align=right&gt;[http://www.theregister.co.uk/2011/11/29/sas_versus_world_programming/|The start of some sanity?]&lt;/p&gt;&lt;/div&gt;
&lt;/font&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
984141</field>
<field name="parent_node">
984264</field>
</data>
</node>
