Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make elastic_integer an alias #284

Closed
johnmcfarlane opened this issue Sep 8, 2018 · 3 comments
Closed

Make elastic_integer an alias #284

johnmcfarlane opened this issue Sep 8, 2018 · 3 comments

Comments

@johnmcfarlane
Copy link
Owner

The NumDigits in cnl::elastic_integer<NumDigits, Integer> may have been a mistake. Repurpose it as promote_integer<Integer> so that, e.g. operator+ doubles the width of the result.

New layout:

template<typename Rep>
promote_integer;

template<int Digits, typename Narrowest>
wide_integer;

template<int Digits, typename Narrowest>
using elastic_integer = promote_integer<wide_integer<Digits, Narrowest>>;
@elcojacobs
Copy link

I'm not sure I fully understand what you mean here, but it would be very useful for me if I can define a fixed_point<24,0, int32_t>, which does not saturate its underlying type.
When two of these are multiplied, I need a promoted type, but for addition, the type already has enough room to grow.

The elastic integer seems to provide exactly that: promoting to a bigger type only when it is needed. For addition, it only needs one extra integer bit and if and if there are unused digits left, no underlying type promotion is needed.

@johnmcfarlane
Copy link
Owner Author

The alias version of elastic_integer would do this. Because cnl::digits and cnl::set_digits would be used by promote_integer to decide the appropriate width of return types, and because wide_integer is bit-resolution, you'd get the same extra single bit when adding and double the bits when multiplying.

You can get your fixed-point type currently using fixed_point<elastic_integer<24>>. When they are added, you get fixed_point<elastic_integer<24>>. That wouldn't change if elastic_integer became an alias but wide_integer would now take on the job of keeping track of the exact number of bits.

@johnmcfarlane
Copy link
Owner Author

This appears to be captured/superseded by #864.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants