CustomFloat

Bill Baxter wbaxter at gmail.com
Thu Oct 16 21:44:47 PDT 2008


On Fri, Oct 17, 2008 at 1:30 PM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> 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.
>


In theory it would be great to have this in Phobos.  I say in theory
because I haven't actually been in need of such a thing recently, but
it is definitely handy to have if you're working with high dynamic
range images (like from openEXR), or doing other GPU-related things.
Is that the kind of thing you need them for too?  I've heard of using
anything beyond 16-bit and 24-bit floats in the GPU/HDR world, though.
 A full generic solution is probably overkill for that.

--bb



More information about the Digitalmars-d mailing list