Fixed point integer proposal

Hi, Some years ago I wrote a fixed point template for transparent fixed point integer arithmetics and conversion. It worked well and performance was equal to that of native integer types, at least in MS VC++. The template takes a base type and the number of bits reserved for the fraction part and meta-programming works out boundary safe arithmetics and conversions. The template has been used in an image processing library, but lately I used it for seamless conversion of a 4+28 bit fixed point MAD-library decoded mp3-stream to the output buffer of the sound system, with a detour through a float-based sound effect. Would there be public interest in a template like that in the boost library? Soren

On Wed, Jun 24, 2009 at 12:51 PM, Soren Holstebroe <holstebroe@gmail.com>wrote:
Would there be public interest in a template like that in the boost library?
Yes, very much so. My main use case is also image processing. It would be useful if you could compare your work to other implementations, such as: * Phil Endecott's related proposal last year, and the ensuing discussion: http://lists.boost.org/Archives/boost/2007/04/120082.php * Dr. Dobbs, "Fixed-Point Arithmetic Types for C++," http://www.ddj.com/cpp/184401992 How are multiplication and division handled? Is overflow detection and/or saturation arithmetic supported? Cheers, Patrick

Patrick Mihelich wrote:
On Wed, Jun 24, 2009 at 12:51 PM, Soren Holstebroe <holstebroe@gmail.com>wrote:
Would there be public interest in a template like that in the boost library?
Yes, very much so. My main use case is also image processing.
It would be useful if you could compare your work to other implementations, such as: * Phil Endecott's related proposal last year, and the ensuing discussion: http://lists.boost.org/Archives/boost/2007/04/120082.php * Dr. Dobbs, "Fixed-Point Arithmetic Types for C++," http://www.ddj.com/cpp/184401992
How are multiplication and division handled?
Is overflow detection and/or saturation arithmetic supported?
I have posted here before some code based on constrained_value. One difficulty with this area is that users have different opinions on what the semantics should be. For example, does a(24bit) x b(24bit) -> c(24bit), or c(48bit)? My preference is to be explicit about these issues, meaning 24bit x 24bit -> 24 bit. If you want more, you cast the operands first. Similarly there were some questions on division. My implementation also uses boost::operators. In addition, I have 2 versions, one which the bit-widths are set at compile time, and the other set at runtime (I use the latter to expose to python). Since it is small, I am attaching the runtime version

Yes, it is very interesting. I think it will be also useful in finance calculations. I think, to be a more useful and to allow a seamless switch from standatd floating type, this class should support standart boost features, like serialization and formatting.
Hi,
Some years ago I wrote a fixed point template for transparent fixed point integer arithmetics and conversion. It worked well and performance was equal to that of native integer types, at least in MS VC++. The template takes a base type and the number of bits reserved for the fraction part and meta-programming works out boundary safe arithmetics and conversions. The template has been used in an image processing library, but lately I used it for seamless conversion of a 4+28 bit fixed point MAD-library decoded mp3-stream to the output buffer of the sound system, with a detour through a float-based sound effect.
Would there be public interest in a template like that in the boost library?
Soren _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

2009/6/25 Andrey Upadyshev <oliora@gmail.com>
Yes, it is very interesting. I think it will be also useful in finance calculations.
Actually, on that note, would it be possible to allow an arbitrary scale factor instead of specifying a shift? It ought to still be as efficient for power-of-two scales, on the assumption that compilers optimize multiplication and division by such constants...

Soren Holstebroe wrote:
Some years ago I wrote a fixed point template for transparent fixed point integer arithmetics and conversion.
To me, "fixed point" => !"integer".
It worked well and performance was equal to that of native integer types, at least in MS VC++. The template takes a base type and the number of bits reserved for the fraction part and meta-programming works out boundary safe arithmetics and conversions. The template has been used in an image processing library, but lately I used it for seamless conversion of a 4+28 bit fixed point MAD-library decoded mp3-stream to the output buffer of the sound system, with a detour through a float-based sound effect.
Would there be public interest in a template like that in the boost library?
I proposed something like this a while ago. The feedback suggested that most potential users wanted more than I was offering. In particular, saturating or otherwise detecting overflows seemed to be required. I did have a go at implementing this (using a saturating int class as the implementation type) but I'm unenthusiastic about proposing something that I'm not myself using. Other people suggested that it would be better to use expression templates and I seem to recall that someone was actually working on that. It was also suggested that I ought to provide all of the features that <cmath> provides for floating point. Regards, Phil.
participants (6)
-
Andrey Upadyshev
-
Neal Becker
-
Patrick Mihelich
-
Phil Endecott
-
Scott McMurray
-
Soren Holstebroe