More instantiation problems under hpux

John David Anglin dave@hiauly1.hia.nrc.ca
Wed Jan 16 21:18:00 GMT 2002


> 633     #else
> 634           float __f = static_cast<float>(strtod(__xtrc.c_str(), &__sanity));
> 635     #endif
> 636           if (!(__err & ios_base::failbit)
> 637               && __sanity != __xtrc.c_str() && *__sanity == '\0' && errno == 0)

Looks like a problem alright.

> I am afraid that it is not correct to check errno == 0 in order to
> declare a non-Inf value in __f since the return value from strtod must
> fit in a double not a float.  The cast to a float might

Yup.

> truncate/convert to Inf.  That conversion doesn't set errno on
> overflow (according to my understanding and seen behavior).

Depending on the architecture, the conversion might cause an exception
which if caught could set errno.  However, this is not simple because
in some cases exceptions don't occur immediately.

> Since it is checked for by configure, I don't think the fix is to
> simply use isinf() to check __f.  Also, I'm guessing that people that
> have strtof would prefer this fix inside the #else section, right?
> BTW, for you "all the world is a VAX" fans or anti-fans, from isinf(3)
> on my platform: "Neither the VAX nor the Tahoe floating point have
> distinguished values for either infinity or not-a-number.  These
> routines always return 0 on those architectures."  Thus, the check
> against overflow might need to be more complex for some architectures
> to get this absolutely portable...

The functions isinf and isnan don't exist on the VAX because the floating
point hardware doesn't support the special values values inf and nan.
The function strtod returns HUGE (-HUGE) if the conversion would overflow,
or 0 is the conversion would underflow.  HUGE is the same as HUGE_VAL
unless you muck with _POSIX_SOURCE.  errno is set to ERANGE if the correct
value is outside the range of values that can be represented.  I
probably can find info about the rounding/truncation when doubles are
converted to floats.

HPUX has isinf and isnan.  The function strtod behaves similarly to
the VAX ultrix function.

I'm thinking that in the float case, the result would be ok if the
double obtained from strtod is in the range [FLT_MIN, FLT_MAX] when
positive.  Similarly, negative values should be in the range
[-FLT_MAX, -FLT_MIN].  The comparisons are possible because
FLT_MIN > DBL_MIN and FLT_MAX < DBL_MAX.  Don't know if this is
true for all FP hardware but it should work for ieee and vax.
You have to get these values from float.h.  There are some silly
values for FLT_MIN and DBL_MIN in limits.h on vax ultrix.

In the double case, errno should be set and things should be ok on
most architectures.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)



More information about the Libstdc++ mailing list