
Ullrich Koethe wrote:
For example, VIGRA's promotion traits choose double as the promotion for int when dealing with floating point operations. Why not float? On many architectures float is faster, and precision may not be an issue in the context in which you use it.
Why should int always be the result type of adding two ints?
Because that's what the C++ standard says (AFAIR).
But the standard isn't always the best answer for all promotion situations. For example, some years back I wrote some expression template code for simulation purposes. I wanted a simple user interface so I promoted int / int to double to avoid loss of precision. Stuffed away in some cobweb-infested dusty disk sector I have a library that implements promotion "strategies" using a table-driven configuration of (operator/operand type -> promotion type) rules. I'll see if I can dig it out and post it as a starting point. I'm not sure if it's what we want as a Boost library but it might be a start for discussion. -Dave