[RFC] do_get of floats vs underflow

Paolo Carlini pcarlini@suse.de
Fri Apr 6 13:37:00 GMT 2007


Hi,

due to way we are currently implementing these facilities, we have a
failure in case of floating point underflow: thus no value assigned,
failbit.

I never considered this behavior in detail, until libstdc++/31117, which
noticed that in general any errno usage is thread-unsafe (it is known to 
be ok on linux and darwin).

Since, according to the standard, the behavior of num_get is "as-if"
scanf, not "as-if" strtof, and scanf certainly doesn't fail in any sense
in case of floating point underflow (at least this is what I'm seeing on
linux), I would guess we could just avoid checking whether errno ==
ERANGE, don't fiddle at all with errno, and instead just check that the
value returned by strtof is != HUGE_VAL && != -HUGE_VAL.

Or dot we have reasons to believe people are relying (uncorrectly) on
failbit being set in case of underflow? When evaluating this issue, we 
should also consider that, according to C99, 7.20.1.3/10, about strtof & 
co, in case of underflow "whether errno acquires the value ERANGE is is 
implementation-defined". Thus, I would say I do not consider the latter 
expectation very reasonable, in general.

Thanks in advance for any feedback,
Paolo.

PS: before someone asks, this issue really is orthogonal to +inf, -inf,
etc. parsing, currently considered for C++0x. Any such input sequence
would be detected and treated separately.



More information about the Libstdc++ mailing list