Skip to content

Commit eded7db

Browse files
committed
Do not mix doubles and floats in comparisons. See samtools#871
1 parent 85edfd9 commit eded7db

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

filter.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ static int vector_logic_and(filter_t *filter, bcf1_t *line, token_t *rtok, token
16051605
{ \
16061606
if ( missing_logic[nmiss] ) { rtok->pass_site = 1; i = atok->nvalues; break; } \
16071607
} \
1608-
else if ( atok->values[i] CMP_OP btok->values[j] ) { rtok->pass_site = 1; i = atok->nvalues; break; } \
1608+
else if ( (float)atok->values[i] CMP_OP (float)btok->values[j] ) { rtok->pass_site = 1; i = atok->nvalues; break; } \
16091609
} \
16101610
} \
16111611
} \
@@ -1665,7 +1665,7 @@ static int vector_logic_and(filter_t *filter, bcf1_t *line, token_t *rtok, token
16651665
{ \
16661666
if ( missing_logic[nmiss] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; j = xtok->nval1; break; } \
16671667
} \
1668-
else if ( xptr[j] CMP_OP yptr[k] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; j = xtok->nval1; break; } \
1668+
else if ( (float)xptr[j] CMP_OP (float)yptr[k] ) { rtok->pass_samples[i] = 1; rtok->pass_site = 1; j = xtok->nval1; break; } \
16691669
} \
16701670
} \
16711671
} \
@@ -2284,13 +2284,14 @@ static int filters_init1(filter_t *filter, char *str, int len, token_t *tok)
22842284
// is it a value? Here we parse as integer/float separately and use strtof
22852285
// rather than strtod, because the more accurate double representation
22862286
// would invalidate floating point comparisons like QUAL=59.2, obtained via
2287-
// htslib/vcf parser
2287+
// htslib/vcf parser.
2288+
// Update: use strtod() and force floats only in comparisons
22882289
char *end;
22892290
tok->threshold = strtol(tmp.s, &end, 10); // integer?
22902291
if ( end - tmp.s != strlen(tmp.s) )
22912292
{
22922293
errno = 0;
2293-
tok->threshold = strtof(tmp.s, &end); // float?
2294+
tok->threshold = strtod(tmp.s, &end); // float?
22942295
if ( errno!=0 || end!=tmp.s+len ) error("[%s:%d %s] Error: the tag \"%s\" is not defined in the VCF header\n", __FILE__,__LINE__,__FUNCTION__,tmp.s);
22952296
}
22962297
tok->is_constant = 1;

0 commit comments

Comments
 (0)