God loves extended precision

Stuart McDonald uunet!hplabs.hpl.hp.com!mcdonald
Thu Jan 19 12:00:42 PST 1995


Jonathan,       Your requirement of portable C code makes it
                difficult.

                There are two ways to simulate double-precision
                on an extended-precision machine.

                First, the preferred way, is to set the hardware
                to double-precision mode.  There are no portable
                ways of doing this, alas, yet it only requires
                setting a pair of bits in a floating-point
                control reg. typically, or alerting the compiler
                to generate double-only code.  Some extended-based
                systems only narrow precision, not range, so
                your portable double-precision simulations had
                better not bump into double's under/overflow
                threshold, or else they may get better answers
                than expected!

                Second, the software way, requires access to
                the inexact flag and control of IEEE roundings.
                Transportability in this area is better than the
                first approach because every IEEE system must
                provide access to the flags and roundings control.
                The Numerics C Extensions Group (NCEG) of X3J11
                even has a technical report with recommendations
                for a standard set of C headers for this purpose.
                        Here's how you compensate for
                        two-roundings-not-one via software:
                                o  Do the op to extended;
                                o  If it was inexact, redo it
                                   in round-towards-zero mode AND
                                        if the least significant bit
                                        of the extended result is zero,
                                        set it to one;
                                o  Store the result to a volatile double,
                                   or if really paranoid, call a subroutine
                                   to do same.

		P.S.  Double-only architectures?  Just say, No!  I personally
		like extended, and would never want to use a Standard C
		compiler that didn't have long double as a type wider than
		double!



More information about the Numeric-interest mailing list