This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with scanf reading long types in scientific notation

I¹m not sure if this has been dealt with or not, but I happen to be thinking
about it at the moment and wanted to say something before I forget.
There is as situation in which I believe an improvement is needed:
Regarding all the scanf functions reading long values
(sscanf,fscanf,scanf,... etc...).
Currently, if a number is written in scientific notation (as will be the
default case sometimes for large whole numbers that might happen to be
stored in double types), scanf won¹t properly read it¹s value into a long
data type. For example:
if I want to read the number
1.5892938475E10, 1.5892938475e10, 1.5892938475E+10, or 1.5892938475e+10
scanf(³%ld²,&longValue) ;will not read any of the later cases correctly. I
imagine the same to be true for int types.
Currently, what I have to do is:
I don¹t think I should have to write my own functions to deal with this type
of standard read of plain old data, so whether it¹s a bug or just a feature
request is semantics.
The introduction of 64-bit systems after everything was developed for 32-bit
systems has caused one set of issues. This may be related to that, but it
also might be seen as a preference for large whole numbers to be more be
more easily stored and converted between long and double values. Maybe the
desire for this has come out of dealing with large numbers available in
64-bit systems. 
In my opinion, it should be changed so that scanf(³%ld²,&longValue) behaves
as scanf(³%lf²,&doubleValue);longValue=doubleValue;, specifically to improve
the reading of scientific numbers. It is entirely possible to have a large
whole number written in scientific notation. I feel that this issue has
caused bugs in many of my programs, so it should be fixed in order that
others in the future can have confidence in the functionality of
scanf(³%ld²,&longValue) working correctly in all cases where there is a
number to be read. I propose that it be set up this way for all versions of
*scanf type functions. I don¹t know if literally using the double reading
algorithm and then assigning to a long or int value is the best approach or
if there is a better way, but I think the functionality should be
implemented in the future.
Sean McGuffee

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]