CustomFloat
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Oct 16 21:30:33 PDT 2008
I found myself in need for smaller and specialized floating point types,
where I configure the exact configuration (sign, mantissa, exponent,
bias). See http://en.wikipedia.org/wiki/Half_precision for a half
precision number slated for inclusion in IEEE 754r.
Would it be interesting to add a CustomFloat template to phobos? I'm
thinking along the lines of:
template CustomFloat!(bool sign, uint mantissa,
uint exponent, uint bias)
{
...
}
So half-precision numbers are:
alias CustomFloat!(true, 5, 10, 15) HalfFloat;
There are quite a few details to kink out but this is definitely doable.
Numbers like 24-bit floating point and even 8-bit floating point would
be easy to support too. For now CustomFloat would be intended
exclusively as a compact storage mechanism; only conversion to the
standard floating points would be implemented. Later, maybe we can get
to implement some operations natively at least on machines that support
them in hardware. I wanted to gauge interest in the topic.
Andrei
More information about the Digitalmars-d
mailing list