Boost logo

Boost :

Subject: Re: [boost] [fixed_point] Request for interest in a binary fixed point library
From: Christopher Kormanyos (e_float_at_[hidden])
Date: 2012-04-16 17:44:21


<big snip> > Would this syntax be convenient? Or, do we need something intermediary as > f1 = convert(1.2345); > f2 = convert(f1 - 2); > f2 = convert(f1 / f2); > The template function convert will return a wrapper of its parameter that is accepted as an implicit conversion. <snip> > Best, Vicente As always, good luck with a project of such importance and complexity. I'm relatively new here. But I am concerned about the above-mentioned dialog. Perhaps I have not understood this dialog because the discussion was at a relatively high level of C++ abstraction. But boost already has a policy on mixing specialized numeric types with built-in types. As far as I know, a specialized type in boost is supposed to seamlessly interact with all built-in types on both the left-hand as well as the right-hand side of all expressions. I believe that boost mandates implicit conversion to built-in types *without* a conversion-wrapper. This means that if the user selects to lose performance by mixing, say, double with fixed_point, then the user did it---willingly, that is on purpose! About converting fixed_point<unsigned bits_mantissa,                     signed bits_fraction> from one mantissa/fraction representation to another, I say don't ever do it without explicit ctor call or assignment operator. If you don't do this, then the code amount blows up beyond what it reasonably should. You might have this:   fixed_point<15, -16> radius<123, 100>(); // Ratio of approx. 1.23 And you want to go to this:   fixed_point<15, -16> result1 = pi_rep<15, -16>() * (radius * radius); // Should work! OK. But if you want to go to this:   fixed_point<7, -8> result2 = pi_rep<15, -16>() * (radius * radius); // Should not work! In my opinion, it should not work. The user should explicitly convert to the other fixed-point type with copy-construct. But this should work:   fixed_point<15, -16> result3 = 3.141592654 * (radius * radius); // Should work! And if you ever get into stuff like this:   fixed_point<8, -1024> high_precision_decimal<1, 3>(); ... Then you may want to consider interaction with boost.math. Best regards, Chris.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk