Re: [RFA] convert_doublest_to_floatformat: handle off-range values.

Joel Brobecker
2012-06-14T00:51:02Z

> + if (exponent + fmt->exp_bias <= 0)
> + {
> + /* The value is too small to be expressed in the destination
> + type (not enough bits in the exponent. Treat as 0. */
> + put_field (uto, order, fmt->totalsize, fmt->exp_start,
> + fmt->exp_len, 0);
> + put_field (uto, order, fmt->totalsize, fmt->man_start,
> + fmt->man_len, 0);
> + goto finalize_byteorder;
> + }

For these small numbers, we could do like libiberty, and generate
denormalized numbers, like so:

if (exponent + fmt->exp_bias - 1 > 0)
put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
fmt->exp_len, exponent + fmt->exp_bias - 1);
else
{
/* Handle a denormalized number. FIXME: What should we do for
non-IEEE formats? */
put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
fmt->exp_len, 0);
mant = ldexp (mant, exponent + fmt->exp_bias - 1);
}

But it'd be a larger change, because we'd have to write a portable
version of ldexp that works for "long double". Actually, we could
import ldexp and ldexpl.

We should probably also consider the import of frexp and frexpl
as well. It'd allow us to get rid of our own implementation.

--
Joel