This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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]

RE: strtold?


I took a quick look last night at the source for _strtold in ldtoa.c,
and it seems to be sub-par in several respects.  (I have not actually
run it to test it.)  _strtold() ends up calling asctoeg(), to which
all of these issues apply.  Among the problems (if I've read it
correctly):
1)  It only skips leading spaces (not space as checked by isspace())
2)  It does not support hex
3)  It appears to ignore 'z' in the middle of a number
4)  It does not have errno handling (as Corinna noticed)
 
So, yes it is incompatible with C and POSIX in total.  Therefore,
_strtold does not seem to be suitable for promotion to the real strtold
in its present form, and is not even good enough for use in scanf, for
that matter; it needs enhancement even just for scanf.
 
Corinna's having noticed the error returns not being C/POSIX actually
raises an issue with trying to have scanf call the real strtold.  That
is that scanf is not supposed to return errors (set errno) for reading
infinities, etc.  If we were to share later, we'd need some kind of
wrapper to avoid errno when called from the scan functions but to
set errno when used as strtold.
 
There's also a cryptic footnote in the C standard for fscanf() that says
"fscanf pushes back at most one input character onto the input stream.
Therefore, some sequences that are acceptable to strtod, strtol, etc.,
are unacceptable to fscanf."  It does not elaborate.
 
Craig
 

-----Original Message-----
From: newlib-owner@sourceware.org [mailto:newlib-owner@sourceware.org]
On Behalf Of Corinna Vinschen
Sent: Sunday, March 22, 2009 1:02 PM
To: newlib@sourceware.org
Subject: Re: long double (was "strtold?")

On Mar 16 18:44, Jeff Johnston wrote:
> Howland Craig D (Craig) wrote:
>> ...
>> functions to the math library.  (I hadn't stumbled across ldtoa.c,
yet,
>> ...  
> Regarding why strtold isn't exposed.: there was a reason, but I can't

> for the life of me
> remember.  It may no longer be relevant.  I'll keep pondering.

Is it possible that this implementation of strtold suffers
incompatibility
with POSIX?  Per POSIX this function is supposed to set errno to ERANGE
if an overflow occurs, plus returning the values HUGE_VALL or
-HUGE_VALL.
In case of an underflow, ERANGE has to be returned as well.  I don't see
that this function actually behaves that way.


Corinna

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


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