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

floor rounding issue in gain_group.cpp #31

Closed
guruofquality opened this issue Apr 2, 2015 · 4 comments
Closed

floor rounding issue in gain_group.cpp #31

guruofquality opened this issue Apr 2, 2015 · 4 comments

Comments

@guruofquality
Copy link
Contributor

Here is small bug with a quick fix: the floor rounding for working around floating point errors in gain_group is incorrect for negative numbers. The consequence is that negative gains will cause the distribution algorithm to be off by a step size. I introduced this bug into the code base years ago. Nevertheless, I would appreciate it if you could upstream this or an equivalent patch into maint. Thanks.

diff --git a/host/lib/utils/gain_group.cpp b/host/lib/utils/gain_group.cpp
index e907a65..0f56eb8 100644
--- a/host/lib/utils/gain_group.cpp
+++ b/host/lib/utils/gain_group.cpp
@@ -51,6 +51,7 @@ static bool compare_by_step_size(
  * \return a multiple of step approximating num
  */
 template <typename T> static T floor_step(T num, T step, T e = T(0.001)){
+    if (num < T(0)) return step*int(num/step - e);
     return step*int(num/step + e);
 }

@bhilburn
Copy link
Contributor

Okay, we have replicated this. The patch is going through review and testing, and will go onto maint. Closing the bug to track it internally.

@guruofquality
Copy link
Contributor Author

bump Sorry to bother, but it looks like this patch got lost in the process.

@guruofquality
Copy link
Contributor Author

@mbr0wn I know its somewhat of an innocuous bug. It just makes negative numbers round in the wrong direction and being off by 1dB or so isn’t really noticeable. I've been sitting on this patch for a while, and I'm looking for some guidance as to drop it, keep it, ignore it, etc.

@mbr0wn
Copy link
Contributor

mbr0wn commented Jan 4, 2017

Not sure why it got lost. Reintegrating.

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

3 participants