This repository was archived by the owner on Jan 31, 2020. It is now read-only.
Use new diff() function for absolute difference between two unsigned coords#64
Open
jmarshall wants to merge 1 commit intogenome:masterfrom
Open
Use new diff() function for absolute difference between two unsigned coords#64jmarshall wants to merge 1 commit intogenome:masterfrom
jmarshall wants to merge 1 commit intogenome:masterfrom
Conversation
Using abs(pos1-pos2) has potential to overflow and, when pos1/pos2 are unsigned, fails to compile when there are ambiguous signed int/signed long/etc std::abs() functions to choose between. Avoid these issues by introducing a function that does what is really needed, namely finding the difference without sign between the two coordinates.
This was referenced Mar 21, 2018
|
Ran into the ambiguous |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the ambiguous
abs()compilation errors described in #62. Casting tointis not really the best way to fix this, as the cause of the problem is that the arguments areunsigned intrather thanintand what's really needed is some sort ofabs_differencefunction that works on unsigneds natively.There are several other source files that would also produce these compiler errors, but those source files happen to also
#include <math.h>which gives themfloat abs(float)/etc functions that resolve the ambiguous function choice while probably making things worse.This PR adds a new
unsigned diff(unsigned, unsigned)function and uses it instead of rawabs()in all these source files. It also adds in pindel.h an implementation of this function that computes the difference by cases rather than by usingabs(), so as to avoid overflow — which would occur forabs()-based methods when comparing a coordinate near 0 with one near the end of a 232-base chromosome. (If this is overkill, the implementation could be replaced with anabs()-based one, but I doubt there is any difference in efficiency.)