optimize NaN and -Inf check

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@782657 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2009-06-08 14:47:23 +00:00
parent 9382159d10
commit 2e5960f5e6
2 changed files with 8 additions and 6 deletions

View File

@ -122,9 +122,10 @@ public class BoostedQuery extends Query {
public float score() throws IOException {
float score = qWeight * scorer.score() * vals.floatVal(scorer.doc());
// current Lucene sorting priority queues can't handle NaN (score!=score is true for NaN) and -Infinity
if (score != score || score==Float.NEGATIVE_INFINITY) return -Float.MAX_VALUE;
return score;
// Current Lucene priority queues can't handle NaN and -Infinity, so
// map to -Float.MAX_VALUE. This conditional handles both -infinity
// and NaN since comparisons with NaN are always false.
return score>Float.NEGATIVE_INFINITY ? score : -Float.MAX_VALUE;
}
public boolean skipTo(int target) throws IOException {

View File

@ -133,9 +133,10 @@ public class FunctionQuery extends Query {
public float score() throws IOException {
float score = qWeight * vals.floatVal(doc);
// current Lucene sorting priority queues can't handle NaN (score!=score is true for NaN) and -Infinity
if (score != score || score==Float.NEGATIVE_INFINITY) return -Float.MAX_VALUE;
return score;
// Current Lucene priority queues can't handle NaN and -Infinity, so
// map to -Float.MAX_VALUE. This conditional handles both -infinity
// and NaN since comparisons with NaN are always false.
return score>Float.NEGATIVE_INFINITY ? score : -Float.MAX_VALUE;
}
public boolean skipTo(int target) throws IOException {