Skip to content

Commit

Permalink
Fix GrainSize rounding error
Browse files Browse the repository at this point in the history
The rounding formula is different between
positive and negative scores due to the
GrainSize/2 term that is asymmetric.

So use truncation instead of rounding. This
guarantees that evaluation is rounded to zero
in the same way for both positive and negative
scores.

Found with position's flip

bench: 4634244
  • Loading branch information
mcostalba committed Aug 10, 2013
1 parent 5769509 commit 94a3608
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/evaluate.cpp
Expand Up @@ -1083,7 +1083,7 @@ Value do_evaluate(const Position& pos, Value& margin) {

int ev = (eg_value(v) * int(sf)) / SCALE_FACTOR_NORMAL;
int result = (mg_value(v) * int(ph) + ev * int(128 - ph)) / 128;
return Value((result + GrainSize / 2) & ~(GrainSize - 1));
return Value((result / GrainSize) * GrainSize); // Sign independent
}

// apply_weight() weights score v by score w trying to prevent overflow
Expand Down

0 comments on commit 94a3608

Please sign in to comment.