[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

COBOL, IEEE Std 754-2008 Signaling NaN



On Sun, 20 Mar 2011 09:50:01 -0600 Charles Stevens wrote:

Comments?  Further refinement suggestions?  

Will there be support for Signaling NaNs (in either binary FP
or decimal FP)?

If yes, what will be printed for them? 
What forms will be valid input to read at run time?

Fortran, since at least the 2003 standard has had "support" for
signaling NaNs, but most implementations that I have seen the
output from, print the same string NaN for both quiet and 
signaling NaNs.  The only exception is IBM that prints NaNQ
and NaNS (which does not conform to Standard Fortran).

Standard Fortran says that (case insensitive) NAN and NAN()
are quiet NaNs, while everything else is processor dependent.

C99 considered adding support for Signaling NaNs, but decided
against.  There is a group of people writing a technical report
on adding IEEE-754-2008 to C, and part of the report is a section
on signaling NaNs.

Here is a Fortran program to see if signaling NaNs can be
created, and to see what prints:

        program ieee_test_nan

        use, intrinsic :: ieee_arithmetic
        implicit none
        real(4) :: ss, sq,x
        real(8) :: ds, dq
        integer(4) :: iss,isq
        integer(8) :: ids,idq
        character(25) :: css, csq, cds, cdq

        ss = ieee_value(ss,ieee_signaling_nan)
        iss = transfer(ss,iss)
        sq = ieee_value(sq,ieee_quiet_nan)
        isq = transfer(sq,isq)
        ds = ieee_value(ds,ieee_signaling_nan)
        ids = transfer(ds,ids)
        dq = ieee_value(dq,ieee_quiet_nan)
        idq = transfer(dq,idq)

        write (*,"(a22,f8.3,z10.8)") "ieee_signaling_nan is ", ss,iss
        write (*,"(a22,f8.3,z10.8)") "ieee_quiet_nan     is ", sq,isq

        if (ieee_class(ss) == ieee_signaling_nan) then
           css = " = ieee_signaling_nan"
        else
           css = "NOT ieee_signaling_nan"
        end if

        if (ieee_class(sq) == ieee_quiet_nan) then
           csq = " = ieee_quiet_nan"
        else
           csq = "NOT ieee_quiet_nan"
        end if

        if (ieee_class(ds) == ieee_signaling_nan) then
           cds = " = ieee_signaling_nan"
        else
           cds = "NOT ieee_signaling_nan"
        end if

        if (ieee_class(dq) == ieee_quiet_nan) then
           cdq = " = ieee_quiet_nan"
        else
           cdq = "NOT ieee_quiet_nan"
        end if

        write (*,*) "snan, 32-bit prints as: ", ss, " ", css
        write (*,*) "qnan, 32-bit prints as: ", sq, " ", csq
        write (*,*) "snan, 64-bit prints as: ", ds, " ", cds
        write (*,*) "qnan, 64-bit prints as: ", dq, " ", cdq

        end

---
Fred J. Tydeman        Tydeman Consulting
tydeman@xxxxxxxxx      Testing, numerics, programming
+1 (775) 358-9748      Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.


754 | revision | FAQ | references | list archive