-
Notifications
You must be signed in to change notification settings - Fork 35
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
Binary search related bug in MzSpectrum.Extract #710
Comments
Another probably incorrect implementation of handling binary search on double arrays. |
Here, starting index again doesn't correctly determine which index it is closer to. This one is more serious because it has 17 references. mzLib/mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs Lines 673 to 695 in b0f82ea
|
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mzLib/mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs
Lines 718 to 730 in b0f82ea
The linked method has an error commonly associated with performig binary searches on double arrays. The method as written uses a binary search to find the minimum mz value in the MzSpectrum.XArray and does not test to see if the correct, closest value is the index to the right or the left.
To fix this issue, replace lines currently binary search associated code should be replaced with the following:
`
int ind = Array.BinarySearch(XArray, minX);
if (ind < 0)
{
ind = ~ind;
}
The text was updated successfully, but these errors were encountered: