public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/303] New: scanf into single rounds in 2.3.3 (truncates in 2.3.1)
@ 2004-08-06  4:06 d dot bullivant at auckland dot ac dot nz
  2004-08-06  7:41 ` [Bug libc/303] " jakub at redhat dot com
  0 siblings, 1 reply; 2+ messages in thread
From: d dot bullivant at auckland dot ac dot nz @ 2004-08-06  4:06 UTC (permalink / raw)
  To: glibc-bugs

When reading into a single with %f, scanf now rounds (2.3.3) whereas it used to
truncate (2.3.1) - see program below.

Could you please confirm that this is an intentional change.

*******************************************************************************
FILE : scanf_double.c

LAST MODIFIED : 5 August 2004

DESCRIPTION:
Code for testing reading doubles into singles.

BUILD:
gcc scanf_double.c -o scanf_double

OUTPUT:
glibc-2.3.1
single 5 7e2fe
double 5 7e2fe81f74638
difference 1.93664e-06

glibc-2.3.3
single 5 7e2ff
double 5 7e2fe81f74638
difference -1.87805e-06
==============================================================================*/

#include <ieee754.h>

main(int argc,char **argv)
{
        char *string_double="0.3397167399474852E+02";
        double d;
        float f;
        union ieee754_double *d_ptr;
        union ieee754_float *f_ptr;

        d_ptr=(union ieee754_double *)&d;
        f_ptr=(union ieee754_float *)&f;
        sscanf(string_double,"%f",&f);
        sscanf(string_double,"%lf",&d);
        printf("single %lx
%lx\n",(f_ptr->ieee).exponent-127,(f_ptr->ieee).mantissa);
        printf("double %lx %llx\n",(d_ptr->ieee).exponent-1023,
                ((long long unsigned)((d_ptr->ieee).mantissa0)*0x100000000ll+
                (long long unsigned)((d_ptr->ieee).mantissa1))*0x8ll);
        printf("difference %g\n",d-(double)f);
}

-- 
           Summary: scanf into single rounds in 2.3.3 (truncates in 2.3.1)
           Product: glibc
           Version: 2.3.3
            Status: NEW
          Severity: minor
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: d dot bullivant at auckland dot ac dot nz
                CC: glibc-bugs at sources dot redhat dot com


http://sources.redhat.com/bugzilla/show_bug.cgi?id=303

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libc/303] scanf into single rounds in 2.3.3 (truncates in 2.3.1)
  2004-08-06  4:06 [Bug libc/303] New: scanf into single rounds in 2.3.3 (truncates in 2.3.1) d dot bullivant at auckland dot ac dot nz
@ 2004-08-06  7:41 ` jakub at redhat dot com
  0 siblings, 0 replies; 2+ messages in thread
From: jakub at redhat dot com @ 2004-08-06  7:41 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From jakub at redhat dot com  2004-08-06 07:41 -------
Yeah, it is an intentional change (fix).
2003-02-19  Ulrich Drepper  <drepper@redhat.com>

        * stdlib/strtod.c (INTERNAL): Up the safety margin for cutting off
        decimal input digits.
        * stdlib/tst-strtod.c (main): Add test for strtof bug.

strtof (and scanf which uses it internally) was always rounding, but in some
cases it incorrectly computed the number of digits it needs to fetch so that it
is properly rounded.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://sources.redhat.com/bugzilla/show_bug.cgi?id=303

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-08-06  7:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-06  4:06 [Bug libc/303] New: scanf into single rounds in 2.3.3 (truncates in 2.3.1) d dot bullivant at auckland dot ac dot nz
2004-08-06  7:41 ` [Bug libc/303] " jakub at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).