<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
  <title>Decimal Types for C++: Second Draft</title>
</head>

<body>
<pre>
                                                  Doc No:   SC22/WG21/N1839
                                                            J16/05-0099
                                                  Date:     2005-06-24
                                                  Project:  JTC1.22.32
                                                  Reply to: Robert Klarer
                                                            IBM Canada, Ltd.
                                                            klarer@ca.ibm.com
</pre>

<h1>
Decimal Types for C++: Second Draft
</h1>

<h1>
0 About this document
</h1>
<p>
[<i>Editor's note:</i> this document is being proposed (by me) as a basis for continuing work.  None of the design choices implied in this work is final.  Better ideas, as well as comments and critiques will be gratefully received.]
</p>
<p>
This document is known to be incomplet, inkorrect, and badly forma<sup>tt</sup>ed.
</p>
<h1>
1 Introduction 
</h1>
<p>
Most of today's general purpose computing architectures provide binary floating-point arithmetic in hardware.  Binary float-point is an efficient representation that minimizes memory use, and is simpler to implement than floating-point arithmetic using other bases.  It has therefore become the norm for scientific computations, with almost all implementations following the IEEE-754 standard for binary floating-point arithmetic.
</p>
<p>
However, human computation and communication of numeric values almost always uses decimal arithmetic, and decimal notations.  Laboratory notes, scientific papers, legal documents, business reports and financial statements all record numeric values in decimal form.  When numeric data are given to a program or are displayed to a user, binary to-and-from decimal conversion is required.  There are inherent rounding errors involved in such conversions; decimal fractions cannot, in general, be represented exactly by floating-point values.  These errors often cause usability and efficiency problems, depending on the application.
</p>
<p>
These problems are minor when the application domain accepts, or requires results to have, associated error estimates (as is the case with scientific applications).  However, in business and financial applications, computations are either required to be exact (with no rounding errors) unless explicitly rounded, or be supported by detailed analyses that are auditable to be correct.  Such applications therefore have to take special care in handling any rounding errors introduced by the computations.
</p>
<p>
The most efficient way to avoid conversion error is to use decimal arithmetic.  Recognizing this, the IEEE-754R Standard for Floating-Point Arithmetic specifies decimal floating-point encodings and arithmetic.  This technical report specifies extensions to the International Standard for the C++ programming language to permit the use of decimal arithmetic in a manner consistent with the IEEE-754R standard.
</p>
<h2>
1.1 Arithmetic model
</h2>
<p>
This Technical Report is based on a model of decimal arithmetic which is a formalization of the decimal system of numeration (Algorism) as further defined and constrained by the relevant standards,
IEEE-854, ANSI X3-274, and IEEE-754R.
</p>
<p>
There are three components to the model:
</p>
<ul>
<li>
<i>numbers</i> - which represent the values which can be manipulated by, or be the results of, the core operations defined in the model
</li>
<li>
<i>operations</i> - the core operations (such as addition, multiplication, etc.) which can be carried out on numbers
</li>
<li>
<i>context</i> - which represents the user-selectable parameters and rules which govern the results of arithmetic operations (for example, the rounding mode to be used)
</li>
</ul>
<p>
The model defines these components in the abstract. It defines neither the way in which operations are expressed (which might vary depending on the computer language or other interface being used), nor the concrete representation (specific layout in storage, or in a processor's register, for example) of numbers or context.
</p>
<p>
From the perspective of the C++ language, <i>numbers</i> are represented by data types, <i>operations</i> are defined within expressions, and <i>context</i>
is the floating environment specified in &lt;cfenv&gt; and &lt;fenv.h&gt;. This Technical Report
specifies how the C++ language implements these components.
</p>
<p>
Note: A description of the arithmetic model can be found in
http://www2.hursley.ibm.com/decimal/decarith.html.
</p>
<h2>
1.2 Encodings
</h2>
<p>
In the C++ International Standard, the representation of a floating-point number is specified in an abstract form where the constituent components of the representation are defined (sign, exponent, significand) but the internals of these components are not.   In particular, the exponent range, significand size and the base (or radix), are implementation defined. This allows flexibility for an implementation to take advantage of its underlying hardware architecture. Furthermore, certain behaviors of operations are also implementation defined, for example in the area of handling of special numbers and in exceptions.
</p>
<p>
This approach was inherited from the C programming language.  At the time that C was first standardized, there were already various hardware implementations of floating-point arithmetic in common use. Specifying the exact details of a representation would make most of the existing C implementations at the time not conforming.
</p>
<p>
The C99 standard specifies a binding to IEEE-754 (annex F).  Still, conformance to IEEE-754 is not a mandatory requirement.  A C99 implementation that conforms to IEEE-754 defines the macro __STDC_IEC_559__.
</p>
<p>
This Technical Report specifies decimal floating-point arithmetic according to the IEEE-754R standard, with the constituent components of the representation defined. This is more stringent than the approach taken for the floating point types in the C++ standard.  Since it is expected that all decimal floating-point hardware implementations will conform to the IEEE-754R standard, binding to this standard directly benefits both implementers and programmers.
</p>
<h2>
1.3 References
</h2>
<p>
The following standards contain provisions which, through reference in this text, constitute provisions of this Technical Report.  For dated references, subsequent amendment to, or revisions of, any of these publications do not apply.  However, parties to agreements based on this Technical Report are encouraged to investigate the possibility of applying the most recent editions of the normative documents indicated below.  For undated references, the latest edition of the normative document referred applies.  Members of the IEC and ISO maintain registers of current valid International Standards.
</p>
<p>
1.3.1 ISO/IEC 14882:2003, <em>Information technology -- Programming languages, their environments and system software interfaces -- Programming Language C++</em>.
</p>
<p>
1.3.2 ISO/IEC TR 19768:2005, <em>Information technology -- Programming languages, their environments and system software interfaces -- Technical Report on C++ Library Extensions</em>.
</p>
<p>
1.3.3 ANSI/IEEE 754R - <em>IEEE Standard for Floating-Point Arithmetic.  The Institute of Electrical and Electronic Engineers, Inc.</em>.
</p>
<p>
1.3.4 ANSI/IEEE 854-1997 - <em>IEEE Standard for Radix-Independent Floating-Point Arithmetic.  The Institute of Electrical and Electronic Engineers, Inc., New York,</em> 1987.
</p>
<h1>
2 Conventions
</h1>
<p>
This technical report is non-normative; the extensions that it describes may be considered for inclusion in a future revision of the International Standard for C++, but they are not currently required for conformance to that standard.  Furthermore, it is conceivable that a future revision of the International Standard will include facilities that are similar and not identical to the extensions described in this report,
</p>
<p>
Although this report describes extensions to the <em>C++ standard library</em>, vendors may choose to implement these extensions in the C++ language translator itself.  This practice is permitted so long as all well-formed programs are accepted by the implementation, and the semantics of those programs are the same as they would be had the extensions taken the form of a library.
[<em>Note:</em> The same practice is permitted with respect to the implementation of the C++ standard library. <em>--end note</em>]
</p>
<h2>
2.1 Relation to C++ Standard Library Introduction
</h2>
<p>
Unless otherwise specified, the whole of the ISO C++ Standard Library introduction [lib.library] is included into this Technical Report by reference.
</p>
<p>
This Technical Report introduces the following elements to supplement those described in [lib.structure.specifications]:
</p>
<ul>
<li>
<b>Constraints:</b> constraints on template arguments; these are enforced by the implementation
</li>
<li>
<b>Expansion:</b> the semantics of a macro's expansion text
</li>
</ul>
<h2>
2.2 Relation to "Technical Report on C++ Library Extensions"
</h2>
<p>
Unless otherwise specified, the following sections of ISO/IEC Technical Report 19768: "Technical Report on C++ Library Extensions" are included into this Technical Report by reference:
</p>
<ul>
<li>General [tr.intro]</li>
<li>Metaprogramming and type traits [tr.meta]</li>
<li>Additions to header <code>&lt;functional&gt;</code> synopsis [tr.unord.fun.syn]</li>
<li>Class template <code>hash</code> [tr.unord.hash]</li>
<li>C compatibility [tr.c99]</li>
</ul>
<h2>
2.3 Categories of extensions
</h2>
<p>
This technical report describes 4 categories of library extensions:
</p>
<ol>
<li>
New library components (types and functions) that are declared entirely in new headers, such as the type <code>dfp::decimal32</code> in the <code>&lt;dec32></code> header.
</li>
<li>
New library components declared as additions to existing standard headers, such as the functions added to the headers <code>&lt;cmath></code> and <code>&lt;math.h></code> in clause 3.7.
</li>
<li>
New library components declared as additions to TR1 headers, such as the template <code>is_decimal_floating_point</code> added to the header <code>&lt;type_traits></code> in clause 3.10.
</li>
<li>
Additions to standard library components, such as the specializations of <code>std::numeric_limits</code> in clauses 3.2.14, 3.3.14, and 3.3.15.
</li>
</ol>
<p>
New headers are distinguished from extensions to existing headers by the title of the <i>synopsis</i> clause.  In the first case the title is of the form "Header <code>&lt;foo></code> synopsis," and the synopsis includes all namespace scope declarations contained in the header.  In the second case the title is of the form "Additions to header <code>&lt;foo></code> synopsis" and the synopsis includes only the extensions, <i>i.e.</i> those namespace scope declarations that are not present in the C++ standard or TR1.
</p>
<h2>
2.4 Namespaces and headers
</h2>
<p>
The extensions described in this technical report are declared within the namespace <code>dfp</code>, which is nested inside the namespace <code>std</code>.
</p>
<p>
Unless otherwise specified, references to other entities described in this technical report are assumed to be qualified with <code>std::dfp::</code>, references to entities described in the C++ standard library are assumed to be qualified with <code>std::</code>, and references to entities described in TR1 are assumed to be qualified with <code>std::tr1::</code>.
</p>
<p>
Even when an extension is specified as additions to standard headers (the second and third categories in section 2.3), vendors should not simply add declarations to standard headers in a way that would be visible to users by default [<em>Note:</em> That would fail to be standard conforming, because the new names, even within a namespace, could conflict with user macros. <em>--end note</em>]  Users should be required to take explicit action to have access to library extensions.
It is recommended either that additional declarations in standard headers be protected with a macro that is not defined by default, or else that all extended headers, including both new headers and parallel versions of standard headers with nonstandard declarations, be placed in a separate directory that is not part of the default search path.
</p>
<h1>
3 Decimal floating-point types
</h1>
<p>
This Technical Report introduces three <i>decimal floating-point types</i>, named decimal32, decimal64, and decimal128.  The set of values of type decimal32 is a subset of the set of values of type decimal64; the set of values of the type decimal64 is a subset of the set of values of the type decimal128.  Support for decimal128 is optional.
</p>
<h2>
3.1 Decimal type encodings 
</h2>
<p>
The three decimal encoding formats defined in IEEE-754R correspond to the three decimal floating types as follows:
</p>
<ul>
<li>
decimal32 is a <em>decimal32</em> number, which is encoded in four consecutive bytes (32 bits)
</li>
<li>
decimal64 is a <em>decimal64</em> number, which is encoded in eight consecutive bytes (64 bits)
</li>
<li>
decimal128 is a <em>decimal128</em> number, which is encoded in 16 consecutive bytes (128 bits)
</li>
</ul>
<p>
{<i>Note:</i> this implies that <code>sizeof(std::dfp::decimal32) == 4</code>, <code>sizeof(std::dfp::decimal64) == 8</code>, and <code>sizeof(std::decimal128) == 16</code>.  <i>--end note</i>]
</p>
<p>
The finite numbers are defined by a sign, an exponent, (which is a power of ten), and a decimal integer coefficient.  The value of a finite number is given by (1)<sup>sign</sup> x coefficient x 10<sup>exponent</sup>.  Refer to IEEE-754R for details of the format.
</p>
<p>
These formats are characterized by the length of the coefficient, and the maximum and minimum exponent.  Table 1 shows these characteristics by format.
</p>
<h4>Table 1 -- Format Characteristics</h4>
<table border="1">
  <tbody>
    <tr>
      <td>Format</td>
      <td><b>decimal32</b></td>
      <td><b>decimal64</b></td>
      <td><b>decimal128</b></td>

    </tr>
    <tr>
      <td>Coefficient length in digits</td>
      <td>7</td>
      <td>16</td>
      <td>34</td>
    </tr>

    <tr>
      <td>Maximum Exponent (E<sub>max</sub>)</td>
      <td>96</td>
      <td>384</td>
      <td>6144</td>
    </tr>

    <tr>
      <td>Minimum Exponent (E<sub>min</sub>)</td>
      <td>-95</td>
      <td>-383</td>
      <td>-6143</td>
    </tr>
  </tbody>
</table>
<h2>
3.2 32-bit Decimal type
</h2>
<h3>
3.2.1 Header <tt>&lt;dec32></tt> synopsis
</h3>
<pre>
      #include &lt;iosfwd>

      namespace std {
      namespace dfp {
        class decimal32;

        // <i>3.2.9 conversion to generic floating-point type:</i>
        long double decimal32_to_long_double(decimal32 d);
        long double decimal_to_long_double(const decimal32 &amp; d);

        // <i>3.2.10 unary arithmetic operators:</i>
        decimal32 operator+(const decimal32 &amp; lhs);
        decimal32 operator-(const decimal32 &amp; lhs);

        // <i>3.2.11 binary arithmetic operators:</i>
        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator+(const LHS &amp; lhs,
                                               const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator+(const decimal32 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator-(const LHS &amp; lhs,
                                               const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator-(const decimal32 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator*(const LHS &amp; lhs,
                                               const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator*(const decimal32 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator/(const LHS &amp; lhs,
                                               const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator/(const decimal32 &amp; lhs,
                                               const RHS &amp; rhs);

        // <i>3.2.12 comparison operators:</i>
        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator==(const LHS &amp; lhs,
                                                const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator==(const decimal32 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator!=(const LHS &amp; lhs,
                                                const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator!=(const decimal32 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator&lt;(const LHS &amp; lhs,
                                               const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator&lt;(const decimal32 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator&lt;=(const LHS &amp; lhs,
                                                const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator&lt;=(const decimal32 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator>(const LHS &amp; lhs,
                                               const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator>(const decimal32 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator>=(const LHS &amp; lhs,
                                                const decimal32 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator>=(const decimal32 &amp; lhs,
                                                const RHS &amp; rhs);

        // <i>3.2.13 Formatted input:</i>
        template &lt;class charT, class traits>
          std::basic_istream&lt;charT, traits> &amp;
            operator>>(std::basic_istream&lt;charT, traits> &amp; is, const decimal32 &amp; d);

        // <i>3.2.14 Formatted output:</i>
        template &lt;class charT, class traits>
          std::basic_ostream&lt;charT, traits> &amp;
            operator&lt;&lt;(std::basic_ostream&lt;charT, traits> &amp; os, const decimal32 &amp; d);
      }
      }

</pre>
<h3>
3.2.2 Class decimal32
</h3>
<pre>
      namespace std {
      namespace dfp {
        class decimal32 {
          public:
         
            // <i>3.2.3 construct/copy/destroy:</i>
            decimal32();
            decimal32(const decimal32 &amp; d32);
            decimal32 &amp; operator=(const decimal32 &amp; d32);
            ~decimal32();

            // <i>3.2.4 conversion from floating-point type:</i>
            explicit decimal32(const decimal64 &amp; d64);
            explicit decimal32(const decimal128 &amp; d128);
            explicit decimal32(float r);
            explicit decimal32(double r);
            explicit decimal32(long double r);

            // <i>3.2.5 conversion from integral type:</i>
            decimal32(int z);
            decimal32(unsigned int z);
            decimal32(long z);
            decimal32(unsigned long z);
            decimal32(long long z);
            decimal32(unsigned long long z);

            // <i>3.2.6 initialization from coefficient and exponent:</i>
            decimal32(long long coeff, int exponent);
            decimal32(unsigned long long coeff, int exponent);

            // <i>3.2.7 conversion to integral type:</i>
            operator long long() const;

            // <i>3.2.8 compound assignment:</i>
            template &lt;class T>
            /* <i>implementation-defined</i> */ operator+=(const T &amp; rhs);

            template &lt;class T>
            /* <i>implementation-defined</i> */ operator-=(const T &amp; rhs);

            template &lt;class T>
            /* <i>implementation-defined</i> */ operator*=(const T &amp; rhs);

            template &lt;class T>
            /* <i>implementation-defined</i> */ operator/=(const T &amp; rhs);
        };
      }
      }
</pre>
<h3>
3.2.3 Construct/copy/destroy
</h3>
<pre>
decimal32();
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal32 with the value 0;
</p>
</blockquote>
<pre>
decimal32(const decimal32 &amp; d32);
decimal32 &amp; operator=(const decimal32 &amp; d32);
</pre>
<blockquote>
<p>
<b>Effects:</b> Copies an object of type decimal32.
</p>
</blockquote>
<pre>
~decimal32();
</pre>
<blockquote>
<p>
<b>Effects:</b> Destroys an object of type decimal32.
</p>
</blockquote>
<h3>
3.2.4 Conversion from floating-point type
</h3>
<pre>
explicit decimal32(const decimal64 &amp; d64);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal32 by converting from type decimal64.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>
<pre>
explicit decimal32(const decimal128 &amp; d128);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal32 by converting from type decimal128.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>
<pre>
explicit decimal32(float r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal32 by converting from type <code>float</code>.  If <code>std::numeric_limits&lt;float>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<pre>
explicit decimal32(double r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal32 by converting from type <code>double</code>.  If <code>std::numeric_limits&lt;float>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<pre>
explicit decimal32(long double r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal32 by converting from type <code>long double</code>.  If <code>std::numeric_limits&lt;float>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<h3>
3.2.5 Conversion from integral type
</h3>
<pre>
decimal32(int z);
decimal32(unsigned int z);
decimal32(long z);
decimal32(unsigned long z);
decimal32(long long z);
decimal32(unsigned long long z);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal32 by converting from the type of <i>z</i>.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>
<h3>
3.2.6 Initialization from coefficient and exponent
</h3>
<pre>
decimal32(long long coeff, int exponent);
decimal32(unsigned long long coeff, int exponent);
</pre>
<blockquote>
<p>
<b>Effects:</b> If coeff x 10<sup>exponent</sup> is representable within the range of decimal32, constructs an object of type decimal32 with that value.  Otherwise, initializes the object with DEC_NAN [<i>3.7.1</i>].
</p>
</blockquote>
<p>
[<i>Editor's note:</i> An alternative design might throw a <code>std::range_error</code> exception in the error case.]
</p>
<h3>
3.2.7 Conversion to integral type
</h3>
<pre>
operator long long() const;
</pre>
<blockquote>
<p>
<b>Returns:</b> Returns the result of the conversion of <code>*this</code> to <code>long long</code>, performed as in IEEE-754R.
</p>
</blockquote>
<h3>
3.2.8 Compound assignment
</h3>
<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator+=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Adds <code>rhs</code> to <code>*this</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator-=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Subtracts <code>rhs</code> from <code>*this</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator*=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Multiplies <code>*this</code> by <code>rhs</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator/=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Divides <code>*this</code> by <code>rhs</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<h3>
3.2.9 Conversion to generic floating-point type
</h3>
<pre>
long double decimal32_to_long_double(decimal32 d);
long double decimal_to_long_double(const decimal32 &amp; d);
</pre>
<blockquote>
<p>
<b>Returns:</b> If <code>std::numeric_limits&lt;long double>::is_iec559 == true</code>, returns the result of the conversion of <code>*this</code> to <code>long double</code>, performed as in IEEE-754R.  Otherwise, the returned value is implementation-defined.
</p>
</blockquote>
<p>
[<i>Editor's note:</i> this notation is ugly.  A user-defined converson operator would be vastly preferable to these functions but, alas, user-defined conversion operators cannot be <code>explicit</code>.  A previous draft of this document specified a <code>decimal32</code> member function named <code>to_long_double()</code> that had the same result as these functions.  The current "free function" approach is better because it works regardless of whether the implementation of these types uses library classes or compiler builtins.  The <code>decimal32_to_long_double</code> form is provided for C programmers who want to write code that works equally well in C++.]
</p>
<h3>
3.2.10 Unary arithmetic operators
</h3>
<pre>
decimal32 operator+(const decimal32 &amp; lhs);
</pre>
<blockquote>
<p>
<b>Returns:</b> Adds <code>lhs</code> to <code>0</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>
<pre>
decimal32 operator-(const decimal32 &amp; lhs);
</pre>
<blockquote>
<p>
<b>Returns:</b> Subtracts <code>lhs</code> from <code>0</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<h3>
3.2.11 Binary arithmetic operators
</h3>
<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator+(const LHS &amp; lhs,
                                       const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Adds <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator+(const decimal32 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Adds <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator-(const LHS &amp; lhs,
                                       const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Subtracts <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator-(const decimal32 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Subtracts <code>rhs</code> from <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator*(const LHS &amp; lhs,
                                       const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Multiplies <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator*(const decimal32 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Multiplies <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator/(const LHS &amp; lhs,
                                       const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Divides <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator/(const decimal32 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Divides <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<h3>
3.2.12 Comparison operators
</h3>
<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator==(const LHS &amp; lhs,
                                        const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator==(const decimal32 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator!=(const LHS &amp; lhs,
                                        const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is not exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator!=(const decimal32 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is not exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator&lt;(const LHS &amp; lhs,
                                       const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator&lt;(const decimal32 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator&lt;=(const LHS &amp; lhs,
                                        const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than or equal to<code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator&lt;=(const decimal32 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than or equal to<code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator>(const LHS &amp; lhs,
                                       const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator>(const decimal32 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator>=(const LHS &amp; lhs,
                                        const decimal32 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than or equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator>=(const decimal32 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than or equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>


<h3>
3.2.13 Formatted input
</h3>
<pre>
template &lt;class charT, class traits>
  std::basic_istream&lt;charT, traits> &amp;
    operator>>(std::basic_istream&lt;charT, traits> &amp; is, const decimal32 &amp; d);
</pre>
<blockquote>
<p>
<b>Effects:</b>
This function constructs an object of class <code>std::basic_istream&lt;charT, traits>::sentry</code>.  If the <code>sentry</code> object returns <code>true</code> when converted to a value of type bool, input is extracted as if by the following code fragment:
</p>
<pre>
    typedef extended_num_get&lt;charT, std::istreambuf_iterator&lt;charT, traits> > extnumget;
    std::ios_base::iostate err = 0;
    std::use_facet&lt;extnumget>(is.getloc()).get(*this, 0, *this, err, d);
    setstate(err);
</pre>
<p>
If an exception is thrown during input then <code>std::ios::badbit</code> is set in the error state of the input stream <code>is</code>.  If <code>(is.exceptions() &amp; std::ios_base::badbit) != 0</code> then the exception is rethrown.  In any case, the formatted input function destroys the <code>sentry</code> object.
</p>
<p>
<b>Returns:</b> <code>is</code>.
</p>
</blockquote>
<h3>
3.2.14 Formatted output
</h3>
<pre>
template &lt;class charT, class traits>
  std::basic_ostream&lt;charT, traits> &amp;
    operator&lt;&lt;(std::basic_ostream&lt;charT, traits> &amp; os, const decimal32 &amp; d);
</pre>
<blockquote>
<p>
<b>Effects:</b>
This function constructs an object of class <code>std::basic_ostream&lt;charT, traits>::sentry</code>.  If the <code>sentry</code> object returns <code>true</code> when converted to a value of type bool, output is generated as if by the following code fragment:

</p>
<pre>
    typedef extended_num_put&lt;charT, std::ostreambuf_iterator&lt;charT, traits> > extnumput;
    bool failed =
      std::use_facet&lt;extnumput>(os.getloc()).put(*this, *this, os.fill(), d).failed();
    if (failed)
      { os.setstate(std::ios_base::failbit); }
</pre>
<p>
If an exception is thrown during output then <code>std::ios::badbit</code> is set in the error state of the input stream <code>os</code>.  If <code>(os.exceptions() &amp; std::ios_base::badbit) != 0</code> then the exception is rethrown.  In any case, the formatted output function destroys the <code>sentry</code> object.
</p>
<p>
<b>Returns:</b> <code>os</code>.
</p>
</blockquote>
<h3>
3.2.15 Addition to header &lt;limits>
</h3>
<p>
The standard template <tt>std::numeric_limits</tt> shall be specialized for the decimal32 type.
</p>
<p>
[<i>Example:</i>
</p>
<pre>
      namespace std {
        template&lt;> class numeric_limits&lt;dfp::decimal32> {
        public:
          static const bool is_specialized = true;

          static dfp::decimal32 min() throw() { return DEC32_MIN; }
          static dfp::decimal32 max() throw() { return DEC32_MAX; }

          static const int digits   = 7;
          static const int digits10 = digits; 

          static const bool is_signed  = true;
          static const bool is_integer = false;
          static const bool is_exact   = false;

          static const int radix = 10;
          static dfp::decimal32 epsilon()     throw() { return DEC32_EPSILON; }
          static dfp::decimal32 round_error() throw() { return ...; }

          static const int min_exponent   = -95;
          static const int min_exponent10 = min_exponent;
          static const int max_exponent   = 96;
          static const int max_exponent10 = max_exponent; 

          static const bool has_infinity             = true;
          static const bool has_quiet_NaN            = true;
          static const bool has_signaling_NaN        = true;
          static const float_denorm_style has_denorm = denorm_present;
          static const bool has_denorm_loss          = true;

          static dfp::decimal32 infinity()      throw() { return ...; }
          static dfp::decimal32 quiet_NaN()     throw() { return ...; }
          static dfp::decimal32 signaling_NaN() throw() { return ...; }
          static dfp::decimal32 denorm_min()    throw() { return DEC32_DEN; }

          static const bool is_iec559       = false;
          static const bool is_bounded      = true;
          static const bool is_modulo       = false;
          static const bool traps           = true;
          static const bool tinyness_before = true;

          static const float_round_style round_style = round_indeterminate;
        };
      }
</pre>
<p>
--<i>end example</i>]
</p>
<h2>
3.3 64-bit Decimal type
</h2>
<h3>
3.3.1 Header <tt>&lt;dec64></tt> synopsis
</h3>
<pre>
      #include &lt;iosfwd>

      namespace std {
      namespace dfp {
        class decimal64;

        // <i>3.3.9 conversion to generic floating-point type:</i>
        long double decimal64_to_long_double(decimal64 d);
        long double decimal_to_long_double(const decimal64 &amp; d);

        // <i>3.3.10 unary arithmetic operators:</i>
        decimal64 operator+(const decimal64 &amp; lhs);
        decimal64 operator-(const decimal64 &amp; lhs);

        // <i>3.3.11 binary arithmetic operators:</i>
        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator+(const LHS &amp; lhs,
                                               const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator+(const decimal64 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator-(const LHS &amp; lhs,
                                               const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator-(const decimal64 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator*(const LHS &amp; lhs,
                                               const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator*(const decimal64 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator/(const LHS &amp; lhs,
                                               const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator/(const decimal64 &amp; lhs,
                                               const RHS &amp; rhs);

        // <i>3.3.12 comparison operators:</i>
        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator==(const LHS &amp; lhs,
                                                const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator==(const decimal64 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator!=(const LHS &amp; lhs,
                                                const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator!=(const decimal64 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator&lt;(const LHS &amp; lhs,
                                               const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator&lt;(const decimal64 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator&lt;=(const LHS &amp; lhs,
                                                const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator&lt;=(const decimal64 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator>(const LHS &amp; lhs,
                                               const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator>(const decimal64 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator>=(const LHS &amp; lhs,
                                                const decimal64 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator>=(const decimal64 &amp; lhs,
                                                const RHS &amp; rhs);

        // <i>3.3.13 Formatted input</i>
        template &lt;class charT, class traits>
          std::basic_istream&lt;charT, traits> &amp;
            operator>>(std::basic_istream&lt;charT, traits> &amp; is, const decimal64 &amp; d);

        // <i>3.3.14 Formatted output</i>
        template &lt;class charT, class traits>
          std::basic_ostream&lt;charT, traits> &amp;
            operator&lt;&lt;(std::basic_ostream&lt;charT, traits> &amp; os, const decimal64 &amp; d);
      }
      }

</pre>
<h3>
3.3.2 Class decimal64
</h3>
<pre>
      namespace std {
      namespace dfp {
        class decimal64 {
          public:

            // <i>3.2.3 construct/copy/destroy:</i>
            decimal64();
            decimal64(const decimal64 &amp; d64);
            decimal64 &amp; operator=(const decimal64 &amp; d64);
            ~decimal64();

            // <i>3.3.4 conversion from floating-point type:</i>
            decimal64(const decimal32 &amp; d32);
            explicit decimal64(const decimal128 &amp; d128);
            explicit decimal64(float r);
            explicit decimal64(double r);
            explicit decimal64(long double r);

            // <i>3.3.5 conversion from integral type:</i>
            decimal64(int z);
            decimal64(unsigned int z);
            decimal64(long z);
            decimal64(unsigned long z);
            decimal64(long long z);
            decimal64(unsigned long long z);

            // <i>3.3.6 initialization from coefficient and exponent:</i>
            decimal64(long long coeff, int exponent);
            decimal64(unsigned long long coeff, int exponent);

            // <i>3.3.7 conversion to integral type:</i>
            operator long long() const;

            // <i>3.3.8 compound assignment:</i>
            template &lt;class T>
              /* <i>implementation-defined</i> */ operator+=(T rhs);

            template &lt;class T>
              /* <i>implementation-defined</i> */ operator-=(T rhs);

            template &lt;class T>
              /* <i>implementation-defined</i> */ operator*=(T rhs);

            template &lt;class T>
              /* <i>implementation-defined</i> */ operator/=(T rhs);
        };
      }
      }
</pre>
<h3>
3.3.3 Construct/copy/destroy
</h3>
<pre>
decimal64();
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal64 with the value 0;
</p>
</blockquote>
<pre>
decimal64(const decimal64 &amp; d64);
decimal64 &amp; operator=(const decimal64 &amp; d64);
</pre>
<blockquote>
<p>
<b>Effects:</b> Copies an object of type decimal64.
</p>
</blockquote>
<pre>
~decimal64();
</pre>
<blockquote>
<p>
<b>Effects:</b> Destroys an object of type decimal64.
</p>
</blockquote>
<h3>
3.3.4 Conversion from floating-point
</h3>
<pre>
decimal64(const decimal32 &amp; d32);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal64 by converting from type decimal32.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>
<pre>
explicit decimal64(const decimal128 &amp; d128);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal64 by converting from type decimal128.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>
<pre>
explicit decimal64(float r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal64 by converting from type <code>float</code>.  If <code>std::numeric_limits&lt;float>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<pre>
explicit decimal64(double r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal64 by converting from type <code>double</code>.  If <code>std::numeric_limits&lt;double>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<pre>
explicit decimal64(long double r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal64 by converting from type <code>long double</code>.  If <code>std::numeric_limits&lt;long double>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<h3>
3.3.5 Conversion from integral type
</h3>
<pre>
decimal64(int z);
decimal64(unsigned int z);
decimal64(long z);
decimal64(unsigned long z);
decimal64(long long z);
decimal64(unsigned long long z);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal64 by converting from the type of <i>z</i>.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>
<h3>
3.3.6 Initialization from coefficient and exponent
</h3>
<pre>
decimal64(long long coeff, int exponent);
decimal64(unsigned long long coeff, int exponent);
</pre>
<blockquote>
<p>
<b>Effects:</b> If coeff x 10<sup>exponent</sup> is representable within the range of decimal32, constructs an object of type decimal64 with that value.  Otherwise, initializes the object with DEC_NAN [<i>3.7.1</i>].
</p>
</blockquote>
<p>
[<i>Editor's note:</i> An alternative design might throw a <code>std::range_error</code> exception in the error case.]
</p>

<h3>
3.3.7 Conversion to integral type
</h3>
<pre>
operator long long() const;
</pre>
<blockquote>
<p>
<b>Returns:</b> Returns the result of the conversion of <code>*this</code> to <code>long long</code>, performed as in IEEE-754R.
</p>
</blockquote>

<h3>
3.3.8 Compound assignment
</h3>
<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator+=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Adds <code>rhs</code> to <code>*this</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator-=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Subtracts <code>rhs</code> from <code>*this</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator*=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Multiplies <code>*this</code> by <code>rhs</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator/=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Divides <code>*this</code> by <code>rhs</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<h3>
3.3.9 Conversion to generic floating-point type
</h3>
<pre>
long double decimal64_to_long_double(decimal64 d);
long double decimal_to_long_double(const decimal64 &amp; d);
</pre>
<blockquote>
<p>
<b>Returns:</b> If <code>std::numeric_limits&lt;long double>::is_iec559 == true</code>, returns the result of the conversion of <code>*this</code> to <code>long double</code>, performed as in IEEE-754R.  Otherwise, the returned value is implementation-defined.
</p>
</blockquote>
<p>
[<i>Editor's note:</i> this notation is ugly.  A user-defined converson operator would be vastly preferable to these functions but, alas, user-defined conversion operators cannot be <code>explicit</code>.  A previous draft of this document specified a <code>decimal64</code> member function named <code>to_long_double()</code> that had the same result as these functions.  The current "free function" approach is better because it works regardless of whether the implementation of these types uses library classes or compiler builtins.  The <code>decimal64_to_long_double</code> form is provided for C programmers who want to write code that works equally well in C++.]
</p>
<h3>
3.3.10 Unary arithmetic operators
</h3>
<pre>
decimal64 operator+(const decimal64 &amp; lhs);
</pre>
<blockquote>
<p>
<b>Returns:</b> Adds <code>lhs</code> to <code>0</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>
<pre>
decimal64 operator-(const decimal64 &amp; lhs);
</pre>
<blockquote>
<p>
<b>Returns:</b> Subtracts <code>lhs</code> from <code>0</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<h3>
3.3.11 Binary arithmetic operators
</h3>
<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator+(const LHS &amp; lhs,
                                       const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Adds <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator+(const decimal64 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Adds <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator-(const LHS &amp; lhs,
                                       const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Subtracts <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator-(const decimal64 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Subtracts <code>rhs</code> from <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator*(const LHS &amp; lhs,
                                       const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Multiplies <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator*(const decimal64 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Multiplies <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator/(const LHS &amp; lhs,
                                       const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Divides <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator/(const decimal64 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Divides <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<h3>
3.3.12 Comparison operators
</h3>
<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator==(const LHS &amp; lhs,
                                        const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator==(const decimal64 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator!=(const LHS &amp; lhs,
                                        const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is not exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator!=(const decimal64 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is not exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator&lt;(const LHS &amp; lhs,
                                       const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator&lt;(const decimal64 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator&lt;=(const LHS &amp; lhs,
                                        const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than or equal to<code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator&lt;=(const decimal64 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than or equal to<code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator>(const LHS &amp; lhs,
                                       const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator>(const decimal64 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator>=(const LHS &amp; lhs,
                                        const decimal64 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than or equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator>=(const decimal64 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than or equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>


<h3>
3.3.13 Formatted input
</h3>
<pre>
template &lt;class charT, class traits>
  std::basic_istream&lt;charT, traits> &amp;
    operator>>(std::basic_istream&lt;charT, traits> &amp; is, const decimal64 &amp; d);
</pre>
<blockquote>
<p>
<b>Effects:</b>
This function constructs an object of class <code>std::basic_istream&lt;charT, traits>::sentry</code>.  If the <code>sentry</code> object returns <code>true</code> when converted to a value of type bool, input is extracted as if by the following code fragment:
</p>
<pre>
    typedef extended_num_get&lt;charT, std::istreambuf_iterator&lt;charT, traits> > extnumget;
    std::ios_base::iostate err = 0;
    std::use_facet&lt;extnumget>(is.getloc()).get(*this, 0, *this, err, d);
    setstate(err);
</pre>
<p>
If an exception is thrown during input then <code>std::ios::badbit</code> is set in the error state of the input stream <code>is</code>.  If <code>(is.exceptions() &amp; std::ios_base::badbit) != 0</code> then the exception is rethrown.  In any case, the formatted input function destroys the <code>sentry</code> object.
</p>
<p>
<b>Returns:</b> <code>is</code>.
</p>
</blockquote>
<h3>
3.3.14 Formatted output
</h3>
<pre>
template &lt;class charT, class traits>
  std::basic_ostream&lt;charT, traits> &amp;
    operator&lt;&lt;(std::basic_ostream&lt;charT, traits> &amp; os, const decimal64 &amp; d);
</pre>
<blockquote>
<p>
<b>Effects:</b>
This function constructs an object of class <code>std::basic_ostream&lt;charT, traits>::sentry</code>.  If the <code>sentry</code> object returns <code>true</code> when converted to a value of type bool, output is generated as if by the following code fragment:

</p>
<pre>
    typedef extended_num_put&lt;charT, std::ostreambuf_iterator&lt;charT, traits> > extnumput;
    bool failed =
      std::use_facet&lt;extnumput>(os.getloc()).put(*this, *this, os.fill(), d).failed();
    if (failed)
      { os.setstate(std::ios_base::failbit); }
</pre>
<p>
If an exception is thrown during output then <code>std::ios::badbit</code> is set in the error state of the input stream <code>os</code>.  If <code>(os.exceptions() &amp; std::ios_base::badbit) != 0</code> then the exception is rethrown.  In any case, the formatted output function destroys the <code>sentry</code> object.
</p>
<p>
<b>Returns:</b> <code>os</code>.
</p>
</blockquote>
<h3>
3.3.15 Addition to header &lt;limits>
</h3>
<p>
The standard template <tt>std::numeric_limits</tt> shall be specialized for the decimal64 type.
</p>
<p>
[<i>Example:</i>
</p>
<pre>
      namespace std {
        template&lt;> class numeric_limits&lt;dfp::decimal64> {
        public:
          static const bool is_specialized = true;

          static dfp::decimal64 min() throw() { return DEC64_MIN; }
          static dfp::decimal64 max() throw() { return DEC64_MAX; }

          static const int digits      = 16;
          static const int digits10    = digits; 

          static const bool is_signed  = true;
          static const bool is_integer = false;
          static const bool is_exact   = false;

          static const int radix = 10;
          static dfp::decimal64 epsilon()     throw() { return DEC64_EPSILON; }
          static dfp::decimal64 round_error() throw() { return ...; }

          static const int min_exponent   = -383;
          static const int min_exponent10 = min_exponent;
          static const int max_exponent   = 384;
          static const int max_exponent10 = max_exponent; 

          static const bool has_infinity             = true;
          static const bool has_quiet_NaN            = true;
          static const bool has_signaling_NaN        = true;
          static const float_denorm_style has_denorm = denorm_present;
          static const bool has_denorm_loss          = true;

          static dfp::decimal64 infinity()      throw() { return ...; }
          static dfp::decimal64 quiet_NaN()     throw() { return ...; }
          static dfp::decimal64 signaling_NaN() throw() { return ...; }
          static dfp::decimal64 denorm_min()    throw() { return DEC64_DEN; }

          static const bool is_iec559       = false;
          static const bool is_bounded      = true;
          static const bool is_modulo       = false;
          static const bool traps           = true;
          static const bool tinyness_before = true;

          static const float_round_style round_style = round_indeterminate;
        };
      }
</pre>
<p>
--<i>end example</i>]
</p>
<h2>
3.4 128-bit Decimal type
</h2>
<h3>
3.4.1 Header <tt>&lt;dec128></tt> synopsis
</h3>
<pre>
      #include &lt;iosfwd>

      namespace std {
      namespace dfp {
        class decimal128;

        // <i>3.4.9 conversion functions:</i>
        long double decimal128_to_long_double(decimal128 d);
        long double decimal_to_long_double(const decimal128 &amp; d);

        // <i>3.4.10 unary arithmetic operators:</i>
        decimal128 operator+(const decimal128 &amp; lhs);
        decimal128 operator-(const decimal128 &amp; lhs);

        // <i>3.4.11 binary arithmetic operators:</i>
        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator+(const LHS &amp; lhs,
                                               const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator+(const decimal128 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator-(const LHS &amp; lhs,
                                               const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator-(const decimal128 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator*(const LHS &amp; lhs,
                                               const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator*(const decimal128 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator/(const LHS &amp; lhs,
                                               const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator/(const decimal128 &amp; lhs,
                                               const RHS &amp; rhs);

        // <i>3.4.12 comparison operators:</i>
        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator==(const LHS &amp; lhs,
                                                const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator==(const decimal128 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator!=(const LHS &amp; lhs,
                                                const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator!=(const decimal128 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator&lt;(const LHS &amp; lhs,
                                               const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator&lt;(const decimal128 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator&lt;=(const LHS &amp; lhs,
                                                const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator&lt;=(const decimal128 &amp; lhs,
                                                const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator>(const LHS &amp; lhs,
                                               const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator>(const decimal128 &amp; lhs,
                                               const RHS &amp; rhs);

        template &lt;class LHS>
        /* <i>implementation-defined</i> */ operator>=(const LHS &amp; lhs,
                                                const decimal128 &amp; rhs);

        template &lt;class RHS>
        /* <i>implementation-defined</i> */ operator>=(const decimal128 &amp; lhs,
                                                const RHS &amp; rhs);

        // <i>3.4.13 Formatted input</i>
        template &lt;class charT, class traits>
          std::basic_istream&lt;charT, traits> &amp;
            operator>>(std::basic_istream&lt;charT, traits> &amp; is, const decimal128 &amp; d);

        // <i>3.4.14 Formatted output</i>
        template &lt;class charT, class traits>
          std::basic_ostream&lt;charT, traits> &amp;
            operator&lt;&lt;(std::basic_ostream&lt;charT, traits> &amp; os, const decimal128 &amp; d);
      }
      }
</pre>
<h3>
3.4.2 Class decimal128
</h3>
<pre>
      namespace std {
      namespace dfp {
        class decimal128 {
          public:

            // <i>3.4.3 construct/copy/destroy:</i>
            decimal128();
            decimal128(const decimal128 &amp; d128);
            decimal128 &amp; operator=(const decimal128 &amp; d128);
            ~decimal128();

            // <i>3.4.4 conversion from floating-point type:</i> 
            decimal128(const decimal32 &amp; d32);
            decimal128(const decimal64 &amp; d64);
            explicit decimal128(float r);
            explicit decimal128(double r);
            explicit decimal128(long double r);

            // <i>3.4.5 conversion from integral type:</i> 
            decimal128(int z);
            decimal128(unsigned int z);
            decimal128(long z);
            decimal128(unsigned long z);
            decimal128(long long z);
            decimal128(unsigned long long z);

            // <i>3.4.6 initialization from coefficient and exponent:</i> 
            decimal128(long long coeff, int exponent);
            decimal128(unsigned long long coeff, int exponent);

            // <i>3.4.7 conversion to integral type:</i> 
            operator long long() const;

            // <i>3.4.8 compound assignment:</i> 
            template &lt;class T>
              /* <i>implementation-defined</i> */ operator+=(T rhs);

            template &lt;class T>
              /* <i>implementation-defined</i> */ operator-=(T rhs);

            template &lt;class T>
              /* <i>implementation-defined</i> */ operator*=(T rhs);

            template &lt;class T>
              /* <i>implementation-defined</i> */ operator/=(T rhs);
        };
      }
      }
</pre>
<h3>
3.4.3 Construct/copy/destroy
</h3>
<pre>
decimal128();
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal128 with the value 0;
</p>
</blockquote>
<pre>
decimal128(const decimal128 &amp; d128);
decimal128 &amp; operator=(const decimal128 &amp; d128);
</pre>
<blockquote>
<p>
<b>Effects:</b> Copies an object of type decimal128.
</p>
</blockquote>
<pre>
~decimal128();
</pre>
<blockquote>
<p>
<b>Effects:</b> Destroys an object of type decimal128.
</p>
</blockquote>
<h3>
3.4.4 Conversion from floating-point type
</h3>

<pre>
decimal128(const decimal32 &amp; d32);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal32 by converting from type decimal32.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>
<pre>
decimal128(const decimal64 &amp; d64);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal128 by converting from type decimal64.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>

<pre>
explicit decimal128(float r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal128 by converting from type <code>float</code>.  If <code>std::numeric_limits&lt;float>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<pre>
explicit decimal128(double r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal128 by converting from type <code>double</code>.  If <code>std::numeric_limits&lt;float>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<pre>
explicit decimal128(long double r);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal128 by converting from type <code>long double</code>.  If <code>std::numeric_limits&lt;float>::is_iec559 == true</code> then the conversion is performed as in IEEE-754R.  Otherwise, the result of the conversion is implementation-defined.
</p>
</blockquote>
<h3>
3.4.5 Conversion from integral type
</h3>
<pre>
decimal128(int z);
decimal128(unsigned int z);
decimal128(long z);
decimal128(unsigned long z);
decimal128(long long z);
decimal128(unsigned long long z);
</pre>
<blockquote>
<p>
<b>Effects:</b> Constructs an object of type decimal128 by converting from the type of <i>z</i>.  Conversion is performed as in IEEE-754R.
</p>
</blockquote>

<h3>
3.4.6 Initialization from coefficient and exponent
</h3>
<pre>
decimal128(long long coeff, int exponent);
decimal128(unsigned long long coeff, int exponent);
</pre>
<blockquote>
<p>
<b>Effects:</b> If coeff x 10<sup>exponent</sup> is representable within the range of decimal128, constructs an object of type decimal128 with that value.  Otherwise, initializes the object with DEC_NAN [<i>3.7.1</i>].
</p>
</blockquote>
<p>
[<i>Editor's note:</i> An alternative design might throw a <code>std::range_error</code> exception in the error case.]
</p>

<h3>
3.4.7 Conversion to integral type
</h3>
<pre>
operator long long() const;
</pre>
<blockquote>
<p>
<b>Returns:</b> Returns the result of the conversion of <code>*this</code> to <code>long long</code>, performed as in IEEE-754R.
</p>
</blockquote>

<h3>
3.4.8 Compound assignment
</h3>
<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator+=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Adds <code>rhs</code> to <code>*this</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator-=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Subtracts <code>rhs</code> from <code>*this</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator*=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Multiplies <code>*this</code> by <code>rhs</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<pre>
template &lt;class T>
/* <i>implementation-defined</i> */ operator/=(const T &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>T</code> is one of the integral types, or one of the decimal floating-point types.
<br/>
<b>Effects:</b> Divides <code>*this</code> by <code>rhs</code>, as in IEEE-754R, and assigns the result to <code>*this</code>.
<br/>
<b>Returns:</b> <code>*this</code> 
</p>
</blockquote>

<h3>
3.4.9 Conversion to generic floating-point type
</h3>
<pre>
long double decimal128_to_long_double(decimal128 d);
long double decimal_to_long_double(const decimal128 &amp; d);
</pre>
<blockquote>
<p>
<b>Returns:</b> If <code>std::numeric_limits&lt;long double>::is_iec559 == true</code>, returns the result of the conversion of <code>*this</code> to <code>long double</code>, performed as in IEEE-754R.  Otherwise, the returned value is implementation-defined.
</p>
</blockquote>
<p>
[<i>Editor's note:</i> this notation is ugly.  A user-defined converson operator would be vastly preferable to these functions but, alas, user-defined conversion operators cannot be <code>explicit</code>.  A previous draft of this document specified a <code>decimal128</code> member function named <code>to_long_double()</code> that had the same result as these functions.  The current "free function" approach is better because it works regardless of whether the implementation of these types uses library classes or compiler builtins.  The <code>decimal128_to_long_double</code> form is provided for C programmers who want to write code that works equally well in C++.]
</p>

<h3>
3.4.10 Unary arithmetic operators
</h3>
<pre>
decimal128 operator+(const decimal128 &amp; lhs);
</pre>
<blockquote>
<p>
<b>Returns:</b> Adds <code>lhs</code> to <code>0</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>
<pre>
decimal128 operator-(const decimal128 &amp; lhs);
</pre>
<blockquote>
<p>
<b>Returns:</b> Subtracts <code>lhs</code> from <code>0</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>
<h3>

3.4.11 Binary arithmetic operators
</h3>
<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator+(const LHS &amp; lhs,
                                       const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Adds <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator+(const decimal128 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Adds <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator-(const LHS &amp; lhs,
                                       const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Subtracts <code>rhs</code> to <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator-(const decimal128 &amp; lhs,
                                       const RHS &amp; rhs);

</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Subtracts <code>rhs</code> from <code>lhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator*(const LHS &amp; lhs,
                                       const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Multiplies <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator*(const decimal128 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Multiplies <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator/(const LHS &amp; lhs,
                                       const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> Divides <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator/(const decimal128 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> Divides <code>lhs</code> by <code>rhs</code>, as in IEEE-754R, and returns the result.
</p>
</blockquote>

<h3>
3.4.12 Comparison operators
</h3>
<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator==(const LHS &amp; lhs,
                                        const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator==(const decimal128 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator!=(const LHS &amp; lhs,
                                        const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is not exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator!=(const decimal128 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is not exactly equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator&lt;(const LHS &amp; lhs,
                                       const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.

<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator&lt;(const decimal128 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>

template &lt;class LHS>
/* <i>implementation-defined</i> */ operator&lt;=(const LHS &amp; lhs,
                                        const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than or equal to<code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator&lt;=(const decimal128 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is less than or equal to<code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator>(const LHS &amp; lhs,
                                       const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator>(const decimal128 &amp; lhs,
                                       const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class LHS>
/* <i>implementation-defined</i> */ operator>=(const LHS &amp; lhs,
                                        const decimal128 &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>LHS</code> is one of the integral types
or one of the decimal floating-point types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than or equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<pre>
template &lt;class RHS>
/* <i>implementation-defined</i> */ operator>=(const decimal128 &amp; lhs,
                                        const RHS &amp; rhs);
</pre>
<blockquote>
<p>
<b>Constraints:</b> <code>RHS</code> is one of the integral types.
<br/>
<b>Returns:</b> <code>true</code> if <code>lhs</code> is greater than or equal to <code>rhs</code> according to IEEE-754R, <code>false</code> otherwise.
</p>
</blockquote>

<h3>
3.4.13 Formatted input
</h3>
<pre>
template &lt;class charT, class traits>
  std::basic_istream&lt;charT, traits> &amp;
    operator>>(std::basic_istream&lt;charT, traits> &amp; is, const decimal128 &amp; d);
</pre>
<blockquote>
<p>
<b>Effects:</b>
This function constructs an object of class <code>std::basic_istream&lt;charT, traits>::sentry</code>.  If the <code>sentry</code> object returns <code>true</code> when converted to a value of type bool, input is extracted as if by the following code fragment:
</p>
<pre>
    typedef extended_num_get&lt;charT, std::istreambuf_iterator&lt;charT, traits> > extnumget;
    std::ios_base::iostate err = 0;
    std::use_facet&lt;extnumget>(is.getloc()).get(*this, 0, *this, err, d);
    setstate(err);
</pre>
<p>
If an exception is thrown during input then <code>std::ios::badbit</code> is set in the error state of the input stream <code>is</code>.  If <code>(is.exceptions() &amp; std::ios_base::badbit) != 0</code> then the exception is rethrown.  In any case, the formatted input function destroys the <code>sentry</code> object.
</p>
<p>
<b>Returns:</b> <code>is</code>.
</p>
</blockquote>
<h3>
3.4.14 Formatted output
</h3>
<pre>
template &lt;class charT, class traits>
  std::basic_ostream&lt;charT, traits> &amp;
    operator&lt;&lt;(std::basic_ostream&lt;charT, traits> &amp; os, const decimal128 &amp; d);
</pre>
<blockquote>
<p>
<b>Effects:</b>
This function constructs an object of class <code>std::basic_ostream&lt;charT, traits>::sentry</code>.  If the <code>sentry</code> object returns <code>true</code> when converted to a value of type bool, output is generated as if by the following code fragment:

</p>
<pre>
    typedef extended_num_put&lt;charT, std::ostreambuf_iterator&lt;charT, traits> > extnumput;
    bool failed =
      std::use_facet&lt;extnumput>(os.getloc()).put(*this, *this, os.fill(), d).failed();
    if (failed)
      { os.setstate(std::ios_base::failbit); }
</pre>
<p>
If an exception is thrown during output then <code>std::ios::badbit</code> is set in the error state of the input stream <code>os</code>.  If <code>(os.exceptions() &amp; std::ios_base::badbit) != 0</code> then the exception is rethrown.  In any case, the formatted output function destroys the <code>sentry</code> object.
</p>
<p>
<b>Returns:</b> <code>os</code>.
</p>
</blockquote>
<h3>
3.4.15 Addition to header &lt;limits>
</h3>
<p>
The standard template <tt>std::numeric_limits</tt> shall be specialized for the decimal128 type.
</p>
<p>
[<i>Example:</i>
</p>
<pre>
      namespace std {
        template&lt;> class numeric_limits&lt;dfp::decimal128> {
        public:
          static const bool is_specialized = true;

          static dfp::decimal128 min() throw() { return DEC128_MIN; }
          static dfp::decimal128 max() throw() { return DEC128_MIN; }

          static const int digits   = 384;
          static const int digits10 = digits; 

          static const bool is_signed  = true;
          static const bool is_integer = false;
          static const bool is_exact   = false;

          static const int radix = 10;
          static dfp::decimal128 epsilon()     throw() { return DEC128_EPSILON; }
          static dfp::decimal128 round_error() throw() { return ...; }

          static const int min_exponent   = -6143;
          static const int min_exponent10 = min_exponent;
          static const int max_exponent   = 6144;
          static const int max_exponent10 = max_exponent; 

          static const bool has_infinity             = true;
          static const bool has_quiet_NaN            = true;
          static const bool has_signaling_NaN        = true;
          static const float_denorm_style has_denorm = denorm_present;
          static const bool has_denorm_loss          = true;

          static dfp::decimal128 infinity()      throw() { return ...; }
          static dfp::decimal128 quiet_NaN()     throw() { return ...; }
          static dfp::decimal128 signaling_NaN() throw() { return ...; }
          static dfp::decimal128 denorm_min()    throw() { return DEC128_DEN; }

          static const bool is_iec559       = false;
          static const bool is_bounded      = true;
          static const bool is_modulo       = false;
          static const bool traps           = true;
          static const bool tinyness_before = true;

          static const float_round_style round_style = round_indeterminate;
        };
      }
</pre>
<p>
--<i>end example</i>]
</p>
<h2>
3.5 Headers &lt;cdecfloat> and &lt;decfloat.h>
</h2>
<p>
The standard C++ headers &lt;cfloat> and &lt;float.h> define characteristics of the floating-point types float, double, and long double.  Their contents remain unchanged by this Technical Report.
</p>
<p>
Headers &lt;cdecfloat> and &lt;decfloat.h> define characteristics of the decimal floating-point types decimal32, decimal64, and decimal128.  As well, &lt;decfloat.h> defines the convenience typedefs _Decimal32, _Decimal64, and _Decimal128, for compatibilty with the C programming language.
</p>
<h3>
3.5.1 Header &lt;cdecfloat> synopsis
</h3>
<pre>
      #include &lt;dec32>
      #include &lt;dec64>
      #include &lt;dec128>

      // <i>number of digits in the coefficient:</i>
      #define DEC32_MANT_DIG  7
      #define DEC64_MANT_DIG 16
      #define DEC64_MANT_DIG 34

      // <i>minimum exponent:</i>
      #define DEC32_MIN_EXP    -95
      #define DEC64_MIN_EXP   -383
      #define DEC128_MIN_EXP -6143

      // <i>maximum exponent:</i>
      #define DEC32_MIN_EXP    96
      #define DEC64_MIN_EXP   384
      #define DEC128_MIN_EXP 6144

      // <i>3.5.3 maximum finite value:</i>
      #define DEC32_MAX  /* implementation-defined */
      #define DEC64_MAX  /* implementation-defined */
      #define DEC128_MAX /* implementation-defined */

      // <i>3.5.4 epsilon:</i>
      #define DEC32_EPSILON  /* implementation-defined */
      #define DEC64_EPSILON  /* implementation-defined */
      #define DEC128_EPSILON /* implementation-defined */

      // <i>3.5.5 minimum positive normal value:</i>
      #define DEC32_MIN  /* implementation-defined */
      #define DEC64_MIN  /* implementation-defined */
      #define DEC128_MIN /* implementation-defined */

      // <i>3.5.6 minimum positive subnormal value:</i>
      #define DEC32_DEN  /* implementation-defined */
      #define DEC64_DEN  /* implementation-defined */
      #define DEC128_DEN /* implementation-defined */
      
</pre>
<h3>
3.5.2 Header &lt;decfloat.h> synopsis
</h3>
<pre>
      #include &lt;cdecfloat>

      // <i>C-compatibility convenience typedefs:</i>
      typedef dfp::decimal32  _Decimal32;
      typedef dfp::decimal64  _Decimal64;
      typedef dfp::decimal128 _Decimal128;
</pre>
<p>
</p>
<h3>
3.5.3 Maximum finite value
</h3>
<p>
<code>#define DEC32_MAX  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal32 equal to the maximum finite number that can be represented by an object of type decimal32; exactly equal to 9.999999 x 10<sup>96</sup> (there are six 9's after the decimal point)
</p>
</blockquote>
<p>
<code>#define DEC64_MAX  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal64 equal to the maximum finite number that can be represented by an object of type decimal64; exactly equal to 9.999999999999999 x 10<sup>384</sup> (there are fifteen 9's after the decimal point)
</p>
</blockquote>
<p>
<code>#define DEC128_MAX /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal128 equal to the maximum finite number that can be represented by an object of type decimal128; exactly equal to 9.999999999999999999999999999999999 x 10<sup>6144</sup> (there are thirty-three 9's after the decimal point)
</p>
</blockquote>
<h3>
3.5.4 Epsilon 
</h3>
<p>
<code>#define DEC32_EPSILON  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal32 equal to the difference between 1 and the least value greater than 1 that can be represented by an object of type decimal32; exactly equal to 1 x 10<sup>-6</sup>
</p>
</blockquote>
<p>
<code>#define DEC64_EPSILON  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal64 equal to the difference between 1 and the least value greater than 1 that can be represented by an object of type decimal32; exactly equal to 1 x 10<sup>-15</sup>
</p>
</blockquote>
<p>
<code>#define DEC128_EPSILON /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal128 equal to the difference between 1 and the least value greater than 1 that can be represented by an object of type decimal128; exactly equal to 1 x 10<sup>-33</sup>
</p>
</blockquote>
<h3>
3.5.5 Minimum positive normal value
</h3>
<p>
<code>#define DEC32_MIN  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal32 equal to the minimum positive normal number that can be represented by an object of type decimal32; exactly equal to 1 x 10<sup>-95</sup>
</p>
</blockquote>
<p>
<code>#define DEC64_MIN  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal64 equal to the minimum positive normal number that can be represented by an object of type decimal64; exactly equal to 1 x 10<sup>-383</sup>
</p>
</blockquote>
<p>
<code>#define DEC128_MIN /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal128 equal to the minimum positive normal number that can be represented by an object of type decimal128; exactly equal to 1 x 10<sup>-6143</sup>
</p>
</blockquote>
<h3>
3.5.6 Minimum positive subnormal value
</h3>
<p>
<code>#define DEC32_DEN  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal32 equal to the minimum positive finite number that can be represented by an object of type decimal32; exactly equal to 1 x 10<sup>-101</sup>
</p>
</blockquote>
<p>
<code>#define DEC64_DEN  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal64 equal to the minimum positive finite number that can be represented by an object of type decimal64; exactly equal to 1 x 10<sup>-398</sup>
</p>
</blockquote>
<p>
<code>#define DEC128_DEN /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal128 equal to the minimum positive finite number that can be represented by an object of type decimal128; exactly equal to 1 x 10<sup>-6176</sup>
</p>
</blockquote>
<h2>
3.6 Additions to &lt;cfenv> and &lt;fenv.h>
</h2>
<p>
The header &lt;cfenv> is described in [tr.c99.cfenv].  The header &lt;fenv.h> is described in [tr.c99.fenv].
</p>
<h3>
3.6.1 Rounding modes
</h3>
<p>
The following macros are added to &lt;cfenv> and &lt;fenv.h>:
</p>
<pre>
      FE_DEC_DOWNWARD
      FE_DEC_TONEAREST
      FE_DEC_TONEARESTFROMZERO
      FE_DEC_TOWARD_ZERO
      FE_DEC_UPWARD
</pre>
<p>
These macros are used by the <tt>fegetround</tt> and <tt>fesetround</tt> functions for getting and setting the rounding mode to be used in decimal floating-point operations.
</p>
<h2>
3.7 Additions to &lt;cmath> and &lt;math.h>
</h2>
<p>
The elementary mathematical functions declared in the standard C++ header &lt;cmath> are overloaded by this Technical Report to support the decimal floating-point types.  The macros <tt>HUGE_VAL_D32</tt>, <tt>HUGE_VAL_D64</tt>, <tt>HUGE_VAL_D128</tt>, <tt>DEC_INFINITY</tt>, and <tt>DEC_NAN</tt> are defined for use with these functions.  With the exception of <tt>sqrt</tt>, <tt>fmax</tt>, and <tt>fmin</tt>, the accuracy of the result of a call to one of these functions is implementation-defined.  The implementation may state that the accuracy is unknown.  The classification macros <tt>FP_NAN</tt>, <tt>FP_INFINITE</tt>, <tt>FP_NORMAL</tt>, <tt>FP_SUBNORMAL</tt>, and <tt>FP_ZERO</tt> and the comparison macros <tt>isgreater</tt>, <tt>isgreaterequal</tt>, <tt>isless</tt>, <tt>islessequal</tt>, <tt>islessgreater</tt>, and <tt>isunordered</tt> are also extended to handle the decimal floating-point types.
</p>
<h3>
3.7.1 Additions to header &lt;cmath> synopsis
</h3>
<pre>

      // <i>3.7.2</i> macros:
      #define HUGE_VAL_D32  /* implementation-defined */
      #define HUGE_VAL_D64  /* implementation-defined */
      #define HUGE_VAL_D128 /* implementation-defined */
      #define DEC_INFINITY  /* implementation-defined */
      #define DEC_NAN       /* implementation-defined */
     
      namespace std {
      namespace dfp {
        // <i>3.7.3</i> samequantum functions:
        bool samequantum     (decimal32 x,  decimal32 y);
        bool samequantumd32  (decimal32 x,  decimal32 y);

        bool samequantum     (decimal64 x,  decimal64 y);
        bool samequantumd64  (decimal64 x,  decimal64 y);

        bool samequantum     (decimal128 x, decimal128 y);
        bool samequantumd128 (decimal128 x, decimal128 y);

        // <i>3.7.4</i> quantize functions:
        decimal32  quantize     (decimal32 x,  decimal32 y);
        decimal32  quantized32  (decimal32 x,  decimal32 y);

        decimal64  quantize     (decimal64 x,  decimal64 y);
        decimal64  quantized64  (decimal64 x,  decimal64 y);

        decimal128 quantize     (decimal128 x, decimal128 y);
        decimal128 quantized128 (decimal128 x, decimal128 y);

        // <i>3.7.5</i> elementary functions:
        // [<i>Editor's note:</i> to be added.]
      } 
      }
</pre>
<h3>
3.7.2 &lt;cmath> macros
</h3>
<p>
<code>#define HUGE_VAL_D32  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> a positive lvalue of type decimal32.
</p>
</blockquote>
<p>
<code>#define HUGE_VAL_D64  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> a positive lvalue of type decimal64, not necessarily representable as a decimal32.
</p>
</blockquote>
<p>
<code>#define HUGE_VAL_128  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> a positive lvalue of type decimal128, not necessarily representable as a decimal64.
</p>
</blockquote>
<p>
<code>#define DEC_INFINITY  /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal32 representing infinity.
</p>
</blockquote>
<p>
<code>#define DEC_NAN      /* implementation-defined */</code>
</p>
<blockquote>
<p>
<b>Expansion:</b> an lvalue of type decimal32 representing quiet NaN.
</p>
</blockquote>
<h3>
3.7.3 <code>samequantum</code> functions
</h3>
<pre>
bool samequantum     (decimal32 x, decimal32 y);
</pre>
<blockquote>
<p>
<b>Effects:</b> behaves as in IEEE-754R.
</p>
</blockquote>
<pre>
bool samequantumd32  (decimal32 x, decimal32 y);
</pre>
<blockquote>
<p>
<b>Returns:</b> samequantum(x, y)
</p>
</blockquote>
<pre>
bool samequantum     (decimal64 x, decimal64 y);
</pre>
<blockquote>
<p>
<b>Effects:</b> behaves as in IEEE-754R.
</p>
</blockquote>
<pre>
bool samequantumd64  (decimal64 x, decimal64 y);
</pre>
<blockquote>
<p>
<b>Returns:</b> samequantum(x, y)
</p>
</blockquote>
<pre>
bool samequantum     (decimal128 x, decimal128 y);
</pre>
<blockquote>
<p>
<b>Effects:</b> behaves as in IEEE-754R.
</p>
</blockquote>
<pre>
bool samequantumd128 (decimal128 x, decimal128 y);
</pre>
<blockquote>
<p>
<b>Returns:</b> samequantum(x, y)
</p>
</blockquote>
<h3>
3.7.4 <code>quantize</code> functions
</h3>
<pre>
bool quantize     (decimal32 x, decimal32 y);
</pre>
<blockquote>
<p>
<b>Effects:</b> behaves as in IEEE-754R.
</p>
</blockquote>
<pre>
bool quantized32  (decimal32 x, decimal32 y);
</pre>
<blockquote>
<p>
<b>Returns:</b> quantize(x, y)
</p>
</blockquote>
<pre>
bool quantize     (decimal64 x, decimal64 y);
</pre>
<blockquote>
<p>
<b>Effects:</b> behaves as in IEEE-754R.
</p>
</blockquote>
<pre>
bool quantized64  (decimal64 x, decimal64 y);
</pre>
<blockquote>
<p>
<b>Returns:</b> quantize(x, y)
</p>
</blockquote>
<pre>
bool quantize     (decimal128 x, decimal128 y);
</pre>
<blockquote>
<p>
<b>Effects:</b> behaves as in IEEE-754R.
</p>
</blockquote>
<pre>
bool quantized128 (decimal128 x, decimal128 y);
</pre>
<blockquote>
<p>
<b>Returns:</b> quantize(x, y)
</p>
</blockquote>
<h3>
3.7.5 Elementary functions
</h3> 
<p>
[<i>Editor's note:</i> text for this section will be taken from the corresponding C TR.]
</p>
<h3>
3.7.6 Changes to &lt;math.h> 
</h3> 
<p>
Each name placed into the namespace <code>dfp</code> by &lt;cmath> is placed into both the namespace <code>dfp</code> and the global namespace by &lt;math.h>.  Macros added to &lt;cmath> by this Technical Report are transitively added to &lt;math.h>.
</p>
<h2>
3.8 Additions to &lt;cstdlib> and &lt;stdlib.h>
</h2>
<h3>
3.8.1 Additions to header &lt;cstdlib> synopsis
</h3>
<pre>
      namespace std {
      namespace dfp {
        // <i>3.8.2</i> strtod functions
        decimal32  strtod32  (const char * nptr, char ** endptr);
        decimal64  strtod64  (const char * nptr, char ** endptr);
        decimal128 strtod128 (const char * nptr, char ** endptr);
      }
      }
</pre>
<h3>
3.8.2 <code>strtod</code> functions
</h3>
<p>
[<i>Editor's note:</i> text for this section will be taken from the corresponding C TR.]
</p>
<h3>
3.8.3 Changes to &lt;stdlib.h> 
</h3> 
<p>
Each name placed into the namespace <code>dfp</code> by &lt;cstdlib> is placed into both the namespace <code>dfp</code> and the global namespace by &lt;stdlib.h>.
</p>
<h2>
3.9 Additions to &lt;cwchar> and &lt;wchar.h>
</h2>
<h3>
3.9.1 Additions to &lt;cwchar> synopsis
</h3>
<pre>
      namespace std {
      namespace dfp {
        // <i>3.9.2</i> wcstod functions
        decimal32  wcstod32  (const char * nptr, char ** endptr);
        decimal64  wcstod64  (const char * nptr, char ** endptr);
        decimal128 wcstod128 (const char * nptr, char ** endptr);
      }
      }
</pre>
<h3>
3.9.2 <code>wcstod</code> functions
</h3>
<p>
[<i>Editor's note:</i> text for this section will be taken from the corresponding C TR.]
</p>
<h3>
3.9.3 Changes to &lt;wchar.h> 
</h3> 
<p>
Each name placed into the namespace <code>dfp</code> by &lt;cwchar> is placed into both the namespace <code>dfp</code> and the global namespace by &lt;wchar.h>.
</p>

<h2>
3.10 Facets 
</h2>
<p>
This TR introduces the locale facet templates <code>extended_num_get</code> and <code>extended_num_put</code>.  For any locale <code><i>loc</i></code> either constructed, or returned by <code>locale::classic()</code>, and any facet <code><i>Facet</i></code> that is one of the required instantiations indicated in Table 2, <code>std::has_facet&lt;<i>Facet</i>>(<i>loc</i>)</code> is <code>true</code>.  Each <code>std::locale</code> member function that has a parameter <code><i>cat</i></code> of type <code>std::locale::category</code> operates on the these facets when <code><i>cat</i> &amp; std::locale::numeric != 0</code>.
</p>
<h4>Table 2 -- Extended Category Facets</h4>
<table border="1">
<tr>
<td>
Category
</td>
<td>
Facets
</td>
</tr>
<tr>
<td>
<code>numeric</code>
</td>
<td>
<code>extended_num_get&lt;char></code>, <code>extended_num_get&lt;wchar_t></code><br />
<code>extended_num_put&lt;char></code>, <code>extended_num_put&lt;wchar_t></code>
</td>
</tr>
</table>

<h3>
3.10.1 Additions to header &lt;locale> synopsis
</h3>
<pre>
  namespace std {
  namespace dfp {

    // <i>3.10.2 extended_num_get facet:</i>
    template &lt;class charT, class InputIterator>  class extended_num_get;

    // <i>3.10.3 extended_num_put facet:</i>
    template &lt;class charT, class OutputIterator> class extended_num_put;
  }
  }
</pre>
<h3>
3.10.2 Class template <code>extended_num_get</code>
</h3>
<pre>
  namespace std {
  namespace dfp {
    template &lt;class charT, class InputIterator = std::istreambuf_iterator&lt;charT, std::char_traits&lt;charT> > >
    class extended_num_get : public std::num_get&lt;charT, InputIterator> {
    public:

      typedef charT char_type;
      typedef InputIterator iter_type;

      explicit extended_num_get(size_t <i>refs</i> = 0);

      iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal32 &amp; <i>val</i>) const;
      iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal64 &amp; <i>val</i>) const;
      iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal128 &amp; <i>val</i>) const;

    protected:
      ~extended_num_get();             // <i>virtual</i>
      virtual iter_type do_get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal32 &amp; <i>val</i>) const;
      virtual iter_type do_get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal64 &amp; <i>val</i>) const;
      virtual iter_type do_get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal128 &amp; <i>val</i>) const;
    };
  }
  }
</pre>
<h3>
3.10.2.1 <code>extended_num_get</code> members
</h3>
<pre>
      iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal32 &amp; <i>val</i>) const;
      iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal64 &amp; <i>val</i>) const;
      iter_type get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal128 &amp; <i>val</i>) const;
</pre>
<blockquote>
<p>
<b>Returns:</b> <code>do_get(<i>in</i>, <i>end</i>, <i>str</i>, <i>err</i>, <i>val</i>)</code>.
</p>
</blockquote>
<h3>
3.10.2.2 <code>extended_num_get</code> virtual functions 
</h3>
<pre>
      iter_type do_get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal32 &amp; <i>val</i>) const;
      iter_type do_get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal64 &amp; <i>val</i>) const;
      iter_type do_get(iter_type <i>in</i>, iter_type <i>end</i>, std::ios_base &amp; <i>str</i>,
                  std::ios_base::iostate &amp; <i>err</i>, const decimal128 &amp; <i>val</i>) const;
</pre>
<blockquote>
<p>
<b>Effects:</b> The input characters will be interpreted as described in [lib.facet.num.get.virtuals], and the resulting value will be stored in <i>val</i>.  For conversions to type decimal32, decimal64, and decimal128, the conversion specifiers are <code>%gHD</code>, <code>%gD</code>, and <code>%gLD</code>, respectively.
</p>
<p>
<b>Returns:</b> <i>in</i>.
</p>
</blockquote>

<h3>
3.10.3 Class template <code>extended_num_put</code>
</h3>
<pre>
  namespace std {
  namespace dfp {
    template &lt;class charT, class OutputIterator = std::ostreambuf_iterator&lt;charT, std::char_traits&lt;charT> > >
    class extended_num_put : public std::num_put&lt;charT, OutputIterator> {
    public:

      typedef charT char_type;
      typedef OutputIterator iter_type;

      explicit extended_num_put(size_t <i>refs</i> = 0);

      iter_type put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal32 &amp; <i>val</i>) const;
      iter_type put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal64 &amp; <i>val</i>) const;
      iter_type put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal128 &amp; <i>val</i>) const;

    protected:
      ~extended_num_put();             // <i>virtual</i>
      virtual iter_type do_put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal32 &amp; <i>val</i>) const;
      virtual iter_type do_put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal64 &amp; <i>val</i>) const;
      virtual iter_type do_put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal128 &amp; <i>val</i>) const;
    };
  }
  }
</pre>
<h3>
3.10.3.1 <code>extended_num_put</code> members
</h3>
<pre>
      iter_type put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal32 &amp; <i>val</i>) const;
      iter_type put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal64 &amp; <i>val</i>) const;
      iter_type put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal128 &amp; <i>val</i>) const;
</pre>
<blockquote>
<p>
<b>Returns:</b> <code>do_put(<i>s</i>, <i>f</i>, <i>fill</i>, <i>val</i>)</code>.
</p>
</blockquote>
<h3>
3.10.3.2 <code>extended_num_put</code> virtual functions 
</h3>
<pre>
      virtual iter_type do_put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal32 &amp; <i>val</i>) const;
      virtual iter_type do_put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal64 &amp; <i>val</i>) const;
      virtual iter_type do_put(iter_type <i>s</i>, ios_base &amp; <i>f</i>, char_type <i>fill</i>, const decimal128 &amp; <i>val</i>) const;
</pre>
<blockquote>
<p>
<b>Effects:</b> The number represented by <i>val</i> will be formatted for output as described in [lib.facet.num.put.virtuals].  A length modifier is added to the conversion specifier as indicated in Table 3.
</p>

<h4>
Table 3 -- Length modifier
</h4>
<table border="1">
<tr>
<th>
type
</th>
<th>
length modifier
</th>
</tr>
<tr>
<td>
decimal32
</td>
<td>
HD
</td>
</tr>
<tr>
<td>
decimal64
</td>
<td>
D
</td>
</tr>
<tr>
<td>
decimal128
</td>
<td>
LD
</td>
</tr>
</table>

<p>
<b>Returns:</b> <i>out</i>.
</p>
</blockquote>

<h2>
3.11 Type traits
</h2>
<p>
The effect of the following type traits, when applied to any of the decimal floating-point types, is implementation-defined: 
</p>
<ul>
<li><code>std::tr1::is_arithmetic</code></li>
<li><code>std::tr1::is_fundamental</code></li>
<li><code>std::tr1::is_scalar</code></li>
<li><code>std::tr1::is_class</code></li>
</ul>
<p>
However, the following expression shall yield <code>true</code> where <i>dec</i> is one of <code>decimal32</code>, <code>decimal64</code>, or <code>decimal128</code>:
</p>
<pre>
  is_arithmetic&lt;<i>dec</i>>::value == is_fundamental&lt;<i>dec</i>>::value == is_scalar&lt;<i>dec</i>>::value == !is_class&lt;<i>dec</i>>::value
</pre>
<p>
[<em>Note:</em> The behavior of the type trait <code>std::tr1::is_floating_point</code> is not altered by this Technical report. <em>--end note</em>]
</p>

<h3>
3.11.1 Addition to header &lt;type_traits> synopsis
</h3>
<pre>
      namespace std {
      namespace dfp {
        // <i>3.11.2 is_decimal_floating_point type_trait:</i>
        template &lt;class T> struct is_decimal_floating_point; 
      }
      }
</pre>
<h3>
3.11.2 <code>is_decimal_floating_point</code> type_trait
</h3>
<p>
[<i>Editor's note:</i> an earlier draft of this document used the name <code>is_decimal_fp</code> for this type_trait.  Though it's longer, the current name was adopted for consistency with the TR1 <code>is_floating_point</code> type_trait.]
</p>
<p>
<code>is_decimal_floating_point</code> is a <i>UnaryTypeTrait</i> [tr.meta.rqmts] and satisfies all of the requirements of that category [tr.meta.requirements].
</p>

<h4>Table 4 -- Type Category Predicates</h4>
<table border="1">
<tr>
<th>
Template
</th>
<th>
Condition
</th>
<th>
Comments
</th>
</tr>
<tr>
<td>
<code>template &lt;class T><br/>struct is_decimal_floating_point;</code>
</td>
<td>
<code>T</code> is one of <code>decimal32</code>, <code>decimal64</code>, or <code>decimal128</code>
</td>
<td>
</td>
</tr>
</table>
<h2>
3.12 Hash functions
</h2>
<h3>
3.12.1 Addition to header &lt;functional> synopsis
</h3>
<pre>
      namespace std {
      namespace tr1 {
        // <i>Hash function specializations</i>
        template &lt;> struct hash&lt;dfp::decimal32>;
        template &lt;> struct hash&lt;dfp::decimal64>;
        template &lt;> struct hash&lt;dfp::decimal128>;
      }
      }
</pre>
<h3>
3.12.2 Hash function specializations
</h3>
<p>
In addition to the types indicated in [tr.unord.hash], the class template <code>hash</code> is required to be instantiable on the decimal floating-point types.
</p>
<h2>
4 Notes on C compatibility
</h2>
<p>
One of the goals of the design of the decimal floating-point types that are the subject of this Technical Report is to minimize incompatibility with the C decimal floating types; however, differences between the C and C++ languages make some incompatibilty inevitable.  Differences between the C and C++ decimal types -- and techniques for overcoming them -- are described in this section.
</p>
<h2>
4.1 Use of &lt;decfloat.h>
</h2>
<p>
To aid portability to C++, it is recommended that C programmers <tt>#include</tt> the header file &lt;decfloat.h> in those translation units that make use of the decimal floating types.  This ensures that the equivalent C++ floating-point types will be available, should the program source be ported to C++. 
</p>
<h2>
4.2 Literals
</h2>
<p>
Literals of decimal floating-point type are not introduced to the C++ language by this Technical Report, though implementations may support them as a conforming extension.  C programs that use decimal floating-point literals will not be portable to a C++ implementation that does not support this extension.
</p>
<p>
Each of the C++ decimal floating-point types has constructors that permit initialization from a pair of integrals representing a coefficient and an exponent.  These constructors permit the result of an initialization to be an exact decimal value, and may be considered an alternative to initialization from decimal literals.
</p>
<p>
[<i>Editor's note:</i> these constructors are problematic for two reasons.  First, they're not available in C, so they represent an obstacle to portability.  Second, they're not free functions, so they preclude the implementation of the decimal floating-point types as builtins.  This requires discussion.]
</p>
<p>
[<i>Editor's note:</i> this draft still doesn't specify convenience functions for initializing objects of decimal floating-point type from strings.  They will appear in the next draft.]
</p>
<h2>
4.3 Conversions
</h2>
<p>
In C, objects of decimal floating-point type can be converted to generic floating-point type by means of an explicit cast.  In C++ this is not possible.  Instead, the functions <code>decimal_to_long_double</code>, <code>decimal32_to_long_double</code>, <code>decimal64_to_long_double</code>, and <code>decimal128_to_long_double</code> should be used for this purpose.  C programmers who wish to maintain portability to C++ should use the <code>decimal32_to_long_double</code>, <code>decimal64_to_long_double</code>, and <code>decimal128_to_long_double</code> forms instead of the cast notation.
</p>
<p>
{<i>Editor's note:</i> there's another issue that I believe requires further discussion.  Currently, decimal values that are within the range of an <code>unsigned long long</code> but not within the range of a <code>long long</code> cannot be accurately converted to integral type in C++, though accurate conversion is possible in C.]
</p>
</body>
</html>
