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

Overflow when adding two unsigned integers #167

Open
PanieriLorenzo opened this issue Dec 11, 2021 · 1 comment
Open

Overflow when adding two unsigned integers #167

PanieriLorenzo opened this issue Dec 11, 2021 · 1 comment

Comments

@PanieriLorenzo
Copy link

This issue is related to #73 but occurs when using add_amp on unsigned integers, for which the result would be the maximum value (or minimum value) that unsigned integer can store, i.e. 1.0 when converted to float representation. In these cases the function will overflow internally, as the unsigned integers are converted to signed integers of the same size during the operation.

Despite the fact that the discussion in #73 arrived at the conclusion that it's intended for some types to not be able to store 1.0, in this case I'd argue it is still a problem, because in theory unsigned types should be able to store 1.0, but in certain cases they can't (unexpectedly). Moreover, a possible solution in this case seems quite simple to implement and not particularly controversial, simply use a larger signed integer conversion internally when dealing with unsigned integer addition, e.g. for u8, use i16 internally.

@PanieriLorenzo
Copy link
Author

I'd like to add that maybe instead of changing how numbers are represented, a more general solution that would help alleviate #73 as well, would be to saturate signals rather than overflowing. This is more consistent to how most dsp things handle overflows. In other words, hard-clip rather than panic.

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

1 participant