digitalmars.D - Re: CustomFloat
Andrei Alexandrescu 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. Andrei
I've done some work on a set of decimal floating point numbers consistent with the new 754r decimal formats approved in June. Some of that work would be applicable here, I think. It would probably make sense to add the decimal formats at the same time. Let me know if I can help. Paul
Oct 17 2008
Paul D. Anderson Wrote:Andrei Alexandrescu 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. Andrei
I've done some work on a set of decimal floating point numbers consistent with the new 754r decimal formats approved in June. Some of that work would be applicable here, I think. It would probably make sense to add the decimal formats at the same time. Let me know if I can help. Paul
Here's a link to info regarding the decimal formats: http://speleotrove.com/decimal/
Oct 17 2008
Paul D. Anderson wrote:Andrei Alexandrescu 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. Andrei
I've done some work on a set of decimal floating point numbers consistent with the new 754r decimal formats approved in June. Some of that work would be applicable here, I think. It would probably make sense to add the decimal formats at the same time. Let me know if I can help.
Sounds interesting, and thanks for the offer. I'd be glad to add decimal types too, in case there's enough interest. I think monetary calculations can be helped, and what don't we do nowadays to help people involved in monetary calculations? :o) Andrei
Oct 17 2008