More instantiation problems under hpux

John David Anglin dave@hiauly1.hia.nrc.ca
Thu Jan 17 09:05:00 GMT 2002


> Inf, will the expression (value > FLT_MAX, DBL_MAX, LDBL_MAX)
> (ignore that I will really use the C++ capture of those values
> since they have already taken pains to handle the problem
> of which C header has the right value, etc)
> 
> compute as expected?  Here is one concrete example:
> 
> double __d = Inf; // Inf is a place holder for any way to create an Inf
> 
> bool __b = (__d > DBL_MAX) || (__d < -DBL_MAX); // Must handle -Inf, which
>                                                 // is supported by IEEE
>                                                 // and others (?)
> 
> Is __b true for all FP implementations that you know about?

No.  It is not true on VAX.  As I said, the hardware doesn't support
either Inf or nans.  There are no double values larger than
HUGE/HUGE_VAL/DBL_MAX.  However, for floats you can take advantage of
the fact that the range for doubles is greater than that for floats to
see if the double result returned by strtod is representable as a float.

This should work on the vax to determine if there was an
overflow or underflow in converting the string __s to a float __f:

#include <float.h>
double __d = strtod (__s, __sanity);
float __f = __d;
bool __err = errno || (d > 0. ? ((__d > FLT_MAX) || (__d < FLT_MIN))
			      : ((__d < -FLT_MAX) || (__d > -FLT_MIN));

Note floats and D-format doubles only differ in the number of bits
in the fraction.  Thus, they have nearly identical ranges and it would
be rare for a double to be outside the range of a D-format float.
D-format doubles are the default.

G-format doubles have less precision and a much wider range of values.
The range for G-format doubles is quite similar to ieee doubles.  Thus,
if a program used G-format doubles, there would be a much greater
likelihood of double being outside the float range.  Thus, the second
part of the above check is important for G-format doubles.

For double string conversion, just use strtod and check errno.

> My current patch uses finitef, if available and finite otherwise.
> Does hpux have finitef and/or finite ?

It has both.

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