From: Kbwms AT aol DOT com Message-ID: <16e.2264c067.2c67fe7c@aol.com> Date: Sun, 10 Aug 2003 16:01:00 EDT Subject: Re: Anomaly in printf() To: djgpp-workers AT delorie DOT com MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="part1_16e.2264c067.2c67fe7c_boundary" X-Mailer: 8.0 for Windows sub 6011 Reply-To: djgpp-workers AT delorie DOT com --part1_16e.2264c067.2c67fe7c_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit In a message dated 8/10/2003 3:30:30 PM Eastern Standard Time, eliz AT elta DOT co DOT il writes: > >Date: Sun, 10 Aug 2003 14:17:13 -0400 > >From: DJ Delorie > > > >>Behold: > >> > >>Demo = 18446744073709551615.000 > >>Demo - 1 = 18446744073709551613.000 > > > >Ok, that's a bug. > > Is it? We are printing a long double, which IIRC has 19 significant > digits. The ``error'' here happens in the 20th digit, unless I'm > mistaken. > Below is what C99 has to say. Since DJGPP/GCC supports 64-bit precision, my assumption is that we should produce 21 digits. As the footnote says, If the minimum-width IEC 60559 extended format (64 bits of precision) is supported, DECIMAL_DIG shall be at least 21. F.4 Floating to integer conversion [#1] If the floating value is infinite or NaN or if the integral part of the floating value exceeds the range of the integer type, then the invalid exception is raised and the resulting value is unspecified. Whether conversion of non- integer floating values whose integral part is within the range of the integer type raises the inexact exception is unspecified.288) F.5 Binary-decimal conversion [#1] Conversion from the widest supported IEC 60559 format to decimal with DECIMAL_DIG digits and back is the identity function.289) [#2] Conversions involving IEC 60559 formats follow all pertinent recommended practice. In particular, conversion between any supported IEC 60559 format and decimal with DECIMAL_DIG or fewer significant digits is correctly rounded. | ____________________ 288ANSI/IEEE 854, but not IEC 60559 (ANSI/IEEE 754), directly specifies that floating-to-integer conversions raise the inexact exception for non-integer in-range values. In those cases where it matters, library functions can be used to effect such conversions with or without raising the inexact exception. See rint, lrint, llrint, and nearbyint in . 289If the minimum-width IEC 60559 extended format (64 bits of precision) is supported, DECIMAL_DIG shall be at least 21. If IEC 60559 double (53 bits of precision) is the widest IEC 60559 format supported, then DECIMAL_DIG shall be at least 17. (By contrast, LDBL_DIG and DBL_DIG are 19 and 15, respectively, for these formats.) --part1_16e.2264c067.2c67fe7c_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable In a message dated 8/10/2003 3:30:30 PM Eastern Standard= Time, eliz AT elta DOT co DOT il writes:

>Date: Sun, 10 Aug 2003 14:17:13 -0400
>From: DJ Delorie <dj AT delorie DOT com>
>
>>Behold:
>>
>>Demo    =3D 18446744073709551615.000
>>Demo - 1 =3D 18446744073709551613.000
>
>Ok, that's a bug.

Is it?  We are printing a long double, which IIRC has 19 significant digits.  The ``error'' here happens in the 20th digit, unless I'm
mistaken.


Below is what C99 has to say.  Since DJGPP/GCC supports 64-bit precisio= n, my assumption is that we should produce 21 digits.  As the footnote=20= says,

       If the minimum-width IEC 60559 extended= format  (64  bits
       of precision) is supported, DECIMAL_DIG= shall be at least 21. 


       F.4  Floating to integer conversio= n

       [#1] If the floating value is infinite&= nbsp; or  NaN  or  if  the
       integral part of the floating value exc= eeds the range of the
       integer type, then the invalid exceptio= n is raised  and  the
       resulting  value is unspecified.&n= bsp; Whether conversion of non-
       integer floating values whose integral=20= part  is  within  the
       range  of  the  integer=20= type raises the inexact exception is
       unspecified.288)

       F.5  Binary-decimal conversion

       [#1] Conversion from the widest support= ed IEC  60559  format
       to  decimal with DECIMAL_DIG digit= s and back is the identity
       function.289)

       [#2]  Conversions  involving&= nbsp; IEC  60559  formats follow all
       pertinent recommended practice.  I= n  particular,  conversion
       between  any  supported = IEC  60559  format and decimal with
       DECIMAL_DIG  or  fewer =20= significant  digits   is   correctly
       rounded.     &= nbsp;            = ;            &nb= sp;            &= nbsp;         |

       ____________________

       288ANSI/IEEE  854,  but = not  IEC  60559  (ANSI/IEEE   754),
          directly  specif= ies  that floating-to-integer conversions
          raise the  inexa= ct  exception  for  non-integer  in-range
          values.  &n= bsp; In  those  cases  where  it  matters,  li= brary
          functions can be used= to effect such conversions with  or
          without  raising= the inexact exception.  See rint, lrint,
          llrint, and nearbyint= in <math.h>.

       289If the minimum-width IEC 60559 exten= ded format  (64  bits
          of precision) is supp= orted, DECIMAL_DIG shall be at least
          21.  If IEC 6055= 9 double (53 bits of  precision)  is  the
          widest IEC 60559 form= at supported, then DECIMAL_DIG shall
          be at least 17. = (By contrast, LDBL_DIG and  DBL_DIG  are
          19 and 15, respective= ly, for these formats.)

--part1_16e.2264c067.2c67fe7c_boundary--